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.
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> </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.
-
Of course!! That is how I should do it. I read about it and then totally forgot about it. Thank you for reminding me the right way to do it. – EColi Jun 23 '14 at 17:54
-
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.
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
-
I have tried ton insert this <s:debug /> but it created some errors so I left it behind, perhaps i should give it another try because it should be very useful – EColi Jun 20 '14 at 11:03
surname == null || surname == ''
. – Aleksandr M Jun 20 '14 at 10:51