Question

<p:inputText value="#{bmiCalculatorBean.height}" update="@form" id="height">
                            <p:ajax update="@form" />
                            <f:convertNumber pattern="0" />
</p:inputText>


<p:inputText value="#{bmiCalculatorBean.weight}" update="@form" id="weight">
                            <p:ajax update="@form" />
                            <f:convertNumber pattern="0" />
</p:inputText>

I have a problem where after I enter a value into the first inputText and click on the "weight" inputText after a short delay the focus is lost and you need to click on the input box again.

How do I fix this?

Was it helpful?

Solution

This is caused by update="@form" and expected behavior.

In general, just do not update parts which do not need to be updated and update only those which really need to be updated. E.g. only the result calculated so far and the <h|p:message> of the current input:

<p:ajax update="calculatedResult currentInput_message" />

True, this may end up in a boilerplate of IDs in update attribute in large forms. The PrimeFaces Selectors (PFS, supporting jQuery selector syntax in JSF selectors) may then help a lot in this.

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