Thanks in advance for your time.
I need to preselect a radio button if it has a saved value. I basically need to compare 2 strings in the valuestack to determine this.
(I can't use <s:radio
at the moment because of some business rules I need to attach based on other input elements in the form).
I tried to do <s:set
the value of the saved id inside s:iterate
like below and then compare them like below but obviously I didnt get it right.
<s:set var="savedId" value="%{flag.problemId}"/>
<s:iterator value="problemIdList">
<s:set var="currentId" value='<s:property value="id"/>' />
<s:if test="%{#currentId.equals(#savedId)}" >
<input checked="checked" type="radio" name="problemId" id="problemId" value='<s:property value="id"/>'/> <s:property value="description"/> <br/>
</s:if>
<s:else>
<input type="radio" name="problemId" id="problemId" value='<s:property value="id"/>'/> <s:property value="description"/> <br/>
</s:else>
</s:iterator>
Basically I need to compare the two strings, my code is below. I know I can't compare with equals() like I have below - any ideas?
Thanks a bunch!
<s:set var="savedId" value="%{flag.problemId}"/> <s:iterator value="problemIdList">
<s:if test=' <s:property value="id"/>.equals(<s:property value="savedId"/>) '>
<input checked="checked" type="radio" name="problemId" id="problemId" value='<s:property value="id"/>'/> <s:property value="description"/> <br/>
</s:if>
<s:else>
<input type="radio" type="radio" name="problemId" id="problemId" value='<s:property value="id"/>'/> <s:property value="description"/> <br/>
</s:else>
Regards, VeeCan
Have you tried:
<s:if test='id.equals(savedId)'>
If "id" is a string OGNL will allow you to use methods of String.