You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by laredotornado <la...@gmail.com> on 2010/03/15 15:57:55 UTC

Way to prevent further validations in the listener?

Hi,

I'm using MyFaces 1.1.5 with Tomahawk 1.1.7.  I have a phase listener and
was wondering if there is a way I can prevent validations from happening if
certain conditions occur.  For example, if I reach the branch with the
comment ...

	public void beforePhase(final PhaseEvent phaseEvent) {
		if (phaseEvent.getPhaseId() == PhaseId.PROCESS_VALIDATIONS) {
			if (errorsOccur(phaseEvent)) { 
				// Prevent other validations from happening. 
			}   // if
		} // if
	}

I would like to prevent the validations from taking place in this text field
...

                <h:inputText id="domeTourNumber_of_Adults"
value="#{domeTour.numAdults}"
                                            required="true"
                                            size="60"
                                            maxlength="60"
                                            styleClass="textFields
numAdultsField">
                <f:validator validatorId="TourNumberValidator" />              
               	<f:validator validatorId="TourTotalPeopleValidator" />
               	<f:validator validatorId="TourAdultChildRatioValidator" />
               </h:inputText>

Any insights you can provide are greatly appreciated, - Dave

-- 
View this message in context: http://old.nabble.com/Way-to-prevent-further-validations-in-the-listener--tp27905462p27905462.html
Sent from the MyFaces - Users mailing list archive at Nabble.com.


Re: Way to prevent further validations in the listener?

Posted by Mike Kienenberger <mk...@gmail.com>.
If you want to skip RENDER_RESPONSE too,

FacesContext.getCurrentInstance().responseComplete();

See http://wiki.apache.org/myfaces/Sending_Files for an example.


