Question

I am writing a simple webpage with EJB and JSF. For my webpresentation I need a page with inputFields and checkboxes. In order to get the input from my webpage into a javaclass I need to configure my faces-config.xml file. Here comes my problem: The checkboxes produce boolean values. Boolean is a primitive datatype. In my javaclass I would define primitives in such a manner

    private boolean checkBox1;
    private boolean checkBox2;

But my faces-config.xml does not recognize this datatype. It wants me to define it via java.lang.Boolean. If i do that everything is fine but it feels wrong to have code like this in any javaclass:

    private java.lang.Boolean checkBox1;
    private java.lang.Boolean checkBox2;

Is there any way to "teach" faces-config.xml what primitives are? :)

Was it helpful?

Solution

In order to get the input from my webpage into a javaclass I need to configure my faces-config.xml file

This isn't making any sense. Just bind the component's value to the bean property directly. The following works just fine for me without any faces-config.xml registration (JSF 2.x assumed):

<h:form>
    <h:selectBooleanCheckbox value="#{bean.checked}" />
    <h:commandButton value="submit" action="#{bean.submit}" />
</h:form>

with

@ManagedBean
@RequestScoped
public class Bean {

    private boolean checked;

    public void submit() {
        System.out.println(checked);
    }

    public boolean isChecked() {
        return true;
    }

    public void setChecked(boolean checked) {
        this.checked = checked;
    }

}

I made a tutorial where they used the graphical editor of the faces-config.xml

Don't use a graphical editor. Don't drag'n'drop code. You won't learn writing code this way. Just write code yourself. You can however use shortcuts/wizards to autogenerate getters/setters and likes. But with that, you should still be sitting in a textbased editor.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top