EColi
EColi

Reputation: 77

How to check if my value is null or empty?

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.

Upvotes: 1

Views: 6545

Answers (3)

afsal parangooz
afsal parangooz

Reputation: 162

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.

Upvotes: 3

EColi
EColi

Reputation: 77

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.

Upvotes: 2

MSR
MSR

Reputation: 533

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

Upvotes: 0

Related Questions