I have a create form in a jspx page. One of the fields in enum type. I want to replace the select in the form with a radio button group.
It started with :
<field:select field="kyn" id="c_com_wop_fin_domain_Got_kyn" items="${kyns}" path="kyns" z="xxx="/>
I changed it to :
c:forEach var="enum" items="${gotkyns}" varStatus="pStatus">
<input type="radio" name="gotkyns" value="${gotkyns}">${gotkyns}</input>
</c:forEach>
I have two radio button but I would like to get the value of the enum in my radio buttons. How could I do that ?
My enum class looks like :
public enum GotKyn {
Hundur, Tyk
}
You could use radiobuton
or radiobuttons
tags ( Spring View technologies)
Import apropriate tag library and create data binding using
Hundur <form:radiobutton path="kyns" value="Hundur"/> <br/>
Tyk <form:radiobutton path="kyns" value="Tyk"/>
or
<form:radiobuttons path="kyns" items="${kynsValues}"/>
where kynsValues
have to be populated in Controller
. You pass in an Array, a List or a Map containing the available options in the "items" property ( Providing a link to data from the model with @ModelAttribute).
@ModelAttribute("kynsValues")
public GotKyn[] populateGotKynsTypes() {
return GotKyn.values();
}