-1

I have a form with tree buttons on in. One of them is the "Cancel" button that goes back to the previous page.

enter image description here

The problem is there is any validation issue, like a mandatory field not submited, the styling of the field is not reset when I go back to the form.

This is a simplified structure of the xhtml:

   <panel id="horizontal">
        <form id="filterVipLoungeForm">
        </form>
        <form id="frmAddPax">
            <form id="frmAccessType">
            </form>
        </form>
        <panelGrid>
            <commandButton value="agregar" />
            <commandButton value="limpiar" />
            <commandButton value="cancelar" />
        </panelGrid>
    </panel>

The code of the button that calls the add passenger form:

<p:commandButton
    value="#{label['manageVipLoungeEntrance.button.addPassenger']}"
    action="#{manageVipLoungeEntranceExtMB.setRenderStatus(3, 1)}"
    actionListener="#{manageVipLoungeEntranceExtMB.hideMainForm}"
    update=":filterVipLoungeForm :horizontal">
</p:commandButton>

The code of the cancel button:

<p:commandButton
    value="#{label['manageVipLoungeEntrance.button.cancel']}"
    onclick="showLocalDate()"
    action="#{manageVipLoungeEntranceExtMB.setRenderStatus(0, 1)}"
    actionListener="#{manageVipLoungeEntranceExtMB.setRenderStatus(3, 0)}"
    update=":filterVipLoungeForm :horizontal">
</p:commandButton>

This calls a method from the backing bean calls setRenderStatus that set the form and he's render status to be evaluated in the rendered attribute.

In this process the render status of the cancel button's form is set to false and the render status of the previous form is set to true.

The hideMainForm method calls two times the setRenderStatus method, setting the main form render status to false and the add passenger render status to true.

The problem there is any validation error and if I go back to the previous page and come back to the form I'm still getting the validation errors.

enter image description here

[EDIT]

Sorry I forgot to add the code of the rendered evaluation of the two forms involucrated in this:

Render status validation for form "frmAddPax"

<h:form id="frmAddPax" rendered="#{manageMB.renderStatus.isRenderFormAddPax()}">

Render status validation for form "filterVipLoungeForm"

<h:form id="filterVipLoungeForm" style="width:95% !important;"
rendered="#{manageMB.renderStatus.isRenderFormMain()}"
onkeypress="return event.keyCode != 13">

I have tried by using the <p:resetInput>but it didn't work, with this I was expecting the form with the id frmAddPax reset his status but it didn't work:

<p:commandButton
    value="#{label['manageVipLoungeEntrance.button.cancel']}"
    onclick="showLocalDate()"
    action="#{manageVipLoungeEntranceExtMB.setRenderStatus(0, 1)}"
    actionListener="#{manageVipLoungeEntranceExtMB.setRenderStatus(3, 0)}"
    update=":filterVipLoungeForm :horizontal">
    <p:resetInput target=":frmAddPax" />
</p:commandButton>
  • How is this different from https://stackoverflow.com/questions/57698791/why-jsf-form-maintain-the-validation-styles-even-if-has-values-on-it and why is there no [mcve] – Kukeltje Aug 29 '19 at 20:23
  • In this case the issue is not about that having a validation styling in red even if the textInputs have data on it. This issue is about when there is any field with the red styling this is maintained even if I go back to the previous page. – Juan Enrique Riquelme Aug 29 '19 at 20:29
  • 1
    And nested forms are bad and does https://stackoverflow.com/questions/21179403/how-to-reset-input-fields-in-a-form-after-validation-fail-when-updating-it-with help? – Kukeltje Aug 29 '19 at 20:29
  • 1
    You want to use Resetnput for this exact case: https://www.primefaces.org/showcase/ui/misc/resetInput.xhtml – Melloware Aug 29 '19 at 20:32
  • @Mellonware I have tried the before without luck but I haven't realized there was a I just used that one and works!!. Thank you!!! – Juan Enrique Riquelme Aug 29 '19 at 20:39
  • @Kukeltje I tried the resetInput but this one doesn't work, later I tried the and it works. Do you know why the last one works and the other dont't? – Juan Enrique Riquelme Aug 29 '19 at 20:45
  • 1: MENTION WHAT YOU TRIED BEFORE... 2: POST CODE OF WHAT YOU TRIED AND EXPECTED TO WORK BUT DID NOT 3: DON'T PUT SOLUTIONS IN QUESTIONS – Kukeltje Aug 30 '19 at 05:09
  • @Kukeltje question and answer edited. Hope this is in the standard now. – Juan Enrique Riquelme Aug 30 '19 at 12:16

1 Answers1

0

I used the <p:ajax resetValues="true"> and this one works as I needed. I really don't know why work with the ajax and not with the resetInput.

<p:commandButton
    value="#{label['manageVipLoungeEntrance.button.cancel']}"
    onclick="showLocalDate()"
    action="#{manageVipLoungeEntranceExtMB.setRenderStatus(0, 1)}"
    actionListener="#{manageVipLoungeEntranceExtMB.setRenderStatus(3, 0)}"
    update=":filterVipLoungeForm :horizontal">
    <p:ajax update=":frmAddPax" resetValues="true" />
</p:commandButton>