You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Bjørn T Johansen <bt...@havleik.no> on 2006/10/19 15:09:08 UTC

Problem with required=true?

I have some edit boxes that has the attribute required set to true but I also have a selectOneMenu which does
a submit when value changes... What is the best way to skip the required test when submitting using the
selectOneMenu onChange event?


Regards,

BTJ

-- 
-----------------------------------------------------------------------------------------------
Bjørn T Johansen

btj@havleik.no
-----------------------------------------------------------------------------------------------
Someone wrote:
"I understand that if you play a Windows CD backwards you hear strange Satanic messages"
To which someone replied:
"It's even worse than that; play it forwards and it installs Windows"
-----------------------------------------------------------------------------------------------

Re: Problem with required=true?

Posted by Bjørn T Johansen <bt...@havleik.no>.
Aaahhh... Ok... Thx... :)

BTJ

On Thu, 19 Oct 2006 15:57:31 -0400
Jeff Bischoff <jb...@klkurz.com> wrote:

> Bjorn,
> 
> That may have been because you were setting the values in the 
> valueChangeListener of an "immediate" component, and then the values of 
> the other components were overwritten in the "Update Model Values" 
> phase. Your immediate action listener is running in between the "Apply 
> Request Values" phase and the "Process Validations" phase.
> 
> Perhaps I should have explained my little skipValidation() method a bit 
> better. It doesn't just skip the "Process Validations" phase, it skips 
> right to "Render Response" phase. So you also skip the "Update Model 
> Values" and "Invoke Application" phases. This means that the changes you 
> make in your valueChangeListener to the other model values will "stick," 
> because the "Update Model Values" phase will never be called to 
> overwrite those changes.
> 
> So if you make careful use of these JSF Utility functions, you can 
> achieve all sorts of desired behaviours. I admit, you are sort of 
> "working-around" the framework... perhaps a future version of JSF will 
> introduce a more flexible model for validations. :)
> 
> Regards,
> 
> Jeff Bischoff
> Kenneth L Kurz & Associates, Inc.
> 
> Bjørn T Johansen wrote:
> > It may be that I am misunderstanding but I remember I had problem setting values in my valueChangeListener method a while ago
> > because those values were overwritten after the valueChangeListener had been invoked...
> > 
> > BTJ
> > 
> > On Thu, 19 Oct 2006 15:13:00 -0400
> > Jeff Bischoff <jb...@klkurz.com> wrote:
> > 
> >> Sure it will.
> >>
> >> In your valueChangeListener:
> >> 1) Update your model as needed (i.e. explicitly call any setters for 
> >> properties you need to change the value of).
> >>
> >> 2) Call refresh() from the wiki to update input components with the new 
> >> values. Do this only if needed, as it will replace anything the user has 
> >> entered with the model values. It's mainly useful on events that load 
> >> new data.
> >>
> >> 3) Call skipValidation() to bypass the validations, including "required"
> >>
> >>
> >> What is it that you are trying to do where this pattern isn't sufficient?
> >>
> >> Bjørn T Johansen wrote:
> >>> Well, I need to update my form with new data as a result of that value change, so as far as I can tell, using this
> >>> skipValidation metehod won't help me?
> >>>
> >>>
> >>> BTJ
> >>>
> >>> On Thu, 19 Oct 2006 09:31:17 -0400
> >>> Jeff Bischoff <jb...@klkurz.com> wrote:
> >>>
> >>>> Bjorn,
> >>>>
> >>>> Put a method like this in some utility class in your web tier java code:
> >>>>
> >>>> public static void skipValidation() {
> >>>> 	FacesContext context = FacesContext.getCurrentInstance();
> >>>> 	context.renderResponse();
> >>>> }
> >>>>
> >>>> Then you can call skipValidation() in your valueChangeListener method.
> >>>>
> >>>> You may notice that input components are not updated with model values 
> >>>> that may have changed as a result of your immediate methods. If you, 
> >>>> this article [1] may be of use to you as well.
> >>>>
> >>>> [1] http://wiki.apache.org/myfaces/ClearInputComponents
> >>>>
> >>>> Regards,
> >>>>
> >>>> Jeff Bischoff
> >>>> Kenneth L Kurz & Associates, Inc.
> >>>>
> >>>> Bjørn T Johansen wrote:
> >>>>> I have some edit boxes that has the attribute required set to true but I also have a selectOneMenu which does
> >>>>> a submit when value changes... What is the best way to skip the required test when submitting using the
> >>>>> selectOneMenu onChange event?
> >>>>>
> >>>>>
> >>>>> Regards,
> >>>>>
> >>>>> BTJ
> >>>>>
> >>>
> >>>
> >>
> > 
> > 
> > 
> 
> 

Re: Problem with required=true?

Posted by Jeff Bischoff <jb...@klkurz.com>.
Bjorn,

