You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Affan Qureshi <qu...@etilize.com> on 2003/03/10 05:40:14 UTC
[Tiles] Design - Overriding items
I have divided the modules(logical) in my application in a Tab layout. I
want to show different pages under the same tab at various points in the
application. It means the putList items change all the time. If I want to
extend and override the values inside the putList tags I have to write the
whole putList tag again in the extended definition. Is this right or is
there a better way?
I have created a bean in which I keep values for links to display in each
tab and modify them at runtime in my Action classes. I put that bean in
session and copy its properties to the TilesContext in the controllerClass
actions. The problem is that this design is not very easy to maintain and
enhance. Also I get the values mixed up in the session which makes the user
go to a wrong page sometimes. And the layout code is all over the place
instead of a single, configurable one (like the XML file).
Is this the right design I have? Any suggestions/solutions?
Thanks a lot,
Affan
PS
My Tiles Code below:
This is my basic/default definition:
<definition name="index.page" path="/webpages/layouts/tabsLayout.jsp"
controllerClass="com.etilize.cms.web.actions.LayoutProcessorAction">
<put name="title" value="MyAppName"/>
<put name="header" value="/webpages/header.jsp"/>
<put name="footer" value="/webpages/footer.jsp"/>
<put name="selectedIndex" value="0"/>
<put name="parameterName" value="selected"/>
<putList name="tabList">
<item value="Home" link="/webpages/home.jsp"
classtype="org.apache.struts.tiles.beans.SimpleMenuItem"/>
................
<item value="Taxonomy" link="/webpages/template.jsp"
classtype="org.apache.struts.tiles.beans.SimpleMenuItem"/>
..................
<item value="Search" link="/webpages/search.jsp"
classtype="org.apache.struts.tiles.beans.SimpleMenuItem"/>
</putList>
</definition>
In actions i have the following code to set the values in the session bean:
LayoutSettings settings =
(LayoutSettings)req.getSession(true).getAttribute(WebAppConstants.TAB_LAYOUT
_SETTINGS);
List tabList = settings.getTabList();
SimpleMenuItem searchTab = (SimpleMenuItem)tabList.get(3);
searchTab.setLink(returnLink);
tabList.set(3,searchTab);
settings.setTabList(tabList);
req.getSession(true).setAttribute(WebAppConstants.TAB_LAYOUT_SETTINGS,settin
gs);
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: [Tiles] Design - Overriding items
Posted by Affan Qureshi <qu...@etilize.com>.
Thanks for the explanation. I have also implemented a similar solution (by
looking at the examples). The problem i am facing is the modification of
session value in the actions. I mean when the session values are modified in
each Action, it makes my code hard to maintain and error-prone. Because now
the layout logic is spread all over the place in my actions. I know this is
more of a design issue than an implementation one.
Also, sometimes I need to forward to actions but also want to pass
parameters to it in the query string. In this case I cannot use
mapping.findForward("Success"). I have to create a new ActionForward object
and provide the url plus the query string. This is again hard-coding of the
urls. Is there any way I can specify request paramters for a forward in
Tiles or Struts?
Thanks,
Affan
> In tiles examples I use the following for a user customized menu:
>
> * A definition contain the attributes for the menu, with a list of
> default items to show.
> * The controller try to retrieve a customized list of items (from
> the session, but could be from a persistent storage)
> o If the list isn't found, get the one defined in the tile
> context from the definition, copy it and store it
> appropriately in the session. So, the list in the definition
> is used to initialize the default values !
> * Replace the list in the tile context with the customized one
> * Return from the controller and show the tile
>
> In this scenario, the definition is used to defined the default
> values. So, the management still centralized in the xml file. The
> controller is used to prepare appropriately the data to show.
>
> Hope this help,
>
> Cedric
>
> >
> >Thanks a lot,
> >Affan
> >
> >PS
> >My Tiles Code below:
> >
> >This is my basic/default definition:
> >
> ><definition name="index.page" path="/webpages/layouts/tabsLayout.jsp"
> >controllerClass="com.etilize.cms.web.actions.LayoutProcessorAction">
> > <put name="title" value="MyAppName"/>
> > <put name="header" value="/webpages/header.jsp"/>
> > <put name="footer" value="/webpages/footer.jsp"/>
> > <put name="selectedIndex" value="0"/>
> > <put name="parameterName" value="selected"/>
> > <putList name="tabList">
> > <item value="Home" link="/webpages/home.jsp"
> >classtype="org.apache.struts.tiles.beans.SimpleMenuItem"/>
> > ................
> > <item value="Taxonomy" link="/webpages/template.jsp"
> >classtype="org.apache.struts.tiles.beans.SimpleMenuItem"/>
> > ..................
> > <item value="Search" link="/webpages/search.jsp"
> >classtype="org.apache.struts.tiles.beans.SimpleMenuItem"/>
> > </putList>
> ></definition>
> >
> >In actions i have the following code to set the values in the session
bean:
> > LayoutSettings settings =
>
>(LayoutSettings)req.getSession(true).getAttribute(WebAppConstants.TAB_LAYOU
T
> >_SETTINGS);
> > List tabList = settings.getTabList();
> > SimpleMenuItem searchTab = (SimpleMenuItem)tabList.get(3);
> > searchTab.setLink(returnLink);
> > tabList.set(3,searchTab);
> > settings.setTabList(tabList);
> >
>
>req.getSession(true).setAttribute(WebAppConstants.TAB_LAYOUT_SETTINGS,setti
n
> >gs);
> >
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: [Tiles] Design - Overriding items
Posted by Cedric Dumoulin <ce...@apache.org>.
Hi,
Affan Qureshi wrote:
>I have divided the modules(logical) in my application in a Tab layout. I
>want to show different pages under the same tab at various points in the
>application. It means the putList items change all the time. If I want to
>extend and override the values inside the putList tags I have to write the
>whole putList tag again in the extended definition. Is this right or is
>there a better way?
>
>
It is right, the list itself is not extended ;-(. This is an
enhancement request. I am not sure if it is already in bugzilla.Feel
free to add it or vote for it.
>I have created a bean in which I keep values for links to display in each
>tab and modify them at runtime in my Action classes. I put that bean in
>session and copy its properties to the TilesContext in the controllerClass
>actions. The problem is that this design is not very easy to maintain and
>enhance. Also I get the values mixed up in the session which makes the user
>go to a wrong page sometimes. And the layout code is all over the place
>instead of a single, configurable one (like the XML file).
>
>Is this the right design I have? Any suggestions/solutions?
>
In tiles examples I use the following for a user customized menu:
* A definition contain the attributes for the menu, with a list of
default items to show.
* The controller try to retrieve a customized list of items (from
the session, but could be from a persistent storage)
o If the list isn't found, get the one defined in the tile
context from the definition, copy it and store it
appropriately in the session. So, the list in the definition
is used to initialize the default values !
* Replace the list in the tile context with the customized one
* Return from the controller and show the tile
In this scenario, the definition is used to defined the default
values. So, the management still centralized in the xml file. The
controller is used to prepare appropriately the data to show.
Hope this help,
Cedric
>
>Thanks a lot,
>Affan
>
>PS
>My Tiles Code below:
>
>This is my basic/default definition:
>
><definition name="index.page" path="/webpages/layouts/tabsLayout.jsp"
>controllerClass="com.etilize.cms.web.actions.LayoutProcessorAction">
> <put name="title" value="MyAppName"/>
> <put name="header" value="/webpages/header.jsp"/>
> <put name="footer" value="/webpages/footer.jsp"/>
> <put name="selectedIndex" value="0"/>
> <put name="parameterName" value="selected"/>
> <putList name="tabList">
> <item value="Home" link="/webpages/home.jsp"
>classtype="org.apache.struts.tiles.beans.SimpleMenuItem"/>
> ................
> <item value="Taxonomy" link="/webpages/template.jsp"
>classtype="org.apache.struts.tiles.beans.SimpleMenuItem"/>
> ..................
> <item value="Search" link="/webpages/search.jsp"
>classtype="org.apache.struts.tiles.beans.SimpleMenuItem"/>
> </putList>
></definition>
>
>In actions i have the following code to set the values in the session bean:
> LayoutSettings settings =
>(LayoutSettings)req.getSession(true).getAttribute(WebAppConstants.TAB_LAYOUT
>_SETTINGS);
> List tabList = settings.getTabList();
> SimpleMenuItem searchTab = (SimpleMenuItem)tabList.get(3);
> searchTab.setLink(returnLink);
> tabList.set(3,searchTab);
> settings.setTabList(tabList);
>
>req.getSession(true).setAttribute(WebAppConstants.TAB_LAYOUT_SETTINGS,settin
>gs);
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: [Tiles] Design - Overriding items
Posted by Dan Allen <da...@mojavelinux.com>.
Man, I had this exact same question...I am eagerly awaiting a
discussion on this topic. Particularly the modification of the
putList through the definition file inheritance.
Dan
Affan Qureshi (quereshi@etilize.com) wrote:
> I have divided the modules(logical) in my application in a Tab layout. I
> want to show different pages under the same tab at various points in the
> application. It means the putList items change all the time. If I want to
> extend and override the values inside the putList tags I have to write the
> whole putList tag again in the extended definition. Is this right or is
> there a better way?
>
> I have created a bean in which I keep values for links to display in each
> tab and modify them at runtime in my Action classes. I put that bean in
> session and copy its properties to the TilesContext in the controllerClass
> actions. The problem is that this design is not very easy to maintain and
> enhance. Also I get the values mixed up in the session which makes the user
> go to a wrong page sometimes. And the layout code is all over the place
> instead of a single, configurable one (like the XML file).
>
> Is this the right design I have? Any suggestions/solutions?
>
> Thanks a lot,
> Affan
>
> PS
> My Tiles Code below:
>
> This is my basic/default definition:
>
> <definition name="index.page" path="/webpages/layouts/tabsLayout.jsp"
> controllerClass="com.etilize.cms.web.actions.LayoutProcessorAction">
> <put name="title" value="MyAppName"/>
> <put name="header" value="/webpages/header.jsp"/>
> <put name="footer" value="/webpages/footer.jsp"/>
> <put name="selectedIndex" value="0"/>
> <put name="parameterName" value="selected"/>
> <putList name="tabList">
> <item value="Home" link="/webpages/home.jsp"
> classtype="org.apache.struts.tiles.beans.SimpleMenuItem"/>
> ................
> <item value="Taxonomy" link="/webpages/template.jsp"
> classtype="org.apache.struts.tiles.beans.SimpleMenuItem"/>
> ..................
> <item value="Search" link="/webpages/search.jsp"
> classtype="org.apache.struts.tiles.beans.SimpleMenuItem"/>
> </putList>
> </definition>
>
> In actions i have the following code to set the values in the session bean:
> LayoutSettings settings =
> (LayoutSettings)req.getSession(true).getAttribute(WebAppConstants.TAB_LAYOUT
> _SETTINGS);
> List tabList = settings.getTabList();
> SimpleMenuItem searchTab = (SimpleMenuItem)tabList.get(3);
> searchTab.setLink(returnLink);
> tabList.set(3,searchTab);
> settings.setTabList(tabList);
>
> req.getSession(true).setAttribute(WebAppConstants.TAB_LAYOUT_SETTINGS,settin
> gs);
--
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Daniel Allen, <da...@mojavelinux.com>
http://www.mojavelinux.com/
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Rumour has it that bad dreams about Windows can be ended by
putting on a pair of Tux slippers and clicking your heels
together 3 times while saying.
"There's no place like /home."
"There's no place like /home."
"There's no place like /home."
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org