0

I've this code:

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:f="http://java.sun.com/jsf/core"
  xmlns:ui="http://java.sun.com/jsf/facelets"
  xmlns:p="http://primefaces.org/ui"  >

    <h:form>
        <h1 class="page-header "> <i class="fa fa-tachometer"></i> Dashboard</h1>
        <p:outputPanel id="contentPanel">
            <p:commandButton value="Añadir caso de prueba" actionListener="#{testCaseBean.prepareCreateTestCase}" oncomplete="PF('addTestCaseDialog').show();" process="@this" update=":dialog"/>
            <p:dataTable>

            </p:dataTable>
        </p:outputPanel>
    </h:form>
    <p:dialog header="Crear caso de prueba" modal="true" id="dialog" widgetVar="addTestCaseDialog" closable="false">
        <h:form id="addTestCaseDialogForm">
            <p:panelGrid columns="4" styleClass="ui-noborder">
                <p:outputLabel for="testCaseName" value="Nombre del caso de prueba:"/>
                <p:inputText id="testCaseName" value="#{testCaseBean.testCase.testCaseName}" required="true"/>
                <p:outputLabel for="assignedTask" value="Tarea relacionada:"/>
                <p:inputText id="assignedTask" value="#{testCaseBean.testCase.assignedTask}" required="true"/>
                <p:outputLabel for="isRegressive" value="Regresivo:" />
                <p:selectBooleanCheckbox id="isRegressive" value="#{testCaseBean.testCase.isRegressive}"/>
            </p:panelGrid>
            <p:commandButton value="Guardar" actionListener="#{testCaseBean.createTestCase}" oncomplete="PF('addTestCaseDialog').hide()" process="addTestCaseDialogForm"/>
            <p:commandButton value="Cancelar" onclick="PF('addTestCaseDialog').hide()" immediate="true" />
        </h:form>
    </p:dialog>

And I'm having a problem: the actionListener method from the dialog commandButton is not being called and I don't know why. If put this in then commandButton:

<p:commandButton value="Guardar" actionListener="# {testCaseBean.createTestCase}" oncomplete="PF('addTestCaseDialog').hide()" process="@this"/>

The method is called, but the form is not processed.

Any help?

Thanks!

rlopezo
  • 425
  • 5
  • 16

3 Answers3

2

PrimeFaces provides a partial rendering and view processing feature based on standard JSF 2 APIs to enable choosing what to process in JSF lifecyle and what to render in the end with ajax.

There are a couple of reserved keywords which serve as helpers.

-@this : Component that triggers the PPR is updated

-@parent: Parent of the PPR trigger is updated.

-@form: Encapsulating form of the PPR trigger is updated

-@none: PPR does not change the DOM with ajax response.

-@all: Whole document is updated as in non-ajax requests.

In Partial Page Rendering, only specified components are rendered, similarly in Partial Processing only defined components are processed. Processing means executing Apply Request Values, Process Validations, Update Model and Invoke Application JSF lifecycle phases only on defined components.

Back to your problem, you should use process @form

Hope this could help you.

Mankeomorakort
  • 1,451
  • 1
  • 22
  • 36
  • How is using `@form` different from explicitly using the (relative) id of the form? And `@form` is the default: http://stackoverflow.com/questions/25339056/understanding-primefaces-process-update-and-jsf-fajax-execute-render-attributes – Kukeltje Feb 08 '17 at 16:27
  • @Kukeltje Both are not difference. In some case when you don't use form's id and don't care about it, you just add attribute (prependId="false") to your form and you just add attribute (process="@form") to your submit component such as p:commandButton ... etc – Mankeomorakort Feb 09 '17 at 02:32
  • if they are not different, yours will fail to. And it's best to *never* use prependId="false" http://stackoverflow.com/questions/7415230/uiform-with-prependid-false-breaks-fajax-render – Kukeltje Feb 09 '17 at 05:52
  • 1
    prependId="false" is useful if you want to write javascript or css as JSF will not prefix the form id to the id you've defined. – Chhea Vanrin Feb 10 '17 at 03:00
1

I also see you have some fields marked as required. If some required fields are not filled up, the validation fails and the action listener is not called.

But if there are no proper < h:messages> tags in your pages or templates, the validation errors are not displayed anywhere !!

Ensure you also have a proper < h:messages> or < p:messages> to show any possible validation errors.

We spend several hours with this issue until we figured it out ...

Maikel Nait
  • 251
  • 3
  • 18
  • It was a validation error that was not displayed. I saw it just before you answer. Thanks anyway! – rlopezo Feb 09 '17 at 16:30
0

Add process="@this" to the commandButton.

Also, study this guide from BalusC:

commandButton/commandLink/ajax action/listener method not invoked or input value not updated

Community
  • 1
  • 1
J Slick
  • 929
  • 11
  • 17