I have form with two inputs, where one value depends on another. When user change one field I need to recalculate values (this is done in setter methods) and update the form.
This is my example:
<h:form>
<p:inputText id="price1" value="#{bean.price1}"}">
<p:ajax event="blur" update="@this, price2"/>
</p:inputText>
<p:inputText id="price2" value="#{bean.price2}">
<p:ajax event="blur" update="@this, price1"/>
</p:inputText>
</h:form>
The problem is that after update focus is lost e.g. if user moves from price1 to price2 using Tab key.
You can try this:
<h:form id="fm">
<script type="text/javascript">
function test(){
$(PrimeFaces.escapeClientId('fm:price2')).focus();
}
</script>
<p:inputText id="price1" value="#{bean.price1}" >
<p:ajax event="blur" oncomplete="test();" update="@this, price2" listener="#{bean.hand}"/>
</p:inputText>
<p:inputText widgetVar="xxx" id="price2" value="#{bean.price2}">
<p:ajax event="blur" update="@this, price1"/>
</p:inputText>
</h:form>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With