Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems dynamically controlling taglibs in a struts template

Status
Not open for further replies.

Kindon

Programmer
Apr 19, 2001
54
US
I created a template using Tiles. No problem. I needed a dynamic menuing system. So I created a tag lib that would output the desired menu based on a parameter passed to it. I then put the taglib in the tamplate like this:

<table>
<tr><nd:tabmgr page=&quot;main&quot;/></tr>
</table>

This works great other than now all pages that use the template have the &quot;main&quot; menu tab highlighted. So I need to dynamically change page. Ok. Fine. Use the template to define page, right? I tried this:

<table>
<tr><nd:tabmgr page=&quot;<tiles:get name=&quot;page&quot;/>&quot;/></tr>
</table>

Well, I quickly found out I cannot use a jsp tag as an attribute to another jsp tag. This is a no go. Makes sense, but, how do I get my menu to work? I want the tempate to control the menu. If possible, I want the tamplate to control a taglib that controls the the menu. Any ideas?
 
This is what I found....

Near the beginning of the page use the struts tiles template tag <tiles:importAttribute/>. This will make all the template attributes available in pageContext. Now you can access the template settings with pageContext.getAttribute(&quot;attributeName&quot;).

Get rid of the page=&quot;&quot; attribute in the taglib and then change the taglib so that it accepts a body. Now you can do something like this:

<nd:tabmgr><%= pageContext.getAttribute(&quot;tab&quot;).toString()%></nd:tabmgr>

Remember pageContext attributes are java.lang.Object not strings. You have to get the string. This was the main thing that I did not understand before and it held me up for a long time.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top