On Mon, Mar 15, 2010 at 3:09 PM, Jakob Korherr <ja...@gmail.com> wrote:
> This is exactly what FacesContext.renderResponse() does. It skips all phases
> except the last one - RENDER_RESPONSE.
>
> Regards,
> Jakob
>
> 2010/3/15 laredotornado <la...@gmail.com>
>
>>
>> Thanks, Jakob.  And here is the final follow-up.  How do I tell JSF to skip
>> the rest of the phases in my listener? - Dave
>>
>>
>>
>> Jakob Korherr wrote:
>> >
>> > Ok cool. The implications are that your action methods and your action
>> > listeners are not invoked in that request! Also, and I forgot that
>> before,
>> > your submitted values are not applied to your managed beans, because
>> > UPDATE_MODEL is also not invoked.
>> >
>> > But this is anyway the expected JSF behavior if a validation fails.
>> >
>> > Regards,
>> > Jakob
>> >
>> > 2010/3/15 laredotornado <la...@gmail.com>
>> >
>> >>
>> >> Skipping the entire validation phase would work for me here.  However,
>> >> what
>> >> are the implications of also skipping the INVOKE_APPLICATION phase?
>> >>
>> >> Thanks, - Dave
>> >>
>> >>
>> >>
>> >> Jakob Korherr wrote:
>> >> >
>> >> > Hi,
>> >> >
>> >> > Do you want to skip the entire validation phase or do just want to
>> >> disable
>> >> > some specific validators?
>> >> >
>> >> > In the first case you can set FacesContext.renderResponse(), however
>> >> also
>> >> > the INVOKE_APPLICATION phase will be skipped here.
>> >> > In the second case you could set a value in the FacesContext's
>> >> attribute
>> >> > Map
>> >> > and consider this value in your validators to either skip or do the
>> >> > validation.
>> >> >
>> >> > I think these are the best solutions to your problem in MyFaces 1.1.
>> In
>> >> > MyFaces 2.0 the attribute "disabled" was added to <f:converter>. This
>> >> > would
>> >> > perfectly fit you in this scenario, but unfortunately this is not
>> >> > available
>> >> > in 1.1.
>> >> >
>> >> > Hope this helps!
>> >> >
>> >> > Regards,
>> >> > Jakob
>> >> >
>> >> > 2010/3/15 laredotornado <la...@gmail.com>
>> >> >
>> >> >>
>> >> >> Hi,
>> >> >>
>> >> >> I'm using MyFaces 1.1.5 with Tomahawk 1.1.7.  I have a phase listener
>> >> and
>> >> >> was wondering if there is a way I can prevent validations from
>> >> happening
>> >> >> if
>> >> >> certain conditions occur.  For example, if I reach the branch with
>> the
>> >> >> comment ...
>> >> >>
>> >> >>        public void beforePhase(final PhaseEvent phaseEvent) {
>> >> >>                if (phaseEvent.getPhaseId() ==
>> >> >> PhaseId.PROCESS_VALIDATIONS)
>> >> >> {
>> >> >>                        if (errorsOccur(phaseEvent)) {
>> >> >>                                // Prevent other validations from
>> >> >> happening.
>> >> >>                        }   // if
>> >> >>                } // if
>> >> >>        }
>> >> >>
>> >> >> I would like to prevent the validations from taking place in this
>> text
>> >> >> field
>> >> >> ...
>> >> >>
>> >> >>                <h:inputText id="domeTourNumber_of_Adults"
>> >> >> value="#{domeTour.numAdults}"
>> >> >>                                            required="true"
>> >> >>                                            size="60"
>> >> >>                                            maxlength="60"
>> >> >>                                            styleClass="textFields
>> >> >> numAdultsField">
>> >> >>                <f:validator validatorId="TourNumberValidator" />
>> >> >>                <f:validator validatorId="TourTotalPeopleValidator" />
>> >> >>                <f:validator
>> validatorId="TourAdultChildRatioValidator"
>> >> />
>> >> >>               </h:inputText>
>> >> >>
>> >> >> Any insights you can provide are greatly appreciated, - Dave
>> >> >>
>> >> >> --
>> >> >> View this message in context:
>> >> >>
>> >>
>> http://old.nabble.com/Way-to-prevent-further-validations-in-the-listener--tp27905462p27905462.html
>> >> >> Sent from the MyFaces - Users mailing list archive at Nabble.com.
>> >> >>
>> >> >>
>> >> >
>> >> >
>> >>
>> >> --
>> >> View this message in context:
>> >>
>> http://old.nabble.com/Way-to-prevent-further-validations-in-the-listener--tp27905462p27907138.html
>> >> Sent from the MyFaces - Users mailing list archive at Nabble.com.
>> >>
>> >>
>> >
>> >
>>
>> --
>> View this message in context:
>> http://old.nabble.com/Way-to-prevent-further-validations-in-the-listener--tp27905462p27909639.html
>> Sent from the MyFaces - Users mailing list archive at Nabble.com.
>>
>>
>

Re: Way to prevent further validations in the listener?

Posted by Jakob Korherr <ja...@gmail.com>.
This is exactly what FacesContext.renderResponse() does. It skips all phases
except the last one - RENDER_RESPONSE.

Regards,
Jakob

2010/3/15 laredotornado <la...@gmail.com>

>
> Thanks, Jakob.  And here is the final follow-up.  How do I tell JSF to skip
> the rest of the phases in my listener? - Dave
>
>
>
> Jakob Korherr wrote:
> >
> > Ok cool. The implications are that your action methods and your action
> > listeners are not invoked in that request! Also, and I forgot that
> before,
> > your submitted values are not applied to your managed beans, because
> > UPDATE_MODEL is also not invoked.
> >
> > But this is anyway the expected JSF behavior if a validation fails.
> >
> > Regards,
> > Jakob
> >
> > 2010/3/15 laredotornado <la...@gmail.com>
> >
> >>
> >> Skipping the entire validation phase would work for me here.  However,
> >> what
> >> are the implications of also skipping the INVOKE_APPLICATION phase?
> >>
> >> Thanks, - Dave
> >>
> >>
> >>
> >> Jakob Korherr wrote:
> >> >
> >> > Hi,
> >> >
> >> > Do you want to skip the entire validation phase or do just want to
> >> disable
> >> > some specific validators?
> >> >
> >> > In the first case you can set FacesContext.renderResponse(), however
> >> also
> >> > the INVOKE_APPLICATION phase will be skipped here.
> >> > In the second case you could set a value in the FacesContext's
> >> attribute
> >> > Map
> >> > and consider this value in your validators to either skip or do the
> >> > validation.
> >> >
> >> > I think these are the best solutions to your problem in MyFaces 1.1.
> In
> >> > MyFaces 2.0 the attribute "disabled" was added to <f:converter>. This
> >> > would
> >> > perfectly fit you in this scenario, but unfortunately this is not
> >> > available
> >> > in 1.1.
> >> >
> >> > Hope this helps!
> >> >
> >> > Regards,
> >> > Jakob
> >> >
> >> > 2010/3/15 laredotornado <la...@gmail.com>
> >> >
> >> >>
> >> >> Hi,
> >> >>
> >> >> I'm using MyFaces 1.1.5 with Tomahawk 1.1.7.  I have a phase listener
> >> and
> >> >> was wondering if there is a way I can prevent validations from
> >> happening
> >> >> if
> >> >> certain conditions occur.  For example, if I reach the branch with
> the
> >> >> comment ...
> >> >>
> >> >>        public void beforePhase(final PhaseEvent phaseEvent) {
> >> >>                if (phaseEvent.getPhaseId() ==
> >> >> PhaseId.PROCESS_VALIDATIONS)
> >> >> {
> >> >>                        if (errorsOccur(phaseEvent)) {
> >> >>                                // Prevent other validations from
> >> >> happening.
> >> >>                        }   // if
> >> >>                } // if
> >> >>        }
> >> >>
> >> >> I would like to prevent the validations from taking place in this
> text
> >> >> field
> >> >> ...
> >> >>
> >> >>                <h:inputText id="domeTourNumber_of_Adults"
> >> >> value="#{domeTour.numAdults}"
> >> >>                                            required="true"
> >> >>                                            size="60"
> >> >>                                            maxlength="60"
> >> >>                                            styleClass="textFields
> >> >> numAdultsField">
> >> >>                <f:validator validatorId="TourNumberValidator" />
> >> >>                <f:validator validatorId="TourTotalPeopleValidator" />
> >> >>                <f:validator
> validatorId="TourAdultChildRatioValidator"
> >> />
> >> >>               </h:inputText>
> >> >>
> >> >> Any insights you can provide are greatly appreciated, - Dave
> >> >>
> >> >> --
> >> >> View this message in context:
> >> >>
> >>
> http://old.nabble.com/Way-to-prevent-further-validations-in-the-listener--tp27905462p27905462.html
> >> >> Sent from the MyFaces - Users mailing list archive at Nabble.com.
> >> >>
> >> >>
> >> >
> >> >
> >>
> >> --
> >> View this message in context:
> >>
> http://old.nabble.com/Way-to-prevent-further-validations-in-the-listener--tp27905462p27907138.html
> >> Sent from the MyFaces - Users mailing list archive at Nabble.com.
> >>
> >>
> >
> >
>
> --
> View this message in context:
> http://old.nabble.com/Way-to-prevent-further-validations-in-the-listener--tp27905462p27909639.html
> Sent from the MyFaces - Users mailing list archive at Nabble.com.
>
>

Re: Way to prevent further validations in the listener?

Posted by laredotornado <la...@gmail.com>.
Thanks, Jakob.  And here is the final follow-up.  How do I tell JSF to skip
the rest of the phases in my listener? - Dave



Jakob Korherr wrote:
> 
> Ok cool. The implications are that your action methods and your action
> listeners are not invoked in that request! Also, and I forgot that before,
> your submitted values are not applied to your managed beans, because
> UPDATE_MODEL is also not invoked.
> 
> But this is anyway the expected JSF behavior if a validation fails.
> 
> Regards,
> Jakob
> 
> 2010/3/15 laredotornado <la...@gmail.com>
> 
>>
>> Skipping the entire validation phase would work for me here.  However,
>> what
>> are the implications of also skipping the INVOKE_APPLICATION phase?
>>
>> Thanks, - Dave
>>
>>
>>
>> Jakob Korherr wrote:
>> >
>> > Hi,
>> >
>> > Do you want to skip the entire validation phase or do just want to
>> disable
>> > some specific validators?
>> >
>> > In the first case you can set FacesContext.renderResponse(), however
>> also
>> > the INVOKE_APPLICATION phase will be skipped here.
>> > In the second case you could set a value in the FacesContext's
>> attribute
>> > Map
>> > and consider this value in your validators to either skip or do the
>> > validation.
>> >
>> > I think these are the best solutions to your problem in MyFaces 1.1. In
>> > MyFaces 2.0 the attribute "disabled" was added to <f:converter>. This
>> > would
>> > perfectly fit you in this scenario, but unfortunately this is not
>> > available
>> > in 1.1.
>> >
>> > Hope this helps!
>> >
>> > Regards,
>> > Jakob
>> >
>> > 2010/3/15 laredotornado <la...@gmail.com>
>> >
>> >>
>> >> Hi,
>> >>
>> >> I'm using MyFaces 1.1.5 with Tomahawk 1.1.7.  I have a phase listener
>> and
>> >> was wondering if there is a way I can prevent validations from
>> happening
>> >> if
>> >> certain conditions occur.  For example, if I reach the branch with the
>> >> comment ...
>> >>
>> >>        public void beforePhase(final PhaseEvent phaseEvent) {
>> >>                if (phaseEvent.getPhaseId() ==
>> >> PhaseId.PROCESS_VALIDATIONS)
>> >> {
>> >>                        if (errorsOccur(phaseEvent)) {
>> >>                                // Prevent other validations from
>> >> happening.
>> >>                        }   // if
>> >>                } // if
>> >>        }
>> >>
>> >> I would like to prevent the validations from taking place in this text
>> >> field
>> >> ...
>> >>
>> >>                <h:inputText id="domeTourNumber_of_Adults"
>> >> value="#{domeTour.numAdults}"
>> >>                                            required="true"
>> >>                                            size="60"
>> >>                                            maxlength="60"
>> >>                                            styleClass="textFields
>> >> numAdultsField">
>> >>                <f:validator validatorId="TourNumberValidator" />
>> >>                <f:validator validatorId="TourTotalPeopleValidator" />
>> >>                <f:validator validatorId="TourAdultChildRatioValidator"
>> />
>> >>               </h:inputText>
>> >>
>> >> Any insights you can provide are greatly appreciated, - Dave
>> >>
>> >> --
>> >> View this message in context:
>> >>
>> http://old.nabble.com/Way-to-prevent-further-validations-in-the-listener--tp27905462p27905462.html
>> >> Sent from the MyFaces - Users mailing list archive at Nabble.com.
>> >>
>> >>
>> >
>> >
>>
>> --
>> View this message in context:
>> http://old.nabble.com/Way-to-prevent-further-validations-in-the-listener--tp27905462p27907138.html
>> Sent from the MyFaces - Users mailing list archive at Nabble.com.
>>
>>
> 
> 

-- 
View this message in context: http://old.nabble.com/Way-to-prevent-further-validations-in-the-listener--tp27905462p27909639.html
Sent from the MyFaces - Users mailing list archive at Nabble.com.


Re: Way to prevent further validations in the listener?

Posted by Jakob Korherr <ja...@gmail.com>.
Ok cool. The implications are that your action methods and your action
listeners are not invoked in that request! Also, and I forgot that before,
your submitted values are not applied to your managed beans, because
UPDATE_MODEL is also not invoked.

But this is anyway the expected JSF behavior if a validation fails.

Regards,
Jakob

2010/3/15 laredotornado <la...@gmail.com>

>
> Skipping the entire validation phase would work for me here.  However, what
> are the implications of also skipping the INVOKE_APPLICATION phase?
>
> Thanks, - Dave
>
>
>
> Jakob Korherr wrote:
> >
> > Hi,
> >
> > Do you want to skip the entire validation phase or do just want to
> disable
> > some specific validators?
> >
> > In the first case you can set FacesContext.renderResponse(), however also
> > the INVOKE_APPLICATION phase will be skipped here.
> > In the second case you could set a value in the FacesContext's attribute
> > Map
> > and consider this value in your validators to either skip or do the
> > validation.
> >
> > I think these are the best solutions to your problem in MyFaces 1.1. In
> > MyFaces 2.0 the attribute "disabled" was added to <f:converter>. This
> > would
> > perfectly fit you in this scenario, but unfortunately this is not
> > available
> > in 1.1.
> >
> > Hope this helps!
> >
> > Regards,
> > Jakob
> >
> > 2010/3/15 laredotornado <la...@gmail.com>
> >
> >>
> >> Hi,
> >>
> >> I'm using MyFaces 1.1.5 with Tomahawk 1.1.7.  I have a phase listener
> and
> >> was wondering if there is a way I can prevent validations from happening
> >> if
> >> certain conditions occur.  For example, if I reach the branch with the
> >> comment ...
> >>
> >>        public void beforePhase(final PhaseEvent phaseEvent) {
> >>                if (phaseEvent.getPhaseId() ==
> >> PhaseId.PROCESS_VALIDATIONS)
> >> {
> >>                        if (errorsOccur(phaseEvent)) {
> >>                                // Prevent other validations from
> >> happening.
> >>                        }   // if
> >>                } // if
> >>        }
> >>
> >> I would like to prevent the validations from taking place in this text
> >> field
> >> ...
> >>
> >>                <h:inputText id="domeTourNumber_of_Adults"
> >> value="#{domeTour.numAdults}"
> >>                                            required="true"
> >>                                            size="60"
> >>                                            maxlength="60"
> >>                                            styleClass="textFields
> >> numAdultsField">
> >>                <f:validator validatorId="TourNumberValidator" />
> >>                <f:validator validatorId="TourTotalPeopleValidator" />
> >>                <f:validator validatorId="TourAdultChildRatioValidator"
> />
> >>               </h:inputText>
> >>
> >> Any insights you can provide are greatly appreciated, - Dave
> >>
> >> --
> >> View this message in context:
> >>
> http://old.nabble.com/Way-to-prevent-further-validations-in-the-listener--tp27905462p27905462.html
> >> Sent from the MyFaces - Users mailing list archive at Nabble.com.
> >>
> >>
> >
> >
>
> --
> View this message in context:
> http://old.nabble.com/Way-to-prevent-further-validations-in-the-listener--tp27905462p27907138.html
> Sent from the MyFaces - Users mailing list archive at Nabble.com.
>
>

Re: Way to prevent further validations in the listener?

Posted by laredotornado <la...@gmail.com>.
Skipping the entire validation phase would work for me here.  However, what
are the implications of also skipping the INVOKE_APPLICATION phase?

Thanks, - Dave



