Saram Rose
Saram Rose

Reputation: 3

Struts <s:if tag does not evaluate while using information from getters

Trying to evaluate the following but not seem to work

  <s:set name="infoType" value='%{"info.aero.aeroType"}' />
  <s:if test='%{#infoType == "A"}'>
    <span> got it </span>
</s:if>

the return type for aeroType is String that is set in a Java class and it returns a alphabet "A" or "B". If infoType is A, I need to perform some calculation. How to get this working?

Upvotes: 0

Views: 172

Answers (1)

Andrea Ligios
Andrea Ligios

Reputation: 50203

  1. Use var instead of name, because it is deprecated

  2. General info on validating one character Strings (you are already flipping quotes, then this part is right)

  3. This is your real problem: you are putting double quotes around your <s:set value; this way you are telling OGNL to take that literal String, instead of reading an object from the stack;

then change this

<s:set name="infoType" value='%{"info.aero.aeroType"}' />

to this

<s:set var="infoType" value="%{info.aero.aeroType}" />

and it wil work

Upvotes: 1

Related Questions