Hi,

The truth is that there isn't a 'for-free' solution, but you can come up with 
something moderately elegant if you think about it.

The first thing I did was to write a simple JSP function that replaces the 
ternary operator in JSP el - nothing wrong with that, it just takes a lot of 
typing each time:

public class DisplayFunctions {
  public static String printIfMatches(String s1, String s2, String value) {
    if(s1 == null || s2 == null) return "";
    if(s1.matches(s2)) return value;
    return "";
  }
}

I then use this function to control the output of the 'active' class on my 
menus.

Assuming I have a 'top' menu, which when clicked brings up a contextual 
sub-menu, I group my ActionBeans by package so that I can do something like:

<li class="${df:printIfMatches(actionBean.class.package.name, 
                                                                        
'com.myapp.action.admin', 'active')}">
    <fmt:message key="link.admin" var="admin"/>
     <s:link beanclass="com.myapp.action.admin.AdminHomeActionBean" 
                                                                                
        rel="${admin}">${admin}</s:link>
</li>
<li class="${df:printIfMatches(actionBean.class.package.name, 
                                                                 
'com.myapp.action.ordering', 'active')}">
    <fmt:message key="link.ordering" var="ordering"/>
     <s:link beanclass="com.myapp.action.ordering.OrderingHomeActionBean" 
                                                                          
rel="${ordering}">${ordering}</s:link>
</li>

Then in the sub-menus (use a separate JSP file - better still a tag file - to 
make it simple to include), something like:

<ul id="submenutabs">
        <li>
                <s:link beanclass="com.myapp.action.admin.RoleActionBean" 
                                
class="${df:printIfMatches(actionBean.class.simpleName, 
                                'RoleActionBean', 'active')}">
                                <fmt:message key="link.manageRoles"/></s:link>
        </li>
        <li>
                <s:link beanclass="com.myapp.action.admin.UserActionBean" 
                                
class="${df:printIfMatches(actionBean.class.simpleName, 
                                'UserActionBean', 'active')}">
                                <fmt:message key="link.manageUsers"/></s:link>
        </li>
        <li>    
                <s:link beanclass="com.myapp.action.admin.PropertiesActionBean" 
                                
class="${df:printIfMatches(actionBean.class.simpleName, 
                                'PropertiesActionBean', 'active')}">
                                <fmt:message 
key="link.manageApplicationProperties"/></s:link>                          
        </li>
</ul>

Better still, each repeating block (so <li>, <s:link>, etc.) should also be 
defined in a separate JSP tag file (with the items that differ - package name, 
etc. - supplied via parameters) so that you can reduce the amount of typing 
further still.

Hope that this helps in some way, or at least gives you something useful to 
think on.

Cheers
Stu




------------------------------------------------------------------------------
The Palm PDK Hot Apps Program offers developers who use the
Plug-In Development Kit to bring their C/C++ apps to Palm for a share
of $1 Million in cash or HP Products. Visit us here for more details:
http://p.sf.net/sfu/dev2dev-palm
_______________________________________________
Stripes-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-users

Reply via email to