That may have been because you were setting the values in the 
valueChangeListener of an "immediate" component, and then the values of 
the other components were overwritten in the "Update Model Values" 
phase. Your immediate action listener is running in between the "Apply 
Request Values" phase and the "Process Validations" phase.

Perhaps I should have explained my little skipValidation() method a bit 
better. It doesn't just skip the "Process Validations" phase, it skips 
right to "Render Response" phase. So you also skip the "Update Model 
Values" and "Invoke Application" phases. This means that the changes you 
make in your valueChangeListener to the other model values will "stick," 
because the "Update Model Values" phase will never be called to 
overwrite those changes.

So if you make careful use of these JSF Utility functions, you can 
achieve all sorts of desired behaviours. I admit, you are sort of 
"working-around" the framework... perhaps a future version of JSF will 
introduce a more flexible model for validations. :)

Regards,

Jeff Bischoff
Kenneth L Kurz & Associates, Inc.

Bjørn T Johansen wrote:
> It may be that I am misunderstanding but I remember I had problem setting values in my valueChangeListener method a while ago
> because those values were overwritten after the valueChangeListener had been invoked...
> 
> BTJ
> 
> On Thu, 19 Oct 2006 15:13:00 -0400
> Jeff Bischoff <jb...@klkurz.com> wrote:
> 
>> Sure it will.
>>
>> In your valueChangeListener:
>> 1) Update your model as needed (i.e. explicitly call any setters for 
>> properties you need to change the value of).
>>
>> 2) Call refresh() from the wiki to update input components with the new 
>> values. Do this only if needed, as it will replace anything the user has 
>> entered with the model values. It's mainly useful on events that load 
>> new data.
>>
>> 3) Call skipValidation() to bypass the validations, including "required"
>>
>>
>> What is it that you are trying to do where this pattern isn't sufficient?
>>
>> Bjørn T Johansen wrote:
>>> Well, I need to update my form with new data as a result of that value change, so as far as I can tell, using this
>>> skipValidation metehod won't help me?
>>>
>>>
>>> BTJ
>>>
>>> On Thu, 19 Oct 2006 09:31:17 -0400
>>> Jeff Bischoff <jb...@klkurz.com> wrote:
>>>
>>>> Bjorn,
>>>>
>>>> Put a method like this in some utility class in your web tier java code:
>>>>
>>>> public static void skipValidation() {
>>>> 	FacesContext context = FacesContext.getCurrentInstance();
>>>> 	context.renderResponse();
>>>> }
>>>>
>>>> Then you can call skipValidation() in your valueChangeListener method.
>>>>
>>>> You may notice that input components are not updated with model values 
>>>> that may have changed as a result of your immediate methods. If you, 
>>>> this article [1] may be of use to you as well.
>>>>
>>>> [1] http://wiki.apache.org/myfaces/ClearInputComponents
>>>>
>>>> Regards,
>>>>
>>>> Jeff Bischoff
>>>> Kenneth L Kurz & Associates, Inc.
>>>>
>>>> Bjørn T Johansen wrote:
>>>>> I have some edit boxes that has the attribute required set to true but I also have a selectOneMenu which does
>>>>> a submit when value changes... What is the best way to skip the required test when submitting using the
>>>>> selectOneMenu onChange event?
>>>>>
>>>>>
>>>>> Regards,
>>>>>
>>>>> BTJ
>>>>>
>>>
>>>
>>
> 
> 
> 



Re: Problem with required=true?

Posted by Bjørn T Johansen <bt...@havleik.no>.
It may be that I am misunderstanding but I remember I had problem setting values in my valueChangeListener method a while ago
because those values were overwritten after the valueChangeListener had been invoked...

BTJ

On Thu, 19 Oct 2006 15:13:00 -0400
Jeff Bischoff <jb...@klkurz.com> wrote:

> Sure it will.
> 
> In your valueChangeListener:
> 1) Update your model as needed (i.e. explicitly call any setters for 
> properties you need to change the value of).
> 
> 2) Call refresh() from the wiki to update input components with the new 
> values. Do this only if needed, as it will replace anything the user has 
> entered with the model values. It's mainly useful on events that load 
> new data.
> 
> 3) Call skipValidation() to bypass the validations, including "required"
> 
> 
> What is it that you are trying to do where this pattern isn't sufficient?
> 
> Bjørn T Johansen wrote:
> > Well, I need to update my form with new data as a result of that value change, so as far as I can tell, using this
> > skipValidation metehod won't help me?
> > 
> > 
> > BTJ
> > 
> > On Thu, 19 Oct 2006 09:31:17 -0400
> > Jeff Bischoff <jb...@klkurz.com> wrote:
> > 
> >> Bjorn,
> >>
> >> Put a method like this in some utility class in your web tier java code:
> >>
> >> public static void skipValidation() {
> >> 	FacesContext context = FacesContext.getCurrentInstance();
> >> 	context.renderResponse();
> >> }
> >>
> >> Then you can call skipValidation() in your valueChangeListener method.
> >>
> >> You may notice that input components are not updated with model values 
> >> that may have changed as a result of your immediate methods. If you, 
> >> this article [1] may be of use to you as well.
> >>
> >> [1] http://wiki.apache.org/myfaces/ClearInputComponents
> >>
> >> Regards,
> >>
> >> Jeff Bischoff
> >> Kenneth L Kurz & Associates, Inc.
> >>
> >> Bjørn T Johansen wrote:
> >>> I have some edit boxes that has the attribute required set to true but I also have a selectOneMenu which does
> >>> a submit when value changes... What is the best way to skip the required test when submitting using the
> >>> selectOneMenu onChange event?
> >>>
> >>>
> >>> Regards,
> >>>
> >>> BTJ
> >>>
> >>
> > 
> > 
> > 
> 
> 

Re: Problem with required=true?

Posted by Jeff Bischoff <jb...@klkurz.com>.
Sure it will.

In your valueChangeListener:
1) Update your model as needed (i.e. explicitly call any setters for 
properties you need to change the value of).

2) Call refresh() from the wiki to update input components with the new 
values. Do this only if needed, as it will replace anything the user has 
entered with the model values. It's mainly useful on events that load 
new data.

3) Call skipValidation() to bypass the validations, including "required"


What is it that you are trying to do where this pattern isn't sufficient?

Bjørn T Johansen wrote:
> Well, I need to update my form with new data as a result of that value change, so as far as I can tell, using this skipValidation
> metehod won't help me?
> 
> 
> BTJ
> 
> On Thu, 19 Oct 2006 09:31:17 -0400
> Jeff Bischoff <jb...@klkurz.com> wrote:
> 
>> Bjorn,
>>
>> Put a method like this in some utility class in your web tier java code:
>>
>> public static void skipValidation() {
>> 	FacesContext context = FacesContext.getCurrentInstance();
>> 	context.renderResponse();
>> }
>>
>> Then you can call skipValidation() in your valueChangeListener method.
>>
>> You may notice that input components are not updated with model values 
>> that may have changed as a result of your immediate methods. If you, 
>> this article [1] may be of use to you as well.
>>
>> [1] http://wiki.apache.org/myfaces/ClearInputComponents
>>
>> Regards,
>>
>> Jeff Bischoff
>> Kenneth L Kurz & Associates, Inc.
>>
>> Bjørn T Johansen wrote:
>>> I have some edit boxes that has the attribute required set to true but I also have a selectOneMenu which does
>>> a submit when value changes... What is the best way to skip the required test when submitting using the
>>> selectOneMenu onChange event?
>>>
>>>
>>> Regards,
>>>
>>> BTJ
>>>
>>
> 
> 
> 



Re: Problem with required=true?

Posted by Bjørn T Johansen <bt...@havleik.no>.
Well, I need to update my form with new data as a result of that value change, so as far as I can tell, using this skipValidation
metehod won't help me?


BTJ

On Thu, 19 Oct 2006 09:31:17 -0400
Jeff Bischoff <jb...@klkurz.com> wrote:

> Bjorn,
> 
> Put a method like this in some utility class in your web tier java code:
> 
> public static void skipValidation() {
> 	FacesContext context = FacesContext.getCurrentInstance();
> 	context.renderResponse();
> }
> 
> Then you can call skipValidation() in your valueChangeListener method.
> 
> You may notice that input components are not updated with model values 
> that may have changed as a result of your immediate methods. If you, 
> this article [1] may be of use to you as well.
> 
> [1] http://wiki.apache.org/myfaces/ClearInputComponents
> 
> Regards,
> 
> Jeff Bischoff
> Kenneth L Kurz & Associates, Inc.
> 
> Bjørn T Johansen wrote:
> > I have some edit boxes that has the attribute required set to true but I also have a selectOneMenu which does
> > a submit when value changes... What is the best way to skip the required test when submitting using the
> > selectOneMenu onChange event?
> > 
> > 
> > Regards,
> > 
> > BTJ
> > 
> 
> 

Re: Problem with required=true?

Posted by Jeff Bischoff <jb...@klkurz.com>.
Bjorn,

Put a method like this in some utility class in your web tier java code:

public static void skipValidation() {
	FacesContext context = FacesContext.getCurrentInstance();
	context.renderResponse();
}

Then you can call skipValidation() in your valueChangeListener method.

You may notice that input components are not updated with model values 
that may have changed as a result of your immediate methods. If you, 
this article [1] may be of use to you as well.

[1] http://wiki.apache.org/myfaces/ClearInputComponents

Regards,

Jeff Bischoff
Kenneth L Kurz & Associates, Inc.

Bjørn T Johansen wrote:
> I have some edit boxes that has the attribute required set to true but I also have a selectOneMenu which does
> a submit when value changes... What is the best way to skip the required test when submitting using the
> selectOneMenu onChange event?
> 
> 
> Regards,
> 
> BTJ
>