0

My JSF radio button doesn't work and I don't really know why. Here' some 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 I click the other radio button the value is still 0 (default). Why is this code not working? The Getter and Setter are here:

public String getType() {
    return type;
}

public void setType(String type) {
    this.type = type;
}

How can I fix that issue?

Kukeltje
  • 12,223
  • 4
  • 24
  • 47
Mongos
  • 71
  • 1
  • 2
  • 10
  • What would be the scope of `jSFDatabase`? Are you posting the form after changing the selection? – Haroldo_OK Apr 05 '17 at 18:09
  • Do you mean a button or something else? No I don't do that how shoud I change the code? – Mongos Apr 05 '17 at 18:14
  • You would need to either use a `` to post the form and re-render the page, or use `` to explicitly re-render a region of the page. – Haroldo_OK Apr 05 '17 at 18:33

1 Answers1

0

You would need to either use <f:ajax /> to re-render the affected regions of the page, or, if you prefer not to use AJAX, post the form. Otherwise, the data won't be updated.

For example, you could do 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/

Haroldo_OK
  • 6,612
  • 3
  • 43
  • 80