JSF: update conditionally in case of success or failure of validation

In my JSF application, I am trying to set some conditions in my command line update attribute so that if validation fails / success, I can manage updated components.

Regarding PrimeFaces: conditional update during validation , I tried using

<p:commandLink process="@form" listener="#{foo}" 
  update="somethingElse" oncomplete="if (!args.validationFailed) $("#link").click();">
<p:commandLink style="display:none" id="link"
  update="something">

But I don’t know why this approach doesn’t work for me .. the click event of this component doesn’t work for me .. I tried to fulfill the accepted answer on the same question, but I couldn’t understand how those solve the goal ...

My goal is to conditionally update depending on the result of the success or failure of the test ... Support I have 3 components XY Z .. I'm trying to do something like this.

<p:commandLink process="@form" listener="#{foo}" 
      update="if(Validation fail)updateSomething[e.g X and Y] **else** update somethingelse[e.g X  Y and Z]">

, , X Y , , X Y Z.

, . .

+5
2

, EL, , . , " ' JavaScript. \" '.

<p:commandLink process="@form" listener="#{foo}" update="somethingElse" 
    oncomplete="if (!args.validationFailed) $('#link').click();">

, <p:commandLink id="link"> "link" . <h:form>. - HTML-, JSF. webbrowser, rightclick View Source, . id="formId:link". jQuery.

<p:commandLink process="@form" listener="#{foo}" update="somethingElse" 
    oncomplete="if (!args.validationFailed) $('#formId\\:link').click();">

. :


, listener="#{foo}".

if (!facesContext.isValidationFailed()) {
    RequestContext.getCurrentInstance().update("somethingElse");
}
+11

, , args "validationFailed", .

 import org.primefaces.context.RequestContext;

 RequestContext requestContext = RequestContext.getCurrentInstance();
 requestContext.addCallbackParam("validationError", true);
 JSFUtils.displayErrorMessage("My message is here!");

& xhtml :

 <p:commandLink ajax="true" action="#{myController.myMethod}"
 oncomplete="if(args.validationError) alert('Error!');"/>
0

All Articles