Question

I have a menu that's common to most of my site. If I'm on Page 1, for example, I want the "Page 1" link in the menu to be highlighted so I can compare the current action to "page1.action" and dynamically add the appropriate CSS class based on the comparison.

I've tried the following from various other Stack Overflow answers but none of them are giving me what I want:

req.contextPath: ${req.contextPath }<br/>
req.requestURL: ${req.requestURL }<br/>
pageContext.request.requestURL: ${pageContext.request.requestURL }<br/>
pageContext.request.requestURI: ${pageContext.request.requestURI }<br/>
pageContext.request.servletPath: ${pageContext.request.servletPath }<br/>
action name: ${com.opensymphony.xwork2.ActionContext.name }<br/>
action name 2: ${#context['struts.actionMapping'].name}<br/>

Here's the output:

req.contextPath: /myContextRoot
req.requestURL: http://localhost:9080/myContextRoot/WEB-INF/app/layout/simpleLayout.jsp
pageContext.request.requestURL: http://localhost:9080/myContextRoot/WEB-INF/app/layout/simpleLayout.jsp
pageContext.request.requestURI: /myContextRoot/WEB-INF/app/layout/simpleLayout.jsp
pageContext.request.servletPath: /WEB-INF/app/layout/simpleLayout.jsp
action name:
action name 2: 

I basically want something where I can do this:

<c:choose>
    <c:when test="${pageContext.request.requestURI == 'page1.action')}">
        <c:set var="page1ButtonClass" value="class=\"active\""/>
    </c:when>
</c:choose>

For what it's worth, we're using Struts 2.3.8.

Was it helpful?

Solution

Try with this code

<c:set var="actionName">
    <s:property value="%{#context['struts.actionMapping'].name}"/>
</c:set>
action name: ${actionName}<br/>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top