tags:

views:

161

answers:

2

Hello,

I'm trying to do a null check on a String but it won't work.

<s:iterator value="matrix" var="row">
    <tr>
       <s:iterator value="value" var="col">
            <td>    
                <s:if test="%{#col==null}">0</s:if>
                <s:else><s:property value="col"/></s:else>
            </td>
        </s:iterator>
    </tr>
</s:iterator>

matrix is a

Map<Integer, List<String>>

The var "col" is correctly assigned a String value from the List.
The list may look like this [ "hello" , null , "world ]

Current output: hello world
Wanted output: hello 0 world

/Thanks in advance

+1  A: 

Try it without the #.

 <s:if test="%{col==null}">0</s:if>

I think the has will attempt to resolve 'col' first, and use the value of col as the property name. Since that'd be empty, it'd do a comparison of "" as the property name, which is the top of the value stack. I'm not sure how that would evaluate here.

I always use something like this:

<s:if test="%{licenseStatusString != null}">
 ... something that uses licenseStatusString
</s:if>
Shawn D.
<s:if test="%{col==null}">0</s:if> givesOutput: 0 0 0
Farmor
replace 'col' in the if with 'top' and see
Shawn D.
Thanks for the answer unfortunately this gives the same problem with an empty cell instead of null. I think I won't bother anymore with this struts problem and make the change in JAVA i.e. Loop through the array and change null to "0".
Farmor
A: 

I have solved my problem.

<s:if test="%{#col==''}">0 </s:if>

The value in the string array wasn't null but an empty String.

Farmor