Question

A (Richfaces) popup with an own form provides a save button which must execute another form (contentForm) and do not forward if validation failures occurs.

However, saveHandler.forward() is always invoked... any ideas?

<a4j:commandButton 
    id="saveContentChanges" 
    value="Speichern" 
    action="#{cc.attrs.handler.save()}"
    type="submit"> 
    <a4j:ajax 
        execute=":contentForm" 
        render=":contentForm"
        oncomplete="if (#{!facesContext.validationFailed}) { saveHandler.forward() } else { #{rich:component('contentSaveHandlerPopup')}.hide() }"
        onerror="errorHandler.onError(event.description); #{rich:component('contentSaveHandlerPopup')}.hide();" />
</a4j:commandButton>

PS. This code is within a composite component. I do not get any errors on the JavaScript console.

Était-ce utile?

La solution

In HTML only single form can be submitted, so in your case only the data from the form where a4j:commanButton resides is submitted from client to server. execute attribute impacts only server side processing, it does not change how data is submitted. So adding to execute a different form makes it actually processed on server side, but since there are no submitted values it means there is nothing to validate.

Alternative solutions are:

  1. (preferred) Put popup with the button to the same form which needs to be submitted and validated.

  2. Put a a4j:jsFunction to contentForm and call it from popup, code would look like this:

.

<h:form id="contentForm">
  .. other fields to be submitted ..
  <a4j:jsFunction name="executeContentFormAction" execute="@form" render="@form"
        action="#{...}"
        oncomplete="if ..."/>
</h:form>

...

<a4j:commandButton 
    id="saveContentChanges" 
    value="Speichern"
    onclick="executeContentFormAction(); return false;">
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top