Hi, I solved the problem implementing a tiles controller and using the "extend" definition attribute in tiles-defs.xml. This solution requires two tiles definition but the jsp body is the same. I used two tiles in order to set the correct action, formName and some other parameter. Maybe this solution can be improved. Any suggestion is welcome.
Inside tiles-def.xml <definition name="base" path="/layouts/standard.jsp"> <put name="title" value="Web Application"/> <put name="header" value="/common/header.jsp"/> <put name="footer" value="/common/footer.jsp"/> </definition> <definition name="standard" extends="base" controllerClass="it.amletodisalle.presentation.tiles.TilesControllerImpl "> <put name="left" value="menu.bar"/> <put name="action" value="default"/> <put name="formName" value="default"/> <put name="subtitle" value="default"/> <putList name="otherValues"> </putList> </definition> For example: <definition name="viewproduct" extends="standard"> <put name="title" value="Web Application - View Products"/> <put name="subtitle" value="View Products"/> <put name="body" value="/protect/viewProducts.jsp"/> <put name="action" value="ActivateAddProduct"/> <putList name="otherValues"> <bean classtype="it.amletodisalle.common.presentation.tiles.ListItem"> <set-property property="nome" value="editProduct"/> <set-property property="valore" value="ActivateEditProduct"/> </bean> <bean classtype="it.amletodisalle.common.presentation.tiles.ListItem"> <set-property property="nome" value="navigationAction"/> <set-property property="valore" value="viewProducts"/> </bean> </putList> </definition> <definition name="addproduct" extends="standard"> <put name="title" value="Web Application - Add Product"/> <put name="subtitle" value="Add Product"/> <put name="body" value="/protect/formProduct.jsp"/> <put name="action" value="AddProduct"/> <put name="formName" value="FormbeanProduct"/> <putList name="otherValues"> <bean classtype="it.amletodisalle.common.presentation.tiles.ListItem"> <set-property property="nome" value="updateURL"/> <set-property property="valore" value="ActivateAddProduct"/> </bean> </putList> </definition> <definition name="editproduct" extends="standard"> <put name="title" value="Web Application - Edit Product"/> <put name="subtitle" value="Edit Product"/> <put name="body" value="/protect/formProduct.jsp"/> <put name="action" value="editProduct"/> <put name="formName" value="FormbeanProduct"/> <putList name="otherValues"> <bean classtype="it.amletodisalle.common.presentation.tiles.ListItem"> <set-property property="nome" value="updateURL"/> <set-property property="valore" value="ActivateAddProduct"/> </bean> </putList> </definition> TilesControllerImpl: import java.io.IOException; import java.util.Iterator; import java.util.List; import javax.servlet.ServletContext; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.struts.tiles.ComponentContext; import org.apache.struts.tiles.Controller; public class TilesControllerImpl implements Controller { public void perform( ComponentContext componentContext, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, ServletContext servletContext ) throws ServletException, IOException { String subtitle = (String) componentContext.getAttribute( Constants.SUB_TITLE); if (!subtitle.equals( Constants.DEFAULT )) { httpServletRequest.setAttribute( Constants.SUB_TITLE, subtitle ); } String action = (String) componentContext.getAttribute( Constants.ACTION ); if (!action.equals( Constants.DEFAULT )) { httpServletRequest.setAttribute( Constants.ACTION, "/" + action + ".do"); } String formName = (String) componentContext.getAttribute( Constants.FORM_NAME); if (!formName.equals( Constants.DEFAULT )) { httpServletRequest.setAttribute( Constants.FORM_NAME, formName); char firstChar = formName.charAt( 0 ); String onsubmitName = "validate" + Character.toUpperCase( firstChar ) + formName.substring( 1, formName.length()); String onsubmit = "return " + onsubmitName + "(this);"; httpServletRequest.setAttribute( Constants.ON_SUBMIT, onsubmit); httpServletRequest.setAttribute( Constants.ON_SUBMIT_NAME, onsubmitName); } List otherValues = (List) componentContext.getAttribute( Constants.OTHER_VALUES ); for ( Iterator iterator = otherValues.iterator(); iterator.hasNext(); ) { ListItem listItem = ( ListItem ) iterator.next(); httpServletRequest.setAttribute( listItem.getNome(), listItem.getValore() ); } } } And inside the ".jsp" you can use the parameters defined inside tiles For Example: ................ <html:javascript formName="${formName}"/> <html:form action="${action}" onsubmit="${onsubmit}"> ............. </html:form> BR /Amleto > -----Messaggio originale----- > Da: Rick Reumann [mailto:[EMAIL PROTECTED] > Inviato: luned́ 24 gennaio 2005 23.18 > A: Struts Users Mailing List > Oggetto: Best practice for dynamic Title values using Tiles? > > > I'm switching back to using Tiles instead of Sitemesh and I > remember one > issue that I found annoying with Tiles and I'd be curious how > you guys > handle it. Say I have a form that is going to be reused for > both "Edit" > and "Add." I want the <title> attribute to read something like "Add > Employee" or "Edit Employee," depending on what I'm doing. It seems > silly to have to create multiple definitions in my tiles-definitions > that are essentially the same exact definition except that > the title has > changed (potentially you might want a definition to be used for more > than just the two that I mentioned). This also requires that > my struts > config has to be set up to forward to multiple tiles definitions when > its really the same page layout but with a different title and could > really just require one definition to use. > > I've thought of different ways I might want to handle this (ie set a > title in request scope before leaving action and have the header.jsp > look for this, or maybe use a filter or over-ride > RequestProcessor?) I'm > curious if others have run into this. Maybe the latest > Struts/Tiles has > a solution that I have not looked into. > > Thanks > > -- > Rick > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > -- > No virus found in this incoming message. > Checked by AVG Anti-Virus. > Version: 7.0.300 / Virus Database: 265.7.2 - Release Date: 21/01/2005 > > -- No virus found in this outgoing message. Checked by AVG Anti-Virus. Version: 7.0.300 / Virus Database: 265.7.2 - Release Date: 21/01/2005 --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]