user590586
user590586

Reputation: 3050

jsf fill form fields when field onblur

I'm new in jsf, and can't find how to do the next thing: I'm trying to create a form with 8 fields (inputs). after the user enters data into the first input, when he onblur's that input I want to make a select query and get all other fields values and then fill the inputs with those values.

I think it's can be done using ajax? I can't find any example that does this.

Any help will be appriciated,

Thank's In Advance.

Upvotes: 0

Views: 7213

Answers (1)

BalusC
BalusC

Reputation: 1108852

Yes, Ajax can be used for this. You just attach a <f:ajax> to the first input which hooks on the blur event and has a listener which prepares the desired data and finally re-renders the other inputs.

E.g.

<h:inputText id="input1" value="#{bean.input1}">
    <f:ajax event="blur" listener="#{bean.input1Listener}" render="input2 input3 input4" />
</h:inputText>
<h:inputText id="input2" value="#{bean.input2}" />
<h:inputText id="input3" value="#{bean.input3}" />
<h:inputText id="input4" value="#{bean.input4}" />

with

public void input1Listener() {
    input2 = "new input2 value";
    input3 = "new input2 value";
    input4 = "new input4 value";
}

Upvotes: 2

Related Questions