Re: [tiles] programatically putting a definition into a layout
Under what circumstances will ComponentContext.getContext( request ); return null? That is what I am seeing in my example. [EMAIL PROTECTED] 06/24/03 04:15AM Hi, There is an example on how to retrieve the tile context in org.apache.struts.webapp.tiles.test.TestActionTileAction. A tile context is created each time a tile is inserted. The tile context is hold in a ComponentContext object. Hope this help, Cedric William Salvucci wrote: tiles context? How do I get that? The logon.jsp has a struts html:form attribute that is associated to the action class. [EMAIL PROTECTED] 06/23/03 06:05AM William Salvucci wrote: with the following tiles-def, I can forward to layout.main and everything is fine: definition name=layout.main path=/layoutMain.jsp put name=header value=header.jsp / put name=app value=layout.app / put name=footer value=footer.jsp / /definition definition name=layout.app path=/layoutApp.jsp put name=mainMenu value=menu.main / put name=subMenu value=subMenu.jsp / put name=body value=welcome.jsp / /definition !-- Menu bar definition -- definition name=menu.main path=/menu.jsp putList name=items add value=Item 1 / add value=Item 2 / add value=Item 3 / /putList /definition I then modify the tiles-def so that in layout.main app = logon.jsp where logon.jsp submit is associated with a struts action. In the struts action I set the layout.main app = layout.app ComponentDefinition layout = TilesUtil.getDefinition(layout.main, request, this.servlet.getServletContext()); layout.put(app, layout.app); It is not recommended to change a definition dynamically, unless you know very well what you do. A definition content is shared by all the website. Changing the content will be reflected to all user of the definition. If you want to change a definition attribute for the current tiles, you should do so in the tile context, which hold a temporary copy of the definition. and forward to layout.main. So basically after the action everything should be the same as my original setup. However, I get the following error on the forward Jun 20, 2003 1:16:00 PM EDT Error HTTP Included resource or file /netl-c ommons/layout.app not found from requested resource /netl-commons/layoutMain.j sp. The layout.app name has been interpreted as an URL. It appear that the Tiles mechanism hasn't catch it. I don't see how you call the action from the logon.jsp page. Cedric layoutMain.jsp is not changed during my update and looks like TABLE border=1 TRTD COLSPAN=2tiles:insert attribute=header//TD/TR TRTD COLSPAN=2tiles:insert attribute=app / /TD/TR TRTD COLSPAN=2tiles:insert attribute=footer//TD/TR /TABLE Any idea why layoutMain.jsp could load layout.app in the original, but can't when I programatically put it into layout.main? I noticed that the put method doesn't have type as an argument for specifying string, page, definition, so I hope that isn't it. - 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] - 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] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: [tiles] programatically putting a definition into a layout
Hi, There is an example on how to retrieve the tile context in org.apache.struts.webapp.tiles.test.TestActionTileAction. A tile context is created each time a tile is inserted. The tile context is hold in a ComponentContext object. Hope this help, Cedric William Salvucci wrote: tiles context? How do I get that? The logon.jsp has a struts html:form attribute that is associated to the action class. [EMAIL PROTECTED] 06/23/03 06:05AM William Salvucci wrote: with the following tiles-def, I can forward to layout.main and everything is fine: definition name=layout.main path=/layoutMain.jsp put name=header value=header.jsp / put name=app value=layout.app / put name=footer value=footer.jsp / /definition definition name=layout.app path=/layoutApp.jsp put name=mainMenu value=menu.main / put name=subMenu value=subMenu.jsp / put name=body value=welcome.jsp / /definition !-- Menu bar definition -- definition name=menu.main path=/menu.jsp putList name=items add value=Item 1 / add value=Item 2 / add value=Item 3 / /putList /definition I then modify the tiles-def so that in layout.main app = logon.jsp where logon.jsp submit is associated with a struts action. In the struts action I set the layout.main app = layout.app ComponentDefinition layout = TilesUtil.getDefinition(layout.main, request, this.servlet.getServletContext()); layout.put(app, layout.app); It is not recommended to change a definition dynamically, unless you know very well what you do. A definition content is shared by all the website. Changing the content will be reflected to all user of the definition. If you want to change a definition attribute for the current tiles, you should do so in the tile context, which hold a temporary copy of the definition. and forward to layout.main. So basically after the action everything should be the same as my original setup. However, I get the following error on the forward Jun 20, 2003 1:16:00 PM EDT Error HTTP Included resource or file /netl-c ommons/layout.app not found from requested resource /netl-commons/layoutMain.j sp. The layout.app name has been interpreted as an URL. It appear that the Tiles mechanism hasn't catch it. I don't see how you call the action from the logon.jsp page. Cedric layoutMain.jsp is not changed during my update and looks like TABLE border=1 TRTD COLSPAN=2tiles:insert attribute=header//TD/TR TRTD COLSPAN=2tiles:insert attribute=app / /TD/TR TRTD COLSPAN=2tiles:insert attribute=footer//TD/TR /TABLE Any idea why layoutMain.jsp could load layout.app in the original, but can't when I programatically put it into layout.main? I noticed that the put method doesn't have type as an argument for specifying string, page, definition, so I hope that isn't it. - 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] - 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]
Re: [tiles] programatically putting a definition into a layout
William Salvucci wrote: with the following tiles-def, I can forward to layout.main and everything is fine: definition name=layout.main path=/layoutMain.jsp put name=header value=header.jsp / put name=app value=layout.app / put name=footer value=footer.jsp / /definition definition name=layout.app path=/layoutApp.jsp put name=mainMenu value=menu.main / put name=subMenu value=subMenu.jsp / put name=body value=welcome.jsp / /definition !-- Menu bar definition -- definition name=menu.main path=/menu.jsp putList name=items add value=Item 1 / add value=Item 2 / add value=Item 3 / /putList /definition I then modify the tiles-def so that in layout.main app = logon.jsp where logon.jsp submit is associated with a struts action. In the struts action I set the layout.main app = layout.app ComponentDefinition layout = TilesUtil.getDefinition(layout.main, request, this.servlet.getServletContext()); layout.put(app, layout.app); It is not recommended to change a definition dynamically, unless you know very well what you do. A definition content is shared by all the website. Changing the content will be reflected to all user of the definition. If you want to change a definition attribute for the current tiles, you should do so in the tile context, which hold a temporary copy of the definition. and forward to layout.main. So basically after the action everything should be the same as my original setup. However, I get the following error on the forward Jun 20, 2003 1:16:00 PM EDT Error HTTP Included resource or file /netl-c ommons/layout.app not found from requested resource /netl-commons/layoutMain.j sp. The layout.app name has been interpreted as an URL. It appear that the Tiles mechanism hasn't catch it. I don't see how you call the action from the logon.jsp page. Cedric layoutMain.jsp is not changed during my update and looks like TABLE border=1 TRTD COLSPAN=2tiles:insert attribute=header//TD/TR TRTD COLSPAN=2tiles:insert attribute=app / /TD/TR TRTD COLSPAN=2tiles:insert attribute=footer//TD/TR /TABLE Any idea why layoutMain.jsp could load layout.app in the original, but can't when I programatically put it into layout.main? I noticed that the put method doesn't have type as an argument for specifying string, page, definition, so I hope that isn't it. - 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]
Re: [tiles] programatically putting a definition into a layout
tiles context? How do I get that? The logon.jsp has a struts html:form attribute that is associated to the action class. [EMAIL PROTECTED] 06/23/03 06:05AM William Salvucci wrote: with the following tiles-def, I can forward to layout.main and everything is fine: definition name=layout.main path=/layoutMain.jsp put name=header value=header.jsp / put name=app value=layout.app / put name=footer value=footer.jsp / /definition definition name=layout.app path=/layoutApp.jsp put name=mainMenu value=menu.main / put name=subMenu value=subMenu.jsp / put name=body value=welcome.jsp / /definition !-- Menu bar definition -- definition name=menu.main path=/menu.jsp putList name=items add value=Item 1 / add value=Item 2 / add value=Item 3 / /putList /definition I then modify the tiles-def so that in layout.main app = logon.jsp where logon.jsp submit is associated with a struts action. In the struts action I set the layout.main app = layout.app ComponentDefinition layout = TilesUtil.getDefinition(layout.main, request, this.servlet.getServletContext()); layout.put(app, layout.app); It is not recommended to change a definition dynamically, unless you know very well what you do. A definition content is shared by all the website. Changing the content will be reflected to all user of the definition. If you want to change a definition attribute for the current tiles, you should do so in the tile context, which hold a temporary copy of the definition. and forward to layout.main. So basically after the action everything should be the same as my original setup. However, I get the following error on the forward Jun 20, 2003 1:16:00 PM EDT Error HTTP Included resource or file /netl-c ommons/layout.app not found from requested resource /netl-commons/layoutMain.j sp. The layout.app name has been interpreted as an URL. It appear that the Tiles mechanism hasn't catch it. I don't see how you call the action from the logon.jsp page. Cedric layoutMain.jsp is not changed during my update and looks like TABLE border=1 TRTD COLSPAN=2tiles:insert attribute=header//TD/TR TRTD COLSPAN=2tiles:insert attribute=app / /TD/TR TRTD COLSPAN=2tiles:insert attribute=footer//TD/TR /TABLE Any idea why layoutMain.jsp could load layout.app in the original, but can't when I programatically put it into layout.main? I noticed that the put method doesn't have type as an argument for specifying string, page, definition, so I hope that isn't it. - 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] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: [tiles] programatically putting a definition into a layout
I just got done figuring all that stuff out, here's an example of dynamically creating a definition, sticking it into the context, and then inserting it into a jsp: In the action: // In my original code I'm looping to create definitions for a portal-esque app // you might eliminate the vector completely java.util.Vector componentList = new java.util.Vector(); ComponentDefinition definition = new ComponentDefinition(); definition.setTemplate(/common/big_window.jsp); definition.put(window.title, Dynamic Title); definition.put(window.content, /do/some/stuff); // Stick the def into the tiles context. You can get this by extending TilesAction // or by request.getContext() (I think) context.putAttribute(templateDefinition1 , definition); componentList.add(templateDefinition1 ); request.setAttribute(componentsList, componentList); So then I've built a collection of definition names and stuck that into the request, this way I know the names to extract. If you're just using 1 definition, you could just have hardcoded the name and not sent it in the request. The following loops over the vector of def names and inserts each one, it's not pretty due to a limitation in jsps and the logic:iterate tag, and adapted from a few of the Tiles example pages: jsp:useBean id=componentsList scope=request class=java.util.Vector / % Iterator it=componentsList.iterator(); Integer index = null; int i = 1; while( it.hasNext() ) { String comp=(String)it.next(); index = new Integer(i++); % tiles:insert name=%=comp% flush=true/ Hope this helps! -Chip -Original Message- From: William Salvucci [mailto:[EMAIL PROTECTED] Sent: Monday, June 23, 2003 11:17 AM To: [EMAIL PROTECTED] Subject: Re: [tiles] programatically putting a definition into a layout tiles context? How do I get that? The logon.jsp has a struts html:form attribute that is associated to the action class. [EMAIL PROTECTED] 06/23/03 06:05AM William Salvucci wrote: with the following tiles-def, I can forward to layout.main and everything is fine: definition name=layout.main path=/layoutMain.jsp put name=header value=header.jsp / put name=app value=layout.app / put name=footer value=footer.jsp / /definition definition name=layout.app path=/layoutApp.jsp put name=mainMenu value=menu.main / put name=subMenu value=subMenu.jsp / put name=body value=welcome.jsp / /definition !-- Menu bar definition -- definition name=menu.main path=/menu.jsp putList name=items add value=Item 1 / add value=Item 2 / add value=Item 3 / /putList /definition I then modify the tiles-def so that in layout.main app = logon.jsp where logon.jsp submit is associated with a struts action. In the struts action I set the layout.main app = layout.app ComponentDefinition layout = TilesUtil.getDefinition(layout.main, request, this.servlet.getServletContext()); layout.put(app, layout.app); It is not recommended to change a definition dynamically, unless you know very well what you do. A definition content is shared by all the website. Changing the content will be reflected to all user of the definition. If you want to change a definition attribute for the current tiles, you should do so in the tile context, which hold a temporary copy of the definition. and forward to layout.main. So basically after the action everything should be the same as my original setup. However, I get the following error on the forward Jun 20, 2003 1:16:00 PM EDT Error HTTP Included resource or file /netl-c ommons/layout.app not found from requested resource /netl-commons/layoutMain.j sp. The layout.app name has been interpreted as an URL. It appear that the Tiles mechanism hasn't catch it. I don't see how you call the action from the logon.jsp page. Cedric layoutMain.jsp is not changed during my update and looks like TABLE border=1 TRTD COLSPAN=2tiles:insert attribute=header//TD/TR TRTD COLSPAN=2tiles:insert attribute=app / /TD/TR TRTD COLSPAN=2tiles:insert attribute=footer//TD/TR /TABLE Any idea why layoutMain.jsp could load layout.app in the original, but can't when I programatically put it into layout.main? I noticed that the put method doesn't have type as an argument for specifying string, page, definition, so I hope that isn't it. - 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] - 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]