• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

TilesAction, how to???

 
Leandro Melo
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone give me an example of how to use TilesAction to dinamically modify a definition???

Or maybe, some other way to dinamically modify a definition...?

Suppose, for example

I need to change from menu.jsp to menu2.jsp depending on the user logged. So i need to change this base definition.

I heard you can do do something like that.

Where changeMenu.do is a TilesAction that can access the attributes of the definition.

Any help would be great!
 
Anthony Watson
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why don't you just return a different forward from your action, depending on the type of user logged in? Each forward could be mapped to a different tile.
 
Leandro Melo
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's not what i want.

There's no motive to have diferent definitions where the pages only differ by the menu.
It's a lot more reasonable to change the menu of the definition depending on the user logged in.

Here's some interesting stuff i found.
http://www.junlu.com/msg/45975.html
[ August 16, 2004: Message edited by: Leandro Melo ]
 
Anthony Watson
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know how to do it like you are talking about, but its not a big deal to create a second definition that inherits from the first and overrides the menu.jsp value and doesn't specify any other values.
 
Leandro Melo
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Suppose then that it's a base definition.
I'm gonna have to duplicate all definitions i have (i'm gonna have 2 types of definitions, the ones that extend from def1 and the other ones that extend from def2) just because of a menu.
Changing wich menu should be displayed dinamically, all other children definitions of the application are already usable.
Think of how bad it would be keeping forwarding to 3 o 4 definitions (supposing i got 3 or 4 diferent menus) that are composed by the exactly same stuff just because of a menu. It's such a bad architecture.
 
Anthony Watson
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did't realize at first that your menu would be on every page. You're right, it sounds like you do need to go another route than what I suggested. Good luck. If you get that TilesAction thing to work, I'd love to see an example of it posted here.
 
Sree Jag
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Leandro,

I had the same requirement too. I did something like this:

<logic:equal name="type" value="HS">
<tiles:insert attribute="styleNavigation"/>
</logic:equal>

<logic:equal name="type" value="HR">
<tiles:insert attribute="navigationRegular"/>
</logic:equal>

where these two attributes are defined in your tiles definition.
i.e i just passed some parameters to the root layout definition JSP


this may not be the exact way u r looking for or i am being too simplistic.

Seshu
 
Anthony Watson
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good news, I figured out how to do what you want, using the method you requested, the TilesAction way. You basically create a new class that can dynamically change your tiles and then tell the definition to look for it before it is displayed.

Below is the code. All you need to do is to change the code in the DynamicTileController to check to see if the user has logged in before you change the menu.

tiles-defs.xml

struts-config.xml

DynamicTileController.java

base.jsp

loginBody.jsp

headerLoggedIn.jsp

page2.jsp

[ August 17, 2004: Message edited by: Anthony Watson ]
 
Leandro Melo
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anthony,
didn`t test your code yet, but that`s what i was taking about.
It seems to be very nice.
The TilesAction class provides a nice api to get/put attributes.
Not too many people know about that, but it`s a nice feature.
The other link i sent in my second post also has some sample code for those interesteds.

Thanks and Regards,
ltcmelo
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic