I'm using JSF 2 with PrimeFaces 4.0.
I have a form with some inputs and validation. Some fields may automatically filled when choosing an entity from a dialog. This works fine when I choose the entity before I submit the whole form (and validate). But when I choose an entity after validation the update of the component does not work.
JSF page:
<h:form id="form">
<p:inputText id="id" value="#{bean.user.id}" required="true"
onclick="PF('usersDialog').show()" />
<p:inputText id="name" value="#{bean.user.name}" required="true"
onclick="PF('usersDialog').show()" />
<p:commandButton value="submit" action="#{bean.submit}" update=":form" />
</h:form>
<p:dialog widgetVar="usersDialog">
<h:form>
<p:dataTable value="#{bean.users}" var="user">
<p:column>
<p:commandButton value="choose" onclick="PF('usersDialog').hide()"
process="@this" action="#{bean.select(user)}" update=":form" />
</p:column>
<p:column>
<h:outputText value="#{user.name}" />
</p:column>
</p:dataTable>
</h:form>
</p:dialog>
I know its up to the JSF lifecycle, but I'm not able to fix it. So how can I update the form after validation fail when choosing an new entity from dialog?
Thanks in advance.
Exactly for this purpose, <p:resetInput>
component was introduced (based on OmniFaces ResetInputAjaxActionListener
).
Nest it inside the command button, with a target
set to the same client ID as update
attribute of command button:
<p:commandButton ... update=":form">
<p:resetInput target=":form" />
</p:commandButton>
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