Dashboard > Community Wiki > ... > Integration > Struts, Tiles and Magnolia
Struts, Tiles and Magnolia Log In View a printable version of the current page.

Added by GrĂ©gory Joseph , last edited by Boris Kraft on Jun 23, 2008  (view change)
Labels: 

Requires Struts 1.3, Magnolia 3.x.

Using a tiles controller can be a quick solution for those who do not know how to develop plugins. All you need is some java knowledge, a bit of configuration and two jar files; the latest struts-core-1.3.x.jar, and the struts-tiles-1.3.x.jar.

You can either go the route of defining your tiles in a tiles-defs.xml file, or define each tile in the jsp itself. They both have their advantages, but defining in the jsp might be a little easier to understand.

<tiles:insert template="/templates/tiles/testTile.jsp" flush="false" controllerClass="com.web.tiles.PageSnippetController" >
		<tiles:put name="items" value="${items}" />
		<tiles:put name="folder" value="${folder}" />
</tiles:insert>

If we do pursue the above mentioned route, you can ignore the next few points until it explains the use of controller class

All files talked about are attached below.

Firstly you need to create a paragraph that points to the jsp file that will include the tile reference. In my case this was codeSnippets.jsp

Secondly you need to add the struts servlet to your web.xml file (below all the other servlet declarations)

<servlet>
    	<servlet-name>action</servlet-name>
    	<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
    	<init-param>
      		<param-name>config</param-name>
      		<param-value>/WEB-INF/struts-config.xml</param-value>
    	</init-param>
    	<init-param>
        	<param-name>chainConfig</param-name>
        	<param-value>org/apache/struts/tiles/chain-config.xml</param-value>
    	</init-param>
    	<init-param>
      		<param-name>debug</param-name>
      		<param-value>3</param-value>
    	</init-param>
    	<init-param>
      		<param-name>detail</param-name>
      		<param-value>3</param-value>
    	</init-param>
    	<load-on-startup>0</load-on-startup>
    </servlet>

struts-config.xml

and then add your struts-config.xml file in the location specified by the 'config' parameter above.

tiles-defs.xml

The next part of you configuration is the tiles-defs.xml file. The location of this file is referenced above in the struts-config.xml file. There is loads of documentation on the apache struts site explaining how tiles work, what you will see her is a small representation of its capabilities. To view them, go to the Struts tiles site.

Tiles template

All thats left is to create your tiles template which is pretty straight forward. You need a jsp file which references a tile specified in the tiles-defs.xml file and the jsp file specified by the associated location in the tile declaration

<definition name=".page.snippets" page="/docroot/tiles/test.jsp" controllerClass="com.magnolia.web.tiles.MagnoliaPageSnippetController" />

remembering that this file must be in an unprotected location in the web app or it will not be able to be read, this is the reason i have it in the 'docroot' folder.

Controller Class

You may have noticed the controllerClass attribute, this references the java class that you can use to access the magnolia repository, external content, whatever you choose. You can totally omit this attribute and just include the jsp, but it would be pointless s you can do that with magnolia already. The controller class needs to implement

org.apache.struts.tiles.Controller
and override override a couple methods, but i will attach that file.

Within the class you can do any processing and set the results back to the request, session, or tileContext.

In my case i had created some custom properties in the magnolia dialog that i had passed into the tile, these enabled me to create a dynamic application without having to delve into magnolia plugins.

All that remains is distributing your controller into the classpath of your application, the WEB-INF/lib folder is standard, and that should be fine.

Hope you find this helpful. I know its is really brief for a lot of information.

In its previous incarnation on JspWiki, this page was last edited on May 11, 2007 11:46:53 AM by Magnolia
Other known authors include :

Powered by a free Atlassian Confluence Open Source Project License granted to Magnolia International. Evaluate Confluence today.
Powered by Atlassian Confluence 2.7, the Enterprise Wiki. Bug/feature request - Atlassian news - Contact administrators