Tapestry错误:资源路径不在别名路径中

时间:2015-05-07 14:47:00

标签: javascript assets tapestry

我不是Java开发人员,不得不使用Tapestry 5.3.8。 我可以在我的网页中使用css,图像和fav图标等资源。我这样做是通过在我的页面中注入它们来实现的:

    /*
     * This SingleOrNull implementation is heavily based on the standard
     * Single/SingleOrDefault methods, retrieved from the reference
     * source codebase on Thu May 7, 2015.
     * http://referencesource.microsoft.com/#System.Core/System/Linq/Enumerable.cs
     *
     * In case it isn't clear, the first part is merely an opportunistic
     * optimization for sources that are actually lists, and which thus
     * expose a precomputed count.  Using a count is faster since we
     * only have to read 0-1 elements.  In contrast, the fallback must
     * read 1-2 elements.
     */
    public static TSource? SingleOrNull<TSource>(
        this IEnumerable<TSource> source)
        where TSource : struct
    {
        if (source == null) throw new ArgumentNullException("source");
        var list = source as IList<TSource>;
        if (list != null)
        {
            switch (list.Count)
            {
                case 0: return null;
                case 1: return list[0];
            }
        }
        else
        {
            using (var e = source.GetEnumerator())
            {
                if (!e.MoveNext()) return null;
                var result = e.Current;
                if (!e.MoveNext()) return result;
            }
        }
        return null;
    }

这没有问题。虽然它有效,但我不相信资产位于正确的文件夹中。它们应该放在文件夹&#39;静态&#39;

现在我想添加一个Javascript文件。这就是我所做的:

@Inject
@Path("context:static/img/logo.png")
private Asset logo;

@Inject
@Path("context:static/img/favicon.ico")
private Asset favIcon;

找到了文件,但是我在运行时遇到以下错误:&#34;资源路径不在别名路径中#34;。

据我所知,我需要为我的Javscript文件所在的路径创建一个别名,但是如何?

我想这必须在方法&#34; contributionClasspathAssetAliasManager&#34;在CiAppModule.java中。这是对的,我应该添加什么?

1 个答案:

答案 0 :(得分:0)

问题在于这一部分:

@Import(library = "context:static/js/additional.js")

当我将其更改为

@Import(library = {"context:static/js/additional.js"})

它有效。

感谢Tapestry的错误报告,这一点根本不清楚。 GRRRR。