2

I have jsp file to display error message in

depends on whether the error string is empty or not.

 <s:if test="{!''.equals(errorMsg)}">
  <div class="errors"><s:property value="errorMsg"/></div>
 </s:if>

But whatever errorMsg is, the div section always there, why? how can solve this problem?

user1006080
  • 75
  • 1
  • 4
  • 11
  • 1
    are you sure you don't actually want the actionerror tag (http://struts.apache.org/2.0.14/docs/actionerror.html) ? – Oleg Mikheev Nov 10 '11 at 19:05

1 Answers1

2

Use !=:

<s:if test='%{errorMsg != ""}'>
    ...

Although if it can be null, you should check for that as well (the reference itself will be false if it's null).

You were constructing an immediate list containing the value of the conditional.

Either use %{} or leave it off altogether.

Note that you could add errors directly to the action as well.

Dave Newton
  • 158,873
  • 26
  • 254
  • 302