Search code examples
javafacelets

Facelets: How to save properties to the view bean?


The question maybe too simple and stupid, however, I didn't get any useful information from google.

The bean class:

public class Foo {

    boolean a;

    public boolean getA() {
        return a;
    }

    public void setA(boolean a) {
        this.a = a;
    }

}

And the page:

<h:selectBooleanCheckbox value="#{foo.a}" />

Instead of a valueChangeListener, how can I write back the value of the checkbox to the "a" property in the view bean? Or generally, What's the recommended way to update the bean properties?


Solution

  • You just need to submit the form. Do this with a <h:commandButton />, for example. Make sure that both tags are within the same <h:form></h:form>.

    Generally speaking, every <h:commandSomething that has no immediate="true" attribute, will submit the form (and let the values of input fields go through conversion, validation and bean update).