Tapestry 布局和组件库
我有几个不同的项目,基本上使用相同的 javascript/css 和布局模板。我想将所有这些移至我的 Tapestry-common-lib 项目中并从那里引用它。
我的 Tapestry-common-lib 中有其他常见组件,但似乎无法使布局正常工作。
在我的 Tapestry-common-lib 项目中,我在 com.company.tapestrylib.components 中有一个 CommonLayout.java 和 CommonLayout.tml 文件位于 com/company/tapestrylib/components
。
我试图从 Index.tml 中的另一个项目引用 CommonLayout,如下所示:
<t:commonlayout xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
</t:commonlayout>
但是,每当我访问该页面时,我都会收到
Unable to resolve 'commonlayout' to a component class name.
Can I do this?我是否也可以将所有常用的 css 和 javascript 放入我的 Tapestry-common-lib jar 中,并引用其中的内容,例如:
<script type="text/javascript" src="${asset:context:/js/jquery-1.4.2.js}"></script>
我一直在四处寻找,发现了大量有关创建自定义组件和组件库的文章,但没有一篇就像我想做的那样重用布局。
更新:
我目前正在使用组件库中的其他抽象组件。它们存储在 [root].tapestrylib.base 中。
我试图将我的通用布局(Layout.java 和 Layout.tml)存储在 [root].tapestrylib.components 中。当尝试从我的其他项目引用此布局时,我得到一个
Unable to resolve 'layout' to a component class name.
我正在尝试像这样使用它:
<html t:type="tapestry-lib/layout" xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd" xmlns:p="tapestry:parameter">
</html>
这是我得到的实际异常的一部分:
11:28:01 ERROR RequestExceptionHandler - Processing of request failed with uncaught exception: Unable to resolve 'tapestry-lib/layout' to a component class name.
org.apache.tapestry5.ioc.internal.OperationException: Unable to resolve 'tapestry-lib/layout' to a component class name. [at classpath:com/mycompany/webapp/pages/Index.tml, line 1]
at org.apache.tapestry5.ioc.internal.OperationTrackerImpl.logAndRethrow(OperationTrackerImpl.java:102)
at org.apache.tapestry5.ioc.internal.OperationTrackerImpl.invoke(OperationTrackerImpl.java:69)
at org.apache.tapestry5.ioc.internal.PerThreadOperationTracker.invoke(PerThreadOperationTracker.java:68)
at org.apache.tapestry5.ioc.internal.RegistryImpl.invoke(RegistryImpl.java:1057)
at org.apache.tapestry5.internal.pageload.PageLoaderImpl.createAssembler(PageLoaderImpl.java:218)
at org.apache.tapestry5.internal.pageload.PageLoaderImpl.getAssembler(PageLoaderImpl.java:208)
at org.apache.tapestry5.internal.pageload.PageLoaderImpl$3.invoke(PageLoaderImpl.java:180)
at org.apache.tapestry5.internal.pageload.PageLoaderImpl$3.invoke(PageLoaderImpl.java:174)
at org.apache.tapestry5.ioc.internal.OperationTrackerImpl.invoke(OperationTrackerImpl.java:65)
at org.apache.tapestry5.ioc.internal.PerThreadOperationTracker.invoke(PerThreadOperationTracker.java:68)
at org.apache.tapestry5.ioc.internal.RegistryImpl.invoke(RegistryImpl.java:1057)
at org.apache.tapestry5.internal.pageload.PageLoaderImpl.loadPage(PageLoaderImpl.java:173)
at $PageLoader_12d045be613.loadPage($PageLoader_12d045be613.java)
I have a few different projects that basically use the same javascript/css and layout template. I want to move all of this into my tapestry-common-lib project and reference it from there.
I have other common components in my tapestry-common-lib, but can't seem to get the layout to work properly.
In my tapestry-common-lib project I have a CommonLayout.java in com.company.tapestrylib.components
and a CommonLayout.tml file undercom/company/tapestrylib/components
.
I am trying to reference the CommonLayout form another project in my Index.tml like so:
<t:commonlayout xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
</t:commonlayout>
However, whenever I access that page I get a
Unable to resolve 'commonlayout' to a component class name.
Can I do this? Can I also put all of my common css and javascript into my tapestry-common-lib jar and reference those from there using for example:
<script type="text/javascript" src="${asset:context:/js/jquery-1.4.2.js}"></script>
I've been looking around and have found plenty of articles on creating custom components and component libraries, but none that reused layouts like I am trying to do.
UPDATE:
I am currently using other abstract components from my component library. These are stored in [root].tapestrylib.base.
I am trying to store my common layout (Layout.java and Layout.tml) in [root].tapestrylib.components. When trying to refer to this layout from my other project, I get a
Unable to resolve 'layout' to a component class name.
I am trying to use it like so:
<html t:type="tapestry-lib/layout" xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd" xmlns:p="tapestry:parameter">
</html>
This is part of the actual exception I am getting:
11:28:01 ERROR RequestExceptionHandler - Processing of request failed with uncaught exception: Unable to resolve 'tapestry-lib/layout' to a component class name.
org.apache.tapestry5.ioc.internal.OperationException: Unable to resolve 'tapestry-lib/layout' to a component class name. [at classpath:com/mycompany/webapp/pages/Index.tml, line 1]
at org.apache.tapestry5.ioc.internal.OperationTrackerImpl.logAndRethrow(OperationTrackerImpl.java:102)
at org.apache.tapestry5.ioc.internal.OperationTrackerImpl.invoke(OperationTrackerImpl.java:69)
at org.apache.tapestry5.ioc.internal.PerThreadOperationTracker.invoke(PerThreadOperationTracker.java:68)
at org.apache.tapestry5.ioc.internal.RegistryImpl.invoke(RegistryImpl.java:1057)
at org.apache.tapestry5.internal.pageload.PageLoaderImpl.createAssembler(PageLoaderImpl.java:218)
at org.apache.tapestry5.internal.pageload.PageLoaderImpl.getAssembler(PageLoaderImpl.java:208)
at org.apache.tapestry5.internal.pageload.PageLoaderImpl$3.invoke(PageLoaderImpl.java:180)
at org.apache.tapestry5.internal.pageload.PageLoaderImpl$3.invoke(PageLoaderImpl.java:174)
at org.apache.tapestry5.ioc.internal.OperationTrackerImpl.invoke(OperationTrackerImpl.java:65)
at org.apache.tapestry5.ioc.internal.PerThreadOperationTracker.invoke(PerThreadOperationTracker.java:68)
at org.apache.tapestry5.ioc.internal.RegistryImpl.invoke(RegistryImpl.java:1057)
at org.apache.tapestry5.internal.pageload.PageLoaderImpl.loadPage(PageLoaderImpl.java:173)
at $PageLoader_12d045be613.loadPage($PageLoader_12d045be613.java)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
布局或非布局组件不应该产生影响。
您的库中是否有可用的组件? (完整的错误报告 [
tapestry.product-mode=false
] 为您提供了可用组件的列表。)如果没有,您的库可能未正确设置。Tapestry 通过扫描类路径上所有 JAR 的清单文件来查找名为
Tapestry-Module-Classes
的条目,从而找到组件库,并从那里加载组件模块配置。检查 JAR 中的 META-INF/MANIFEST.MF 是否有这样的条目,以及它是否引用了正确的组件模块类。Tapestry 文档中的 组件库部分展示了如何设置 Maven 以自动创建此类一个条目。
编辑:
组件需要位于您在模块类中为其配置的包中:
因此任何组件都将进入
my.tapestry.basepackage.components
,mixins到my.tapestry.basepackage.mixins
等,就像在您的主应用程序中一样。要使用库中的组件,只需在它们前面添加您定义的任何内容即可:
编辑 2:
好的,看起来不错。真正有用的是启动时 Tapestry 日志的可用组件列表。它位于启动后最后打印的服务列表的正上方,应该如下所示:
您的组件应该显示在那里,并带有它们的全名和前缀。他们有吗?
Layout or non-layout component should not make a difference.
Are any of the components from your library available? (The full error report [
tapestry.production-mode=false
] gives you a list of available components.) If not, your library probably isn't set up properly.Tapestry finds component libraries by scanning the manifest files of all JARs on the classpath for an entry called
Tapestry-Module-Classes
, and loads the component module configuration from there. Check if theMETA-INF/MANIFEST.MF
in your JAR has such an entry, and if it references the correct component module class.The component library section in the Tapestry docs shows how to set up Maven to automatically create such an entry.
Edit:
The components need to be in the package that you configured for them in your module class:
So any components would go into
my.tapestry.basepackage.components
, mixins intomy.tapestry.basepackage.mixins
, etc., just like in your main app.To use the components from your library, you just prefix them with whatever you defined:
Edit 2:
Okay, that looks fine. What would be really useful to see is the list of available components Tapestry logs at startup. It is located right above the list of services that are printed last after startup, and should look like this:
Your components should show up there with their full name and prefix. Do they?