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

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

What I have done so far

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

in jsp i do as

 <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> 

The problem is that it does not work :(, I cannot see the names, and they are visible if I delete the <s:if> block.

+7
source share
1 answer

Try with this

 <s:if test="%{#user.name != null && #user.name != ''}"> <s:property value="#user.name"/> <!-- Do some thing... --> </s:if> 
+16
source

All Articles