Reset input fields without executing validation

后端 未结 2 923
一整个雨季
一整个雨季 2020-11-30 09:09

I have a Facelets view as below:


 
<         


        
相关标签:
2条回答
  • 2020-11-30 09:42

    The <p:commandButton> processes indeed by default the entire form (process="@form"), you can change this by specifying only the current component in the process attribute.

    <p:commandButton value="Reset" ... process="@this" />
    

    However, this will fail if the form is already been validated beforehand. The input fields which have been marked invalid won't be updated with the new model value (which you've resetted yourself). If you're using PrimeFaces 3.4, then embed <p:resetInput> in the button:

    <p:commandButton value="Reset" ... process="@this">
        <p:resetInput target="@form" />
    </p:commandButton>
    

    If you aren't on PrimeFaces 3.4 yet and can't upgrade to it, you can use OmniFaces ResetInputAjaxActionListener for this.

    A completely different alternative is to just refresh the current page by a fresh new GET request.

    <p:button value="Reset" />
    
    0 讨论(0)
  • 2020-11-30 09:46

    This worked for me in PrimeFaces 5.3

    <p:commandButton action="#{bean.reset()}" value="Reset" process="@this" update="@form" resetValues="true" />
    

    You can probably replace the "@form" target of the update attribute to a specific component if you want.

    0 讨论(0)
提交回复
热议问题