Reputation: 1039
Mojarra 2.1.5 / PrimeFaces 3.5
I dont know how to explain that.I have one inputText and commandButton When I type something in inputText and hit Enter I need the commandButton be executed automatically.
<p:inputText id="txtProducao" required="false"
value="#{ManagedBean.xxxPreco.producaoDia}"
requiredMessage="#{bundle.xxPreco_xProdx}>
</p:inputText>
<p:commandButton id="buttonProducaoDia"
icon="ui-icon-check"
actionListener="#{ManagedBean.calculaProdxxx}"
update="txtValorSoma">
</p:commandButton>
I need to type some value for each inputText and after hit Enter I need the respective commandButton be executed :
Upvotes: 4
Views: 2839
Reputation: 11757
If you have a single p:commandButton
, then pressing ENTER should submit the form. If you have many p:commandButton
in the form. You can define the one which is the default submitted button by using the p:defaultCommand
.
<p:inputText id="txtProducao" required="false"
value="#{ManagedBean.xxxPreco.producaoDia}"
requiredMessage="#{bundle.xxPreco_xProdx}>
</p:inputText>
<p:commandButton id="buttonProducaoDia"
icon="ui-icon-check"
actionListener="#{ManagedBean.calculaProdxxx}"
update="txtValorSoma">
</p:commandButton>
<p:defaultCommand target="buttonProducaoDia" />
[Edit]
I think that you have to solve it using JavaScript, like this:
<p:inputText id="txtProducao" required="false"
value="#{ManagedBean.xxxPreco.producaoDia}"
requiredMessage="#{bundle.xxPreco_xProdx}>
<p:ajax event="keydown" update="@form" onstart="if (event.keyCode != 13) { return false; }" />
</p:inputText>
You can also add an actionListener
to the p:ajax
element. In JavaScript, you could also call a submit.
Upvotes: 5