Menu

Reset the input text in the Create dialogue after selecting Cancel

2015-10-24
2015-11-09
  • GeraldScott

    GeraldScott - 2015-10-24

    When a user enters data in the Create dialogue and then selects Cancel because it failed the validation, the data remains in the form because Cancel just hides the dialogue.

    If the user subsequently tries to create a new entity, the Create dialogue is pre-populated with the data from the earlier cancelled attempt.

    To prevent this from happening, you have to explicitly clear the input text when you cancel the dialogue, as follows:

    (1) in the Cancel commandButton, add an actionListener that will reset the input text

    <p:commandButton value="#{localizationBundle.Cancel}"
            actionListener="#{myBackingBean.clear('MyForm:display')}"
            immediate="true" ajax="false">
            <p:resetInput target="display" />
    </p:commandButton>
    

    (2) add a method in the backing bean to reset the target

    /**
     * Reset the input text fields when the Create dialogue is cancelled 
     */
    public void clear(String target) {
            RequestContext.getCurrentInstance().reset(target);
    }
    

    *Edit: this is an updated solution, using Primefaces ResetInput insted.

     

    Last edit: GeraldScott 2015-10-25
    • Kay Wrobel

      Kay Wrobel - 2015-11-06

      Yeah, this is an old issue that I never tackled. Thanks for reminding me. I have to reengage with my coding on the project as I've been very busy with other things work and life related. I will make sure to apply your suggestion to my current dev copy and it will be part of the next release. I promise.

       
  • Kay Wrobel

    Kay Wrobel - 2015-11-09

    Hi Gerald. I'm checking out your solution right now.

     

Anonymous
Anonymous

Add attachments
Cancel