7

I am using Struts2. And having trouble in test a String for null or empty. The String is in a loop.

What I have done so far is

in Action class I have a List<User>. User have id and name fields and have getters and setters...

in JSP i am doing like

<s:iterator value="userList" var="user" status="userStatus">
    <s:if test"%{user.name != null && user.name != ''}">
       ${user.name}
       <!-- Do some thing... -->
    </s:if>
</s:iterator>

Problem is that Its not working :(, I cannot see the names and they are visible if I remove the <s:if> block.

1 Answer 1

16

Try with this

<s:if test="%{#user.name != null && #user.name != ''}">
   <s:property value="#user.name"/>
   <!-- Do some thing... -->
</s:if>
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! It worked. I am also confused in checking string in Java works in equals(), is it same as != or == in Struts tag in JSP.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.