Creating yes and no switches using struts2 and freemarker

In my struts2 application, I would like to bind the boolean property (let it draw frobbed using isFrobbed () getter) on my controller with a couple of yes and no radio buttons (I know that I can use the checkbox, but for various reasons we preferred would be a clear yes and no)).

Using the checkbox, I will do something like this:

<@s.checkbox name="frobbed" label="would you like this to be frobbed?" /> 

However, with the switches I completely lost. I know there is a struts2 tag called "radio", but I'm not sure how it is used. For example, this does not work.

 <@s.radio name="frobbed" value="true" label="Please frob this object" /> <@s.radio name="frobbed" value="false" label="No frobbing, thanks." /> 

I would like this to be related to the "frobbed" value in the controller, so that, for example, when the value is true, the yes camera is automatically selected.

Any ideas?

+4
source share
3 answers

This syntax works with FreeMarker for logical selection:

 <@s.radio label="" name="frob" list="#@ java.util.LinkedHashMap@ {true:'Frob it',false:'Leave unfrobbed'}" /> 
+4
source

When the choice is simple Yes / No, True / False - I prefer to define in-situ options inside jsp. Sort of..

 <s:radio label="Frobbed?" list="#{true:'Frob Me',false:'Leave me Frobless'}" name="frobbed" value="%{frobbed}"></s:radio> 

Hello

+2
source

Typically, the <s:radio> used with a list of options (or cards). For example, with the card, the key will be the radio values ​​(for example, Boolean.TRUE and Boolean.FALSE in this case), and the value will be the label of the radio button ("Frob away", "I prefer to remain unchanged").

 <s:radio list="yesNo" name="frobbed"/> 

The value of the yesNo attribute is a list or map.

(With a list, you expose an object with a label and value and use the attributes "listKey" and "listValue" <s:radio> . (IIRC))

+1
source

All Articles