Is there some way to replicate rails’ “link-to-unless-current”?
Ie. if i have a list of links in my navigation, and I want to mark the current page with a different css style (or even have it be plain text, not a link)?
Now I just made a method in my action-class (getPage()) which returns a name that I assign for each action, and test for that when building my navigation… Works but not pretty, and I have to manually set the page name (couldn’t struts somehow automaticalyy get it from the context).
Using Struts 2, Tiles, JSP + Struts taglibs.
To get the current url you you can use the Url tag without any params, actions, etc:
Then assuming you construct your navigation Url something like:
Then you can then use a normal if tag to test whether the current url matches on that you’ve constructed.
For example, to change the class, you can do a conditional inline to your anchor definition:
Use the includeParams=”get” if the parameters in your URL are meaningful for navigation otherwise exclude that and use an if like: