8 Replies Latest reply on Jul 29, 2009 7:20 PM by Nick Belaevski

    general problems with validation errors

    John Who Newbie

      Hi everybody,

      I'm having a general problem during my validation of a page.
      For example there is a "search area" with a command button (this button calls a search action (of course)) and another area with all the detail informations on my side.
      So the user search s.th. and klick on the detail link.
      In this detail area there a some input fields to customice certain values. One of the input fields has a custom validator - f.ex. f:validateLenght (min=0, max=1). If the user enters a number >1 there is a error shown. So far so good.
      BUT: Unless the user change the value of this input field there is no chance to call any (!) other action on this side. F.ex. the user noticed his error but also recognise that he selected the false "detail area" and want to call another one (or just call the search method with new criterias) - no way until he changes the value of the input field.

      So is there a possibility to change this behaviour?

      Thanks in advance!

        • 1. Re: general problems with validation errors
          Ilya Shaikovsky Master

          learn about a4j:region component and ajaxSingle property of ajax components for processing limitations.

          • 2. Re: general problems with validation errors
            John Who Newbie

             

            "ilya_shaikovsky" wrote:
            learn about a4j:region component and ajaxSingle property of ajax components for processing limitations.


            As far as I understood the a4j:region tag there is no usage in this content. I don't validate the input field by an ajax request but by a normal f:validate tag?!

            • 3. Re: general problems with validation errors
              Alexander Smirnov Master

              To bypass validation and update for a such links you can use 'immediate' attribute for these command components.

              • 4. Re: general problems with validation errors
                Radhesh Radhakrishnan Newbie

                "immediate" maynot be the right solution:

                Try this:
                Whener you want to disable Validations, add an actionParam to the eventSource with a "disable" flag. Add a PhaseListener, and in the beforePhase of processValidations phase, check for the existence of this flag. If present, iterate through all the children and unplug all the defined validators; but, remember to back them up. Now, let the processValidations Phase complete without any validators. In the afterPhase, you may add all the validators back to EditableValueHolders.

                Hope this helps!

                • 5. Re: general problems with validation errors
                  John Who Newbie

                  Thanks for this info.
                  But I'm having a few problems to contain my PhaseListener...

                  faces-config:

                  <faces-config>
                  <application>...</application>
                  <lifecycle>
                   <phase-listener>my.package.PhaseListener</phase-listener>
                  </lifecycle>
                  </faces-config>
                  


                  and my phaselistener:
                  package my.package;
                  
                  import javax.faces.context.FacesContext;
                  import javax.faces.event.PhaseEvent;
                  import javax.faces.event.PhaseId;
                  
                  public class PhaseListener implements javax.faces.event.PhaseListener {
                  
                   public void afterPhase( PhaseEvent event ) {
                   System.out.println( "AFTER - " + event.getPhaseId() );
                   FacesContext.getCurrentInstance().getExternalContext().log( "AFTER - "+ event.getPhaseId() );
                   }
                  
                   public void beforePhase( PhaseEvent event ) {
                   System.out.println( "BEFORE - " + event.getPhaseId() );
                   if( event.getPhaseId().equals( PhaseId.PROCESS_VALIDATIONS ) ){
                   System.out.println( "Validierung beginnt!" );
                   }
                   FacesContext.getCurrentInstance().getExternalContext().log( "BEFORE - "+ event.getPhaseId() );
                   }
                  
                   public PhaseId getPhaseId() {
                   return null;
                   }
                  
                  }
                  


                  I restartet the server but there is no output. Am I missing some configurations?

                  And just another question: What did you mean by "adding some actionParam to the eventSource with a 'disable' flag? I'm having a commandButton and as far as I know I cant't use the f:param-Tag for it? And how do I get the information from the bean to the PhaseListener? Do I have add the information to my actionEvent in the manged bean and how can I access this information in my phaselistener??

                  Sorry, I'm a little bit confused ;(


                  • 6. Re: general problems with validation errors
                    Nick Belaevski Master

                    Try:

                    public PhaseId getPhaseId() {
                     return PhaseId.ANY_PHASE;
                     }


                    • 7. Re: general problems with validation errors
                      John Who Newbie

                      @nbelaevski: Thanks - that helps!

                      "radhesh" wrote:

                      Whener you want to disable Validations, add an actionParam to the eventSource with a "disable" flag. Add a PhaseListener, and in the beforePhase of processValidations phase, check for the existence of this flag. If present, iterate through all the children and unplug all the defined validators; but, remember to back them up. Now, let the processValidations Phase complete without any validators. In the afterPhase, you may add all the validators back to EditableValueHolders.


                      Now I'm still having the problem that I can react on the VALIDATION_PROCESS but I don't know how...

                      In my example there is an input field with an invalid value. If I click one of several links which don't validate this input field I don't know what to do.

                      F.ex. I added to a link an a4j:actionparam which I can check in the BEFORE_VALIDATION_PROCESS but even if I know I don't want to validate for this request how can I achieve it? How do I iterate through all the children (of what?) and unplug all the defined validators?

                      • 8. Re: general problems with validation errors
                        Nick Belaevski Master

                        I'd suggest to let component tree live its own life and think about another solution, such as:

                        1. Usage of "immediate" attribute
                        2. Emulate behavior of a4j:region using "rendered" attribute. The idea behind this is the fact that non-rendered components are not processed (together with all their kids). So, you can write something like rendered="#{bean.skipThis}", where value of "bean.skipThis" depends on the current lifecycle phase (this is necessary for 2-4th phases only - components disappearing from the page won't suit our needs) and request parameter. If you go this way, think thoroughly about securing actions from wrong data.
                        3. Some exotic way, like validating model state by action method itself - no validators in the view, everything in Java code.