Tapestry mockups and component libraries

I have several different projects that basically use the same javascript / css and layout template. I want to move all this into my tapestry-common-lib project and reference it from there.

I have other common components in my -common-lib tapestry, but it doesn't seem to be able to set up the layout correctly.

In my tapestry-common-lib project, I have CommonLayout.java in com.company.tapestrylib.components and a CommonLayout.tml file in the com/company/tapestrylib/components section.

I am trying to reference the CommonLayout form of another project in my Index.tml like this:

 <t:commonlayout xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd"> </t:commonlayout> 

However, when I access this page, I get

 Unable to resolve 'commonlayout' to a component class name. 

Can I do it? Can I also put all my common css and javascript in the jar tapestry-common-lib and reference them from there using, for example:

 <script type="text/javascript" src="${asset:context:/js/jquery-1.4.2.js}"></script> 

I looked around and found a lot of articles about creating custom components and component libraries, but did not use reusable layouts, as I am trying to do.

UPDATE:

I am currently using other abstract components from my component library. They are stored in [root] .tapestrylib.base.

I am trying to save my general layout (Layout.java and Layout.tml) in [root] .tapestrylib.components. When I try to reference this layout from my other project, I get

 Unable to resolve 'layout' to a component class name. 

I am trying to use it like this:

 <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 that I get:

 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) 
+4
source share
1 answer

The layout component or non-layout should not matter.

Are any components available from your library? (A full error report [ tapestry.production-mode=false ] provides a list of available components.) If not, your library may not be configured properly.

Tapestry locates the component libraries by looking at the manifest files of all the JARs in the class path for the entry named Tapestry-Module-Classes and loads the component module configuration. Check if META-INF/MANIFEST.MF such an entry in your JAR, and if it refers to the correct component module class.

The library component section in Tapestry documents shows how to configure Maven to automatically create such a record.

Edit:

The components must 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 will go into my.tapestry.basepackage.components , mixins in my.tapestry.basepackage.mixins , etc., as in your main application.

To use components from your library, you simply prefix them with what you defined:

 <div t:type="myprefix/MyComponent" ... /> 

Edit 2:

Good, that looks good. What would be really useful to see in the list of available components of Tapestry logs at startup. It is located 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 appear there with their full name and prefix. They?

+4
source

Source: https://habr.com/ru/post/1332392/


All Articles