Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Struts2, JSP, Test String for null and Empty in iteration

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.

like image 802
Talha Ahmed Khan Avatar asked Feb 24 '12 06:02

Talha Ahmed Khan


1 Answers

Try with this

<s:if test="%{#user.name != null && #user.name != ''}">
   <s:property value="#user.name"/>
   <!-- Do some thing... -->
</s:if>
like image 69
mini Avatar answered Sep 21 '22 10:09

mini