Struts2, String null check

I am trying to do a null string check, but this will not 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>

is an

Map<Integer, List<String>>

var "col" is correctly assigned to a string value from the list.
The list may look like this: ["hello", null, "world"

Current output: hello world
Required output: hello 0 world

/Thanks in advance

+3
source share
5 answers

Try without #.

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

, "col" col . , "" , . , .

- :

<s:if test="%{licenseStatusString != null}">
 ... something that uses licenseStatusString
</s:if>
+4

, Struts2.0.x , id var s:iterator, Struts2.1.x.

Asuming Struts 2.1.x var ( )

<s:iterator value="bar" var="foo">
    <s:if test="#foo==null || #foo==''">0</s:if>
</s:iterator>

top , .

<s:iterator value="bar">
    <s:if test="top==null || top==''">0</s:if>
</s:iterator>

String - , null , ,

<s:iterator value="bar">
    <s:property /> <!-- prints iterator current value or '' if its null -->
</s:iterator>

Ps. ognl- %{} test s:if value s:property.

struts2 iterator doc

+3

.

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

, .

0

( single if):

<s:property value="%{col==null ? '0':col}"/></s:else>

<s:property value="%{col==null ? '0': 'The column is' + col}"/></s:else>
0

Struts2; 'Test Clause', '#' .

            <s:iterator value="pageVo.voList" var="vo">
                    <s:if test="%{#vo.iconclass != null}">
                        <i class="${vo.iconclass}"></i>
                    </s:if>
                    <s:if test="%{#vo.label != null}">
                        ${vo.label}
                    </s:if>
                </button>
            </s:iterator>
0

Source: https://habr.com/ru/post/1760562/


All Articles