user1006080
user1006080

Reputation: 75

struts2 evaluate empty string

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?

Upvotes: 2

Views: 5455

Answers (1)

Dave Newton
Dave Newton

Reputation: 160301

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.

Upvotes: 2

Related Questions