I generally use Tiles to handle these kinds of things.
In your struts-config.xml install the Tiles plugin: <plug-in className="org.apache.struts.tiles.TilesPlugin" > <set-property property="definitions-config" value="/WEB-INF/tiles-definitions.xml/> <set-property property="definitions-parser-validate" value="true" /> <set-property property="moduleAware" value="true" /> </plug-in>
In your tiles-definitions.xml define your layout and other tiles:
<tiles-definitions>
<definition name="layout" path="/WEB-INF/jsp/layout.jsp">
<put name="title" value="Portfolio Analytics" />
<put name="header" value="/WEB-INF/jsp/header.jsp" />
<put name="footer" value="/WEB-INF/jsp/footer.jsp"/>
<put name="body" value="/WEB-INF/jsp/blank.jsp" />
<put name="menu" value="/WEB-INF/jsp/menus/menuAll.jsp" />
</definition>
<definition name="welcome" extends="layout">
<!-- replace the value of body in layout with something different -->
<put name="body" value="/WEB-INF/jsp/welcome.jsp"/>
</definition>
</tiles-definitions>
Back in struts-config your actions forward to tiles instead of jsps:
<action-mappings> <action path="/index" type="some.object.Name"> <forward name="success" path="welcome"/> </action> </action-mappings>
Finally, your layout.jsp <%@ taglib uri="/WEB-INF/tiles.tld" prefix="tiles" %> <html> <body> <tiles:insert attribute="header"/> <tiles:insert attribute="menu"/> <tiles:insert attribute="body"/> <tiles:insert attribute="footer"/> </body> </html>
Hope that helps a bit, J
Jeff Smith wrote:
I have 3 different pages in my test app: Greet Unauthenticated User, Login and Greet Authenticated User
There is a PageUnauthGreet.jsp, PageAuthGreet.jsp and PageLoginUser.jsp. Each has an identical structure:
<%@ taglib uri='/tags/struts-template' prefix='template' %> <template:insert template='/TemplateMain.jsp'> <template:put name='pagename' content='Logon' direct='true'/> <template:put name='header' content='/TileHeader.jsp'/> <template:put name='sidebar' content='/TileSidebar.jsp'/> <template:put name='content' content='FOO.jsp'/> </template:insert>
The only difference between the 3 files is the FOO.jsp which loads the content tile specific for that particular page. Each one loads a different tile: TileUnauth.jsp, TileAuth.jsp and FormLogon.jsp
This structure works fine. But it started to bug me that whenever I create a new page, I had to create the structure.jsp and then the tile.jsp
So then I implemented a MasterLayout.jsp page like this:
<%@ taglib uri='/tags/struts-template' prefix='template' %> <%@ taglib uri='/tags/struts-bean' prefix='bean' %> <bean:parameter id="tilePage" name="tilePage"/> <bean:define id="fullTilePage" value='<%= tilePage %>'/> <template:insert template='/TemplateMain.jsp'> <template:put name='pagename' content='Logon' direct='true'/> <template:put name='header' content='/TileHeader.jsp'/> <template:put name='sidebar' content='/TileSidebar.jsp'/> <template:put name='content' content='<%=fullTilePage%>'/> </template:insert>
Now I've been able to get rid of all my structure.jsp files and replace it with this single MasterLayout.jsp
I can invoke it from the struts-config.xml with an action reference like this:
<action path="/Logon" type="org.apache.struts.actions.ForwardAction" parameter="/MasterLayout.jsp?tilePage=FormLogon.jsp"/>
So essentially, I can now display any page that follows the standard structure by writing a single tile for the "content" section of the page and then invoking the MasterLayout with a tilePage= parameter to indicate which tile should be thrown into the content section.
I have two questions:
1) Am I overlooking something that is likely to bite me?
2) Is there a more elegant way to control the filler tile?
In particular, I'm not crazy about the resulting URL line displayed in the browser location. When I forwarded to the logon success page, I had a nice url that just said: http://localhost/MyAppName/LogonSubmit.do
But now that I am redirecting (instead of forwarding - to break the back-button stomping issue) it shows a much icky-er http://localhost:/MyAppName/MasterLayout.jsp?tilePage=/TileWelcome.jsp
I can live with it the way it is, but I want to be sure I'm exploiting all the power there is to be had from the templates and tiles system, the action forwarding syntax and all of that stuff.
Thanks, Jefficus
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]