Radio button in JSF doesn't set value properly -


my jsf radio button doesn't work , don't know why. here' code:

        <h:selectoneradio value="#{jsfdatabase.type}">             <f:selectitem itemvalue="0" itemlabel="database" />             <f:selectitem itemvalue="1" itemlabel="webservice" />         </h:selectoneradio>          <h:outputlabel value="#{jsfdatabase.type }" /> 

if click other radio button value still 0 (default). why code not working? getter , setter here:

public string gettype() {     return type; }  public void settype(string type) {     this.type = type; } 

how can fix issue?

you need either use <f:ajax /> re-render affected regions of page, or, if prefer not use ajax, post form. otherwise, data won't updated.

for example, this:

    <h:selectoneradio value="#{jsfdatabase.type}">         <f:selectitem itemvalue="0" itemlabel="database" />         <f:selectitem itemvalue="1" itemlabel="webservice" />         <f:ajax execute="@form" render="myvalue" />     </h:selectoneradio>      <h:outputlabel id="myvalue" value="#{jsfdatabase.type }" /> 

see: http://docs.oracle.com/javaee/6/javaserverfaces/2.1/docs/vdldocs/facelets/f/ajax.html https://www.mkyong.com/jsf2/jsf-2-button-and-commandbutton-example/


Comments