2
votes

I am writing a simple tag which contains 4 attributes like so:

<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ attribute name="menuName" description="Name of Major Menu" required="true" %>
<%@ attribute name="menuSize" description="Number of Items In Menu" required="true" type="java.lang.Integer" %>
<%@ attribute name="menuImage" description="Icon for Image" required="true" %>
<%@ attribute name="menuNumber" description="Order of Positioning" required="true" %>

There is a point within a Struts 2 tag that I need to make reference to one of these attributes like so:

<s:set name="it" value="%{#application['tools'][${menuName}]}" />

So you see I am doing a lookup in the OGNL expression based upon what the menu name which was passed in. From all the examples I see, EL is the common way of referencing the attribute menuName, but in Struts 2.x EL is disabled for security reasons.

Is there a way to reference the attribute I need to reference. I really do not want to consider any solution which involves me going to previous versions of jstl or struts.

1
<s:set name="menuName" value="%{#attr['menuName']}" /> <s:set name="it" value="%{#application['tools'][#menuName]}" /> Never knew about the #attr before, how neat. Have to wait another 7 hours to answer. - demongolem
Just to clarify, EL is not disabled in Struts2. It's just disabled as a parameter value to the struts tags. You can use EL in your JSPs or in your own tag files. - Steven Benitez
Yes, thanks for the clarification. I meant specifically in a struts tag such as set. Sorry I was lazy with my vocabulary. - demongolem

1 Answers

4
votes
<s:set name="menuName" value="%{#attr['menuName']}" /> 
<s:set name="it" value="%{#application['tools'][#menuName]}" />

Never knew about the #attr before, how neat