Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

struts2: enum in IF

How does the following Java condition translate into s:if test="..." in struts2?

if(company.getAffiliateId().asInt() != com.foo.bar.Affiliates.XYZ.asInt()){
 // do something
}

company.getAffiliateId() returns BigDecimal

com.foo.bar.Affiliates is an enum

This doesn't work:

<s:if test="%{company.affiliateId.asInt() != com.foo.bar.Affiliates.XYZ.asInt() }">
   alert("do something");
</s:if>
like image 391
kosmičák Avatar asked Nov 14 '12 09:11

kosmičák


2 Answers

Use toString method to compare enums.

<s:if test="ENUM.toString() == 'some_enum_as_string'">

And if you want to use enums in JSP

<s:if test="@[email protected]() == 'some_enum_as_string'">
like image 96
Aleksandr M Avatar answered Sep 22 '22 17:09

Aleksandr M


Got it, this works for me:

<s:if test="%{company.affiliateId != @[email protected]() }">
like image 45
kosmičák Avatar answered Sep 21 '22 17:09

kosmičák