How to check if my value is null or empty?

与世无争的帅哥 提交于 2019-12-02 12:42:07

问题


In my JSP code I have the following:

<s:iterator value="details" id="cle" status="rowCle">
    <s:iterator value="value" status="row" >
     <tr>
       <s:if test="%{#surname== ''}">
        <td>&nbsp;</td>
       </s:if>
       <s:else>
            <td class="reference"><s:property value="%{getText(key.longname.toLowerCase()) }" /></td>
       </s:else>

Depending on the value of surname (which is a field with getter in my object details, so it is in the value stack) I want to display the value longname or blank.

I have no problem to display {getText(key.longname.toLowerCase()), I also display surname later in my code, so my only concern is about testing the content of surname to check if it is null or empty.

I have tried several options such as

"%{#surname== ''}">
%{surname== null}'>
'%{#surname== null}'>

but none works.

I am a bit lost. anybody would have a solution please?

Thank you. B.

|improve this question

回答1:


Its better using validation.So that these validation codes will be removed from view layer(JSP). You can inherit method validate() to your action class by extending ActionSupport. Add your validation codes here.If validation catch any error it will show above the jsp page textbox.




回答2:


So finally I wrote the code:

<s:if test="%{ (surname!=null) && (!surname.isEmpty()) }">

and inverted the content of the if and the else, as the test is the opposite.

No need for # or {.... because surname is in the value stack so it is directly accessible.




回答3:


the “debug” tag is a very useful debugging tag to output the content of the “Value Stack” and also the “Stack Context” details in the web page

for more reference u may see this link Debugging Struts <s:debug /> in body



来源:https://stackoverflow.com/questions/24325529/how-to-check-if-my-value-is-null-or-empty

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!