struts2如果标签不能正常工作

时间:2014-01-31 06:52:08

标签: java if-statement struts2

我在表单中使用<s:if>。我的表格是:

<form theme="simple" action="saveDetailsRecBackupConf" method="post" >
    <table id="form_table" border="1">
        <tr>
            <td>Rule Name : </td>
            <td>
                <s:if test='%{rulename == ""}'>
                    Rule name (in if) : '<s:property value="rulename"/>'
                    <input name="rulename" id="rulename" value="">
                </s:if>
                <s:else>
                    Rule name (in else) : '<s:property value="rulename"/>'
                    <input name="rulename" id="rulename" readonly="readonly" value="<s:property value="rulename"/>">
                </s:else>
            </td>
            <td>Frequency : </td>
            <td>
                <s:if test='%{frequency == 0}'>
                    <s:select id="frquency" list="#@java.util.LinkedHashMap@{'15':'15 minutes', '30':'30 minutes', '60':'60 minutes', '120':'120 minutes', '240':'240 minutes', '480':'480 minutes'}" value="60" name="frequency" theme="simple"  style="width: 150px;"/>
                </s:if>
                <s:else>
                    <s:select id="frquency" list="#@java.util.LinkedHashMap@{'15':'15 minutes', '30':'30 minutes', '60':'60 minutes', '120':'120 minutes', '240':'240 minutes', '480':'480 minutes'}" value="frequency" name="frequency" theme="simple"  style="width: 150px;"/>
                </s:else>
            </td>
        </tr>
    </table>
    <input type="submit" value="SAVE" name="SUBMIT" id="save" />
</form>

即使rulename == ""<s:else>始终运行。我也试过了rulename.equals(""),但没有任何变化。

O / P就像:

Rule name (in else) : ''
//readonly and empty text filed

1 个答案:

答案 0 :(得分:0)

试试这个

<s:if test='%{rulename == null || rulename.trim().isEmpty()}'>
    Rule name (in if) : '<s:property value="rulename"/>'
    <input name="rulename" id="rulename" value="">
</s:if>