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 under
com/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)
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 the META-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:
public class MyTapestryComponentsModule {
public static void contributeComponentClassResolver(
Configuration<LibraryMapping> configuration) {
configuration.add(
new LibraryMapping("myprefix", "my.tapestry.basepackage"));
}
}
So any components would go into my.tapestry.basepackage.components
, mixins into my.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:
<div t:type="myprefix/MyComponent" ... />
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:
2010-12-20 20:27:07,663 [main] INFO org.apache.tapestry5.services.TapestryModule.ComponentClassResolver - Available components:
ActionLink: org.apache.tapestry5.corelib.components.ActionLink
AddRowLink: org.apache.tapestry5.corelib.components.AddRowLink
etc.
Your components should show up there with their full name and prefix. Do they?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With