jsf - primeface default selection on radio buttons -
i have field 1 radio button:
xhtml:
<div class="col-md-4"> <p:selectoneradio id="gender" value="#{onegobean.gender}" required="true" requiredmessage="gender required"> <f:selectitems value="#{onegobean.gender}" /> </p:selectoneradio> </div>
bean:
import javax.faces.model.selectitem; private arraylist<selectitem> gender; public final arraylist<selectitem> getgender() { return gender; } public final void setgender(final arraylist<selectitem> gender) { this.gender = gender; } public final void loadgender() { gender = new arraylist<selectitem>(); gender.add(new selectitem("m", "male")); gender.add(new selectitem("f", "female")); }
during loadup arraylist being populated 2 genders. problem is, there no defualt value on web page. both radio buttons not selected. anyne knows why, want 1 button selected default (male)???
you mapping value of radio button list of values, should mapped single value. like:
xhtml:
<div class="col-md-4"> <p:selectoneradio id="gender" value="#{onegobean.gender}" required="true" requiredmessage="gender required"> <f:selectitems value="#{onegobean.genderlist}" /> </p:selectoneradio> </div>
bean:
import javax.faces.model.selectitem; private arraylist<selectitem> genderlist; private string gender = "m"; //give default value public final arraylist<selectitem> getgenderlist() { return genderlist; } public final void setgenderlist(final arraylist<selectitem> genderlist) { this.genderlist = genderlist; } public string getgender() { return gender; } public void setgender(string gender) { this.gender = gender; } public final void loadgender() { genderlist = new arraylist<selectitem>(); genderlist.add(new selectitem("m", "male")); genderlist.add(new selectitem("f", "female")); }
Comments
Post a Comment