struts2 if tag not working properly

I am using <s:if> in my form. My form is:

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

even if the rulename == "", <s:else> runs always. I've also tried rulename.equals(""), but nothing changes.

O/P is like:

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

Answers


Try this

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

Need Your Help

How to query Code First entities based on rowversion/timestamp value?

c# sql-server entity-framework ef-code-first rowversion

I've run into a case where something that worked fairly well with LINQ to SQL seems to be very obtuse (or maybe impossible) with the Entity Framework. Specifically, I've got an entity that includes a