GUISSOUMA Issam
GUISSOUMA Issam

Reputation: 2582

Conditional expression in JSP with Struts2 tag

I maintain an old application developed with Struts2.

I updated Struts2 library from 2.3.19 to 2.3.24.

I'm deploying to Tomcat 8 with jdk8.

In a JSP I have this conditions that works fine with old Struts2 library, jdk 7 and Tomcat 7)

<s:if test='%{current.getClass().name == "com.mycompany.myapp.MyCalss1"}'>
  <div>Class1</div>
</s:if>
<s:if test='%{current.getClass().name == "com.mycompany.myapp.MyCalss2"}'>
  <div>Class2</div>
</s:if>

Anything changed from struts 2.3.19 to 2.3.24? or jdk8, Tomcat 8?

When I add <s:property value="%{ficheCourante}"></s:property> to the JSP it shows com.mycompany.myapp.MyCalss2@46e9d4ac.

Upvotes: 1

Views: 948

Answers (1)

Aleksandr M
Aleksandr M

Reputation: 24396

Class retrieval (i.e. current.getClass()) in JSP isn't allowed anymore due to security reasons. Create a method in your action class and do the comparison there. In JSP you can call it something like that.

<s:if test="compareCurrentClass('com.mycompany.myapp.MyCalss1')">

Or if you need to pass instance of current to compare method then:

<s:if test="compareCurrentClass(current, 'com.mycompany.myapp.MyCalss1')">

In that case declare compareCurrentClass in your action as:

public boolean compareCurrentClass(Object current, String name)

BTW currently latest S2 version is 2.3.28.

Upvotes: 2

Related Questions