Jakob Korherr wrote:
> 
> Hi,
> 
> Do you want to skip the entire validation phase or do just want to disable
> some specific validators?
> 
> In the first case you can set FacesContext.renderResponse(), however also
> the INVOKE_APPLICATION phase will be skipped here.
> In the second case you could set a value in the FacesContext's attribute
> Map
> and consider this value in your validators to either skip or do the
> validation.
> 
> I think these are the best solutions to your problem in MyFaces 1.1. In
> MyFaces 2.0 the attribute "disabled" was added to <f:converter>. This
> would
> perfectly fit you in this scenario, but unfortunately this is not
> available
> in 1.1.
> 
> Hope this helps!
> 
> Regards,
> Jakob
> 
> 2010/3/15 laredotornado <la...@gmail.com>
> 
>>
>> Hi,
>>
>> I'm using MyFaces 1.1.5 with Tomahawk 1.1.7.  I have a phase listener and
>> was wondering if there is a way I can prevent validations from happening
>> if
>> certain conditions occur.  For example, if I reach the branch with the
>> comment ...
>>
>>        public void beforePhase(final PhaseEvent phaseEvent) {
>>                if (phaseEvent.getPhaseId() ==
>> PhaseId.PROCESS_VALIDATIONS)
>> {
>>                        if (errorsOccur(phaseEvent)) {
>>                                // Prevent other validations from
>> happening.
>>                        }   // if
>>                } // if
>>        }
>>
>> I would like to prevent the validations from taking place in this text
>> field
>> ...
>>
>>                <h:inputText id="domeTourNumber_of_Adults"
>> value="#{domeTour.numAdults}"
>>                                            required="true"
>>                                            size="60"
>>                                            maxlength="60"
>>                                            styleClass="textFields
>> numAdultsField">
>>                <f:validator validatorId="TourNumberValidator" />
>>                <f:validator validatorId="TourTotalPeopleValidator" />
>>                <f:validator validatorId="TourAdultChildRatioValidator" />
>>               </h:inputText>
>>
>> Any insights you can provide are greatly appreciated, - Dave
>>
>> --
>> View this message in context:
>> http://old.nabble.com/Way-to-prevent-further-validations-in-the-listener--tp27905462p27905462.html
>> Sent from the MyFaces - Users mailing list archive at Nabble.com.
>>
>>
> 
> 

-- 
View this message in context: http://old.nabble.com/Way-to-prevent-further-validations-in-the-listener--tp27905462p27907138.html
Sent from the MyFaces - Users mailing list archive at Nabble.com.


Re: Way to prevent further validations in the listener?

Posted by Jakob Korherr <ja...@gmail.com>.
Hi,

Do you want to skip the entire validation phase or do just want to disable
some specific validators?

In the first case you can set FacesContext.renderResponse(), however also
the INVOKE_APPLICATION phase will be skipped here.
In the second case you could set a value in the FacesContext's attribute Map
and consider this value in your validators to either skip or do the
validation.

I think these are the best solutions to your problem in MyFaces 1.1. In
MyFaces 2.0 the attribute "disabled" was added to <f:converter>. This would
perfectly fit you in this scenario, but unfortunately this is not available
in 1.1.

Hope this helps!

Regards,
Jakob

2010/3/15 laredotornado <la...@gmail.com>

>
> Hi,
>
> I'm using MyFaces 1.1.5 with Tomahawk 1.1.7.  I have a phase listener and
> was wondering if there is a way I can prevent validations from happening if
> certain conditions occur.  For example, if I reach the branch with the
> comment ...
>
>        public void beforePhase(final PhaseEvent phaseEvent) {
>                if (phaseEvent.getPhaseId() == PhaseId.PROCESS_VALIDATIONS)
> {
>                        if (errorsOccur(phaseEvent)) {
>                                // Prevent other validations from happening.
>                        }   // if
>                } // if
>        }
>
> I would like to prevent the validations from taking place in this text
> field
> ...
>
>                <h:inputText id="domeTourNumber_of_Adults"
> value="#{domeTour.numAdults}"
>                                            required="true"
>                                            size="60"
>                                            maxlength="60"
>                                            styleClass="textFields
> numAdultsField">
>                <f:validator validatorId="TourNumberValidator" />
>                <f:validator validatorId="TourTotalPeopleValidator" />
>                <f:validator validatorId="TourAdultChildRatioValidator" />
>               </h:inputText>
>
> Any insights you can provide are greatly appreciated, - Dave
>
> --
> View this message in context:
> http://old.nabble.com/Way-to-prevent-further-validations-in-the-listener--tp27905462p27905462.html
> Sent from the MyFaces - Users mailing list archive at Nabble.com.
>
>