tags:

views:

29

answers:

1

Hi,

I am building a JSF applcaition.

I defined the GUI and did the select statements query the database using select.

Now i must do the insert statements but i don't know how to read the value of a h:inputText and send it to my bean which performs the insert.

Should h:inputText value be mapped throught faces-config , so i can have it in my java code?

Please advice me !

Any examples are welcomed !

Thanks ,

+3  A: 

JSF has already "send" it to your bean :) All you need to do is to access them in the action method associated with the submit button the usual Java way.

Given this JSF form example:

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

The following bean prints the submitted value to the stdout, proving that JSF has already set the value long before the moment you access it in the action method.

public class Bean {

    private String value;

    public String submit() {
        System.out.println("Submitted value: " + value);
        return null;
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

}

That's all.

I'd suggest to get yourself through some basic JSF tutorials to learn how it all works. If you mention the JSF version you're using (1.x and 2.x makes quite a difference, I personally warmly recommend 2.x), then I can suggest some useful links. To start, the following is a good one to learn about the JSF lifecycle (this was written with JSF 1.2 in mind, but this applies as good on JSF 2.0): Debug JSF lifecycle.

BalusC