You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Michael Heinen <mh...@recommind.com> on 2007/06/28 18:38:56 UTC

how to reset submitted values caused by validation errors ?

Hi,

 

I have a serious conversion/validation problem and don't see any
solution.

 

My form contains an inputField for dates and a dateTime converter.

If an invalid format is entered then the submitted value is not erased
and the page is rerendered with the entered date.

This is working fine so far.

 

Now I execute a kind of cancel button via ajax.

I use an a4j:commandButton with ajaxSingle=true and surrounded this
button by an a4j:region in order to process no input fields on
serverside.

The value that is bound via valueBinding to the inputField is set to
null in the invoked ActionListener.

The problem is now that the old invalid date is rerendered on the page.

 

This happens because the submitted value of the inputField is not null
but still contains the old invalid date.

Therefore the valueBinding is not evaluated in the getter.

 

I can't set the submitted value to null in the converter because invalid
values should be rerendered in case that a normal processing button (not
cancel button) is clicked.

 

Any help is highly appreciated.

Michael


RE: how to reset submitted values caused by validation errors ?

Posted by Michael Heinen <mh...@recommind.com>.
Hi Simon,

 

submittedValue is not transient.

Class javax.faces.component.UIInput contains following not transient
definition:

   private Object _submittedValue = null;

   

The submitted value is also saved in method saveState:

   values[4] = _submittedValue;

   

Moreover I don't use component binding but value binding.

Here is the field definition in my jsp:

<t:inputText id="creationDateFrom"
value="#{SearchController.editableSearch.attributes['creationDate'].begi
n}">

 

SearchController has session scope and I use server side state saving.

 

Any further ideas ?

Should submitted value be transient ?

 

Michael

 

From: Simon Lessard [mailto:simon.lessard.3@gmail.com] 
Sent: Donnerstag, 28. Juni 2007 22:51
To: MyFaces Discussion
Subject: Re: how to reset submitted values caused by validation errors ?

 

Hello Michael,

It seems a bit strange as the submitted value is transient and should
not be subject to state saving and consequently shouldn't polute
subsequent requests. My first guess would be that you're using binding
attribute with a session bean. Also, are you using client or server side
state saving? 


Regards,

~ Simon

On 6/28/07, Michael Heinen <mh...@recommind.com> wrote:

Hi,

 

I have a serious conversion/validation problem and don't see any
solution.

 

My form contains an inputField for dates and a dateTime converter.

If an invalid format is entered then the submitted value is not erased
and the page is rerendered with the entered date.

This is working fine so far.

 

Now I execute a kind of cancel button via ajax.

I use an a4j:commandButton with ajaxSingle=true and surrounded this
button by an a4j:region in order to process no input fields on
serverside.

The value that is bound via valueBinding to the inputField is set to
null in the invoked ActionListener.

The problem is now that the old invalid date is rerendered on the page.

 

This happens because the submitted value of the inputField is not null
but still contains the old invalid date.

Therefore the valueBinding is not evaluated in the getter.

 

I can't set the submitted value to null in the converter because invalid
values should be rerendered in case that a normal processing button (not
cancel button) is clicked.

 

Any help is highly appreciated.

Michael

 


Re: how to reset submitted values caused by validation errors ?

Posted by Simon Lessard <si...@gmail.com>.
Hello Michael,

It seems a bit strange as the submitted value is transient and should not be
subject to state saving and consequently shouldn't polute subsequent
requests. My first guess would be that you're using binding attribute with a
session bean. Also, are you using client or server side state saving?


Regards,

~ Simon

On 6/28/07, Michael Heinen <mh...@recommind.com> wrote:
>
>  Hi,
>
>
>
> I have a serious conversion/validation problem and don't see any solution.
>
>
>
> My form contains an inputField for dates and a dateTime converter.
>
> If an invalid format is entered then the submitted value is not erased and
> the page is rerendered with the entered date.
>
> This is working fine so far.
>
>
>
> Now I execute a kind of cancel button via ajax.
>
> I use an a4j:commandButton with ajaxSingle=true and surrounded this button
> by an a4j:region in order to process no input fields on serverside.
>
> The value that is bound via valueBinding to the inputField is set to null
> in the invoked ActionListener.
>
> The problem is now that the old invalid date is rerendered on the page.
>
>
>
> This happens because the submitted value of the inputField is not null but
> still contains the old invalid date.
>
> Therefore the valueBinding is not evaluated in the getter.
>
>
>
> I can't set the submitted value to null in the converter because invalid
> values should be rerendered in case that a normal processing button (not
> cancel button) is clicked.
>
>
>
> Any help is highly appreciated.
>
> Michael
>

Re: how to reset submitted values caused by validation errors ?

Posted by Simon Lessard <si...@gmail.com>.
Well, I had that issue quite recently with a special multi field validation
component I made. The submitted and local value was not set on the
components whose value didn't change, causing a null value to be passed to
the validation method. Anyway, I'll have to retry that with latest builds
and redo my trace to see if it isn't a classical code 18.

However it is possible to send only modified controls during a submit,
especially since most submits in JSF are launched by JavaScript. One would
simply have to compare controls' current values with their initial value,
then build a new invisible DOM to submit. Quite fishy, but doable.


Regards,

~ Simon

On 6/29/07, Michael Heinen <mh...@recommind.com> wrote:
>
>  Hi Simon,
>
>
>
> I don't know Trinidad, but I think that all values are submitted (or
> better those of the specified region in case of ajax/subforms).
>
> If a value is not submitted how could you test whether it had changed?
>
> But maybe my view of this  world is not correct ….
>
>
>
> Maybe I 'll try to create an extended HtmlInputText component that does
> not save/restore the _submittedValue.
>
>
>
> Michael
>
>
>
> *From:* Simon Lessard [mailto:simon.lessard.3@gmail.com]
> *Sent:* Freitag, 29. Juni 2007 16:13
> *To:* MyFaces Discussion
> *Subject:* Re: how to reset submitted values caused by validation errors ?
>
>
>
> Hello Micheal,
>
> I thought about it and making the submitted value transient is not so good
> because of the way values are submitted. I mainly use Trinidad though so I
> don't know if it's always the case, but only value that actually changed
> seems to be submitted. As a consequence, if the user enter an invalid value
> then submit, the submitted value will be rerendered as the original value in
> the postback response and then resubmit, then the invalid value won't be
> sent, thus preventing validations on the field unless the field is required,
> which is bad. However, I did not test that theory so I might be wrong.
>
>
> Regards,
>
> ~ Simon
>
> On 6/29/07, *Michael Heinen* <mh...@recommind.com> wrote:
>
> Andrew,
>
> Thanks for discussing this with me.
>
> I think this is a major downside in the JSF implementation and makes the
> usage with AJAX very difficult, inconvenient or even impossible. This
> would mean that I have to use component bindings for all values that are
> converted to Non-Strings or validated.
>
> (I don't like component bindings at all and I don't use them in any of
> my JSF applications.
> From my point of view they complicate development.
> But I don't want to start a discussion regarding component bindings here
> ;-) So back to my problem ... )
>
> I played a little bit with UIInput and removed _submittedValue from
> stateSaving (saveState and restoreState).
> This seems to work in my usecases.
> a) If the form is submitted via ajax with an invalid date that is
> *INSIDE* the submitted region then the submitted value is redisplayed
> sucessfully.
> b) If the form is submitted via ajax with an invalid date that is
> *OUTSIDE* the submitted region then the new value that I set in my
> ActionListener is displayed.
>
> As I mentioned I use serverside state saving.
>
> But currently I am not sure whether there are any sideeffects ...
>
> Any help is highly appreciated
> Michael
>
> -----Original Message-----
> From: Andrew Robinson [mailto:andrew.rw.robinson@gmail.com]
> Sent: Freitag, 29. Juni 2007 15:33
> To: MyFaces Discussion
> Subject: Re: how to reset submitted values caused by validation errors ?
>
> Submitted values should not be transient. According to the JSF spec,
> they are to be replaced during the decode phase. If the control is
> never decoded (like with some use cases using an a4j:region), the
> submitted value will never be changed.
>
> The idea of keeping the submitted value around is so that UIInput
> controls can re-display the user's selected value when a validation
> error occurs.
>
> I think your best bet, is to use binding on that component:
>
> <h:inputText id="theText" value="#{bean.value}" binding="#{bean.text}"
> />
>
> <a4j:region>
> <a4j:commandButton actionListener="#{bean.doit}" reRender="theText" />
> </a4j:region>
>
> public class Bean {
> private UIInput text;
> private String value;
> public String getValue() { return this.value; }
> public void setValue(String value) { this.value = value; }
> public UIInput getText() { return text; }
> public void setText(UIInput text) { this.text = text; }
> public void doit(ActionEvent evt) {
>   value = "cleared";
>   // clear any settings in text:
>   text.setSubmittedValue(null);
>   text.setLocalValue (null);
>   text.setValid(true);
>   text.setLocalValueSet(false);
> }
>
> Now the input text should have a value of "cleared" instead of the
> submitted value
>
> -Andrew
>
> On 6/29/07, Michael Heinen < mhn@recommind.com> wrote:
> > Hi Andrew,
> >
> > yes, the control is reRendered and part of the reRendered attribute of
> > the cancel-button.
> > If I place a t:outputText with the identical valueBinding before the
> > t:inputText then the right value is displayed as normal text.
> > But the inputText contains the old submitted value, which is still set
> > from the previous request.
> > I debugged this many times and verified that the old submitted value
> is
> > still set and that the corresponding getter is called.
> >
> > The input component is not in the submitted region because it should
> not
> > be validated.
> > I think this is exactly the problem, that the old submitted value is
> not
> > cleared.
> >
> > But even removing the region from the button and setting
> ajaxSingle=true
> > is no alternative.
> > In this case the wrong date is set again as submitted value (is the
> user
> > does not clear it manually)
> > My actionListener is called but the old view is rerendered containing
> > all submitted values.
> >
> > Furthermore I can't create a new viewRoot in the called ActionListener
> > because ajax would not work in this case and the whole page would be
> > rerendered instead of just the defined outputpanels.
> >
> > What about Simon's idea in the previous answer, that submitted value
> > should be transient ?
> >
> > Thanks,
> > Michael
> >
> > -----Original Message-----
> > From: Andrew Robinson [mailto:andrew.rw.robinson@gmail.com ]
> > Sent: Freitag, 29. Juni 2007 05:59
> > To: MyFaces Discussion
> > Subject: Re: how to reset submitted values caused by validation errors
> ?
> >
> > Do you have that control in the reRender of the a4j:commandButton tag?
> > Perhaps you just aren't re-rendering that component?
> >
> > Also, is that component in the region? If not, then that component
> > will not be validated and updated, and thus will not have the
> > submitted value and local values cleared.
> >
> > -Andrew
> >
> > On 6/28/07, Michael Heinen <mh...@recommind.com> wrote:
> > >
> > >
> > >
> > >
> > > Hi,
> > >
> > >
> > >
> > > I have a serious conversion/validation problem and don't see any
> > solution.
> > >
> > >
> > >
> > > My form contains an inputField for dates and a dateTime converter.
> > >
> > > If an invalid format is entered then the submitted value is not
> erased
> > and
> > > the page is rerendered with the entered date.
> > >
> > > This is working fine so far.
> > >
> > >
> > >
> > > Now I execute a kind of cancel button via ajax.
> > >
> > > I use an a4j:commandButton with ajaxSingle=true and surrounded this
> > button
> > > by an a4j:region in order to process no input fields on serverside.
> > >
> > > The value that is bound via valueBinding to the inputField is set to
> > null in
> > > the invoked ActionListener.
> > >
> > > The problem is now that the old invalid date is rerendered on the
> > page.
> > >
> > >
> > >
> > > This happens because the submitted value of the inputField is not
> null
> > but
> > > still contains the old invalid date.
> > >
> > > Therefore the valueBinding is not evaluated in the getter.
> > >
> > >
> > >
> > > I can't set the submitted value to null in the converter because
> > invalid
> > > values should be rerendered in case that a normal processing button
> > (not
> > > cancel button) is clicked.
> > >
> > >
> > >
> > > Any help is highly appreciated.
> > >
> > > Michael
> >
> >
>
>
>

RE: how to reset submitted values caused by validation errors ?

Posted by Michael Heinen <mh...@recommind.com>.
Hi Simon,

 

I don't know Trinidad, but I think that all values are submitted (or
better those of the specified region in case of ajax/subforms).

If a value is not submitted how could you test whether it had changed?

But maybe my view of this  world is not correct ....

 

Maybe I 'll try to create an extended HtmlInputText component that does
not save/restore the _submittedValue.

 

Michael

 

From: Simon Lessard [mailto:simon.lessard.3@gmail.com] 
Sent: Freitag, 29. Juni 2007 16:13
To: MyFaces Discussion
Subject: Re: how to reset submitted values caused by validation errors ?

 

Hello Micheal,

I thought about it and making the submitted value transient is not so
good because of the way values are submitted. I mainly use Trinidad
though so I don't know if it's always the case, but only value that
actually changed seems to be submitted. As a consequence, if the user
enter an invalid value then submit, the submitted value will be
rerendered as the original value in the postback response and then
resubmit, then the invalid value won't be sent, thus preventing
validations on the field unless the field is required, which is bad.
However, I did not test that theory so I might be wrong. 


Regards,

~ Simon

On 6/29/07, Michael Heinen <mh...@recommind.com> wrote:

Andrew,

Thanks for discussing this with me.

I think this is a major downside in the JSF implementation and makes the
usage with AJAX very difficult, inconvenient or even impossible. This
would mean that I have to use component bindings for all values that are

converted to Non-Strings or validated.

(I don't like component bindings at all and I don't use them in any of
my JSF applications.
>From my point of view they complicate development.
But I don't want to start a discussion regarding component bindings here

;-) So back to my problem ... )

I played a little bit with UIInput and removed _submittedValue from
stateSaving (saveState and restoreState).
This seems to work in my usecases.
a) If the form is submitted via ajax with an invalid date that is 
*INSIDE* the submitted region then the submitted value is redisplayed
sucessfully.
b) If the form is submitted via ajax with an invalid date that is
*OUTSIDE* the submitted region then the new value that I set in my 
ActionListener is displayed.

As I mentioned I use serverside state saving.

But currently I am not sure whether there are any sideeffects ...

Any help is highly appreciated
Michael

-----Original Message----- 
From: Andrew Robinson [mailto:andrew.rw.robinson@gmail.com]
Sent: Freitag, 29. Juni 2007 15:33
To: MyFaces Discussion
Subject: Re: how to reset submitted values caused by validation errors ?


Submitted values should not be transient. According to the JSF spec,
they are to be replaced during the decode phase. If the control is
never decoded (like with some use cases using an a4j:region), the
submitted value will never be changed. 

The idea of keeping the submitted value around is so that UIInput
controls can re-display the user's selected value when a validation
error occurs.

I think your best bet, is to use binding on that component: 

<h:inputText id="theText" value="#{bean.value}" binding="#{bean.text}"
/>

<a4j:region>
<a4j:commandButton actionListener="#{bean.doit}" reRender="theText" /> 
</a4j:region>

public class Bean {
private UIInput text;
private String value;
public String getValue() { return this.value; }
public void setValue(String value) { this.value = value; }
public UIInput getText() { return text; } 
public void setText(UIInput text) { this.text = text; }
public void doit(ActionEvent evt) {
  value = "cleared";
  // clear any settings in text:
  text.setSubmittedValue(null);
  text.setLocalValue (null);
  text.setValid(true);
  text.setLocalValueSet(false);
}

Now the input text should have a value of "cleared" instead of the
submitted value

-Andrew

On 6/29/07, Michael Heinen < mhn@recommind.com> wrote:
> Hi Andrew,
>
> yes, the control is reRendered and part of the reRendered attribute of
> the cancel-button.
> If I place a t:outputText with the identical valueBinding before the 
> t:inputText then the right value is displayed as normal text.
> But the inputText contains the old submitted value, which is still set
> from the previous request.
> I debugged this many times and verified that the old submitted value 
is
> still set and that the corresponding getter is called.
>
> The input component is not in the submitted region because it should
not
> be validated.
> I think this is exactly the problem, that the old submitted value is 
not
> cleared.
>
> But even removing the region from the button and setting
ajaxSingle=true
> is no alternative.
> In this case the wrong date is set again as submitted value (is the
user
> does not clear it manually)
> My actionListener is called but the old view is rerendered containing
> all submitted values.
>
> Furthermore I can't create a new viewRoot in the called ActionListener

> because ajax would not work in this case and the whole page would be
> rerendered instead of just the defined outputpanels.
>
> What about Simon's idea in the previous answer, that submitted value 
> should be transient ?
>
> Thanks,
> Michael
>
> -----Original Message-----
> From: Andrew Robinson [mailto:andrew.rw.robinson@gmail.com ]
> Sent: Freitag, 29. Juni 2007 05:59
> To: MyFaces Discussion
> Subject: Re: how to reset submitted values caused by validation errors
?
>
> Do you have that control in the reRender of the a4j:commandButton tag?

> Perhaps you just aren't re-rendering that component?
>
> Also, is that component in the region? If not, then that component
> will not be validated and updated, and thus will not have the
> submitted value and local values cleared.
>
> -Andrew
>
> On 6/28/07, Michael Heinen <mh...@recommind.com> wrote:
> >
> >
> > 
> >
> > Hi,
> >
> >
> >
> > I have a serious conversion/validation problem and don't see any
> solution.
> >
> >
> >
> > My form contains an inputField for dates and a dateTime converter. 
> >
> > If an invalid format is entered then the submitted value is not
erased
> and
> > the page is rerendered with the entered date.
> >
> > This is working fine so far. 
> >
> >
> >
> > Now I execute a kind of cancel button via ajax.
> >
> > I use an a4j:commandButton with ajaxSingle=true and surrounded this
> button
> > by an a4j:region in order to process no input fields on serverside. 
> >
> > The value that is bound via valueBinding to the inputField is set to
> null in
> > the invoked ActionListener.
> >
> > The problem is now that the old invalid date is rerendered on the 
> page.
> >
> >
> >
> > This happens because the submitted value of the inputField is not
null
> but
> > still contains the old invalid date.
> >
> > Therefore the valueBinding is not evaluated in the getter. 
> >
> >
> >
> > I can't set the submitted value to null in the converter because
> invalid
> > values should be rerendered in case that a normal processing button
> (not
> > cancel button) is clicked.
> >
> >
> >
> > Any help is highly appreciated.
> >
> > Michael
>
>

 


Re: how to reset submitted values caused by validation errors ?

Posted by Simon Lessard <si...@gmail.com>.
Hello Micheal,

I thought about it and making the submitted value transient is not so good
because of the way values are submitted. I mainly use Trinidad though so I
don't know if it's always the case, but only value that actually changed
seems to be submitted. As a consequence, if the user enter an invalid value
then submit, the submitted value will be rerendered as the original value in
the postback response and then resubmit, then the invalid value won't be
sent, thus preventing validations on the field unless the field is required,
which is bad. However, I did not test that theory so I might be wrong.


Regards,

~ Simon

On 6/29/07, Michael Heinen <mh...@recommind.com> wrote:
>
> Andrew,
>
> Thanks for discussing this with me.
>
> I think this is a major downside in the JSF implementation and makes the
> usage with AJAX very difficult, inconvenient or even impossible. This
> would mean that I have to use component bindings for all values that are
> converted to Non-Strings or validated.
>
> (I don't like component bindings at all and I don't use them in any of
> my JSF applications.
> From my point of view they complicate development.
> But I don't want to start a discussion regarding component bindings here
> ;-) So back to my problem ... )
>
> I played a little bit with UIInput and removed _submittedValue from
> stateSaving (saveState and restoreState).
> This seems to work in my usecases.
> a) If the form is submitted via ajax with an invalid date that is
> *INSIDE* the submitted region then the submitted value is redisplayed
> sucessfully.
> b) If the form is submitted via ajax with an invalid date that is
> *OUTSIDE* the submitted region then the new value that I set in my
> ActionListener is displayed.
>
> As I mentioned I use serverside state saving.
>
> But currently I am not sure whether there are any sideeffects ...
>
> Any help is highly appreciated
> Michael
>
> -----Original Message-----
> From: Andrew Robinson [mailto:andrew.rw.robinson@gmail.com]
> Sent: Freitag, 29. Juni 2007 15:33
> To: MyFaces Discussion
> Subject: Re: how to reset submitted values caused by validation errors ?
>
> Submitted values should not be transient. According to the JSF spec,
> they are to be replaced during the decode phase. If the control is
> never decoded (like with some use cases using an a4j:region), the
> submitted value will never be changed.
>
> The idea of keeping the submitted value around is so that UIInput
> controls can re-display the user's selected value when a validation
> error occurs.
>
> I think your best bet, is to use binding on that component:
>
> <h:inputText id="theText" value="#{bean.value}" binding="#{bean.text}"
> />
>
> <a4j:region>
> <a4j:commandButton actionListener="#{bean.doit}" reRender="theText" />
> </a4j:region>
>
> public class Bean {
> private UIInput text;
> private String value;
> public String getValue() { return this.value; }
> public void setValue(String value) { this.value = value; }
> public UIInput getText() { return text; }
> public void setText(UIInput text) { this.text = text; }
> public void doit(ActionEvent evt) {
>   value = "cleared";
>   // clear any settings in text:
>   text.setSubmittedValue(null);
>   text.setLocalValue(null);
>   text.setValid(true);
>   text.setLocalValueSet(false);
> }
>
> Now the input text should have a value of "cleared" instead of the
> submitted value
>
> -Andrew
>
> On 6/29/07, Michael Heinen <mh...@recommind.com> wrote:
> > Hi Andrew,
> >
> > yes, the control is reRendered and part of the reRendered attribute of
> > the cancel-button.
> > If I place a t:outputText with the identical valueBinding before the
> > t:inputText then the right value is displayed as normal text.
> > But the inputText contains the old submitted value, which is still set
> > from the previous request.
> > I debugged this many times and verified that the old submitted value
> is
> > still set and that the corresponding getter is called.
> >
> > The input component is not in the submitted region because it should
> not
> > be validated.
> > I think this is exactly the problem, that the old submitted value is
> not
> > cleared.
> >
> > But even removing the region from the button and setting
> ajaxSingle=true
> > is no alternative.
> > In this case the wrong date is set again as submitted value (is the
> user
> > does not clear it manually)
> > My actionListener is called but the old view is rerendered containing
> > all submitted values.
> >
> > Furthermore I can't create a new viewRoot in the called ActionListener
> > because ajax would not work in this case and the whole page would be
> > rerendered instead of just the defined outputpanels.
> >
> > What about Simon's idea in the previous answer, that submitted value
> > should be transient ?
> >
> > Thanks,
> > Michael
> >
> > -----Original Message-----
> > From: Andrew Robinson [mailto:andrew.rw.robinson@gmail.com]
> > Sent: Freitag, 29. Juni 2007 05:59
> > To: MyFaces Discussion
> > Subject: Re: how to reset submitted values caused by validation errors
> ?
> >
> > Do you have that control in the reRender of the a4j:commandButton tag?
> > Perhaps you just aren't re-rendering that component?
> >
> > Also, is that component in the region? If not, then that component
> > will not be validated and updated, and thus will not have the
> > submitted value and local values cleared.
> >
> > -Andrew
> >
> > On 6/28/07, Michael Heinen <mh...@recommind.com> wrote:
> > >
> > >
> > >
> > >
> > > Hi,
> > >
> > >
> > >
> > > I have a serious conversion/validation problem and don't see any
> > solution.
> > >
> > >
> > >
> > > My form contains an inputField for dates and a dateTime converter.
> > >
> > > If an invalid format is entered then the submitted value is not
> erased
> > and
> > > the page is rerendered with the entered date.
> > >
> > > This is working fine so far.
> > >
> > >
> > >
> > > Now I execute a kind of cancel button via ajax.
> > >
> > > I use an a4j:commandButton with ajaxSingle=true and surrounded this
> > button
> > > by an a4j:region in order to process no input fields on serverside.
> > >
> > > The value that is bound via valueBinding to the inputField is set to
> > null in
> > > the invoked ActionListener.
> > >
> > > The problem is now that the old invalid date is rerendered on the
> > page.
> > >
> > >
> > >
> > > This happens because the submitted value of the inputField is not
> null
> > but
> > > still contains the old invalid date.
> > >
> > > Therefore the valueBinding is not evaluated in the getter.
> > >
> > >
> > >
> > > I can't set the submitted value to null in the converter because
> > invalid
> > > values should be rerendered in case that a normal processing button
> > (not
> > > cancel button) is clicked.
> > >
> > >
> > >
> > > Any help is highly appreciated.
> > >
> > > Michael
> >
> >
>
>

RE: how to reset submitted values caused by validation errors ?

Posted by Michael Heinen <mh...@recommind.com>.
Well I am currently developing such a beast, a kind of a complex editor.
The most complex screen has about 30 ajax buttons, a few datatables on
various layers including datascrollers and inside the datatables are
additional ajax links in every row. 
Therefore I meant that this "clearListener" would work on simple screens
but if a page contains heavy ajax usage this could be very expensive or
a maintenance nightmare.

I absolutely agree with you that JSF needs more component-interdependent
code.
Optional required checks ;-) are really a pain. Without ajax it's hardly
doable.
I am happy about the sandbox compareToValidator which offers cross
component validation
But there is still missing a lot of functions that you need in daily
development and that require hacks and workarounds.

Michael


-----Original Message-----
From: Andrew Robinson [mailto:andrew.rw.robinson@gmail.com] 
Sent: Freitag, 29. Juni 2007 18:13
To: MyFaces Discussion
Subject: Re: how to reset submitted values caused by validation errors ?

Do you really think it will be that many components? This will only
happen if you change the values for components without "using" the
components to make the change. I don't see that as a very common use
case.

BTW - on that subject I do think JSF needs more
component-interdependent code (one component depending on one ore more
other components). This is especially true I think with components
that get turned on/off (visibility or disabled) using javascript. For
example, a check box that enables a text field -- that component
should only be required if the checkbox is checked.

On 6/29/07, Michael Heinen <mh...@recommind.com> wrote:
> Congratulations but you'll have much time from now on because you will
> not sleep late any more :-)) I'm experiencing this right now.
>
> Back to topic:
> The new component you mentioned sounds promising. I think it's
important
> that you can specify multiple values in the for-attribute as we can do
> in the reRender-attribute.
>
> On the other hand I am afraid that this is not the ultimate solution.
> This component must be added to nearly all commands(button/links) and
> all those zones must be specified that could contain fields with
> conversion/validation errors that are not submitted with the current
> command. This could result in a maintenance nightmare, or ?
>
> Pls don't get me wrong Andrew, I think this component could help in
> screens with a small number of commands and components. But wouldn't
it
> be difficult to use this component on complex screens with many
> commands, regions and rerenderAreas.
>
> Michael
>
> -----Original Message-----
> From: Andrew Robinson [mailto:andrew.rw.robinson@gmail.com]
> Sent: Freitag, 29. Juni 2007 16:23
> To: MyFaces Discussion
> Subject: Re: how to reset submitted values caused by validation errors
?
>
> You need to consider that changing values in action methods that
> UIInput components are bound to can get tricky with AJAX and partial
> updates. You are trying to create behavior that is against the JSF
> specification. Now, you site this as a downside, I view it as a lack
> of functionality that you desire that is easy to implement.
>
> What I advise, is to create a custom component, or action listener:
>
> <a4j:commandButton reRender="zoneA">
>   <my:clearSubmittedValues for="zoneA" />
> </a4j:commandButton>
>
> Then by looking at how the updateActionListener works in tomahawk, you
> can mirror the functionality. The body of this code would do the
> following:
>
> 1) use UIComponent.findComponent() to find the "for"
> 2) Search for all controls extending UIInput (or implementing
> EditableValueHolder) under that component
> 3) for all components found, erase the submitted value and local
values.
>
> This way you can determine when you want this behavior and when you
> don't. Who knows, perhaps when I get some time I could make this a
> sandbox component. It would also work well with the subForm component
> (as that behaves similar to the a4j:region). Don't count on a quick
> turn around though, I just had my first child, so have almost no time
> now :-)
>
> -Andrew
>
> On 6/29/07, Michael Heinen <mh...@recommind.com> wrote:
> > Andrew,
> >
> > Thanks for discussing this with me.
> >
> > I think this is a major downside in the JSF implementation and makes
> the
> > usage with AJAX very difficult, inconvenient or even impossible.
This
> > would mean that I have to use component bindings for all values that
> are
> > converted to Non-Strings or validated.
> >
> > (I don't like component bindings at all and I don't use them in any
of
> > my JSF applications.
> > From my point of view they complicate development.
> > But I don't want to start a discussion regarding component bindings
> here
> > ;-) So back to my problem ... )
> >
> > I played a little bit with UIInput and removed _submittedValue from
> > stateSaving (saveState and restoreState).
> > This seems to work in my usecases.
> > a) If the form is submitted via ajax with an invalid date that is
> > *INSIDE* the submitted region then the submitted value is
redisplayed
> > sucessfully.
> > b) If the form is submitted via ajax with an invalid date that is
> > *OUTSIDE* the submitted region then the new value that I set in my
> > ActionListener is displayed.
> >
> > As I mentioned I use serverside state saving.
> >
> > But currently I am not sure whether there are any sideeffects ...
> >
> > Any help is highly appreciated
> > Michael
> >
> > -----Original Message-----
> > From: Andrew Robinson [mailto:andrew.rw.robinson@gmail.com]
> > Sent: Freitag, 29. Juni 2007 15:33
> > To: MyFaces Discussion
> > Subject: Re: how to reset submitted values caused by validation
errors
> ?
> >
> > Submitted values should not be transient. According to the JSF spec,
> > they are to be replaced during the decode phase. If the control is
> > never decoded (like with some use cases using an a4j:region), the
> > submitted value will never be changed.
> >
> > The idea of keeping the submitted value around is so that UIInput
> > controls can re-display the user's selected value when a validation
> > error occurs.
> >
> > I think your best bet, is to use binding on that component:
> >
> > <h:inputText id="theText" value="#{bean.value}"
binding="#{bean.text}"
> > />
> >
> > <a4j:region>
> > <a4j:commandButton actionListener="#{bean.doit}" reRender="theText"
/>
> > </a4j:region>
> >
> > public class Bean {
> > private UIInput text;
> > private String value;
> > public String getValue() { return this.value; }
> > public void setValue(String value) { this.value = value; }
> > public UIInput getText() { return text; }
> > public void setText(UIInput text) { this.text = text; }
> > public void doit(ActionEvent evt) {
> >   value = "cleared";
> >   // clear any settings in text:
> >   text.setSubmittedValue(null);
> >   text.setLocalValue(null);
> >   text.setValid(true);
> >   text.setLocalValueSet(false);
> > }
> >
> > Now the input text should have a value of "cleared" instead of the
> > submitted value
> >
> > -Andrew
> >
> > On 6/29/07, Michael Heinen <mh...@recommind.com> wrote:
> > > Hi Andrew,
> > >
> > > yes, the control is reRendered and part of the reRendered
attribute
> of
> > > the cancel-button.
> > > If I place a t:outputText with the identical valueBinding before
the
> > > t:inputText then the right value is displayed as normal text.
> > > But the inputText contains the old submitted value, which is still
> set
> > > from the previous request.
> > > I debugged this many times and verified that the old submitted
value
> > is
> > > still set and that the corresponding getter is called.
> > >
> > > The input component is not in the submitted region because it
should
> > not
> > > be validated.
> > > I think this is exactly the problem, that the old submitted value
is
> > not
> > > cleared.
> > >
> > > But even removing the region from the button and setting
> > ajaxSingle=true
> > > is no alternative.
> > > In this case the wrong date is set again as submitted value (is
the
> > user
> > > does not clear it manually)
> > > My actionListener is called but the old view is rerendered
> containing
> > > all submitted values.
> > >
> > > Furthermore I can't create a new viewRoot in the called
> ActionListener
> > > because ajax would not work in this case and the whole page would
be
> > > rerendered instead of just the defined outputpanels.
> > >
> > > What about Simon's idea in the previous answer, that submitted
value
> > > should be transient ?
> > >
> > > Thanks,
> > > Michael
> > >
> > > -----Original Message-----
> > > From: Andrew Robinson [mailto:andrew.rw.robinson@gmail.com]
> > > Sent: Freitag, 29. Juni 2007 05:59
> > > To: MyFaces Discussion
> > > Subject: Re: how to reset submitted values caused by validation
> errors
> > ?
> > >
> > > Do you have that control in the reRender of the a4j:commandButton
> tag?
> > > Perhaps you just aren't re-rendering that component?
> > >
> > > Also, is that component in the region? If not, then that component
> > > will not be validated and updated, and thus will not have the
> > > submitted value and local values cleared.
> > >
> > > -Andrew
> > >
> > > On 6/28/07, Michael Heinen <mh...@recommind.com> wrote:
> > > >
> > > >
> > > >
> > > >
> > > > Hi,
> > > >
> > > >
> > > >
> > > > I have a serious conversion/validation problem and don't see any
> > > solution.
> > > >
> > > >
> > > >
> > > > My form contains an inputField for dates and a dateTime
converter.
> > > >
> > > > If an invalid format is entered then the submitted value is not
> > erased
> > > and
> > > > the page is rerendered with the entered date.
> > > >
> > > > This is working fine so far.
> > > >
> > > >
> > > >
> > > > Now I execute a kind of cancel button via ajax.
> > > >
> > > > I use an a4j:commandButton with ajaxSingle=true and surrounded
> this
> > > button
> > > > by an a4j:region in order to process no input fields on
> serverside.
> > > >
> > > > The value that is bound via valueBinding to the inputField is
set
> to
> > > null in
> > > > the invoked ActionListener.
> > > >
> > > > The problem is now that the old invalid date is rerendered on
the
> > > page.
> > > >
> > > >
> > > >
> > > > This happens because the submitted value of the inputField is
not
> > null
> > > but
> > > > still contains the old invalid date.
> > > >
> > > > Therefore the valueBinding is not evaluated in the getter.
> > > >
> > > >
> > > >
> > > > I can't set the submitted value to null in the converter because
> > > invalid
> > > > values should be rerendered in case that a normal processing
> button
> > > (not
> > > > cancel button) is clicked.
> > > >
> > > >
> > > >
> > > > Any help is highly appreciated.
> > > >
> > > > Michael
> > >
> > >
> >
> >
>
>


Re: how to reset submitted values caused by validation errors ?

Posted by Andrew Robinson <an...@gmail.com>.
Do you really think it will be that many components? This will only
happen if you change the values for components without "using" the
components to make the change. I don't see that as a very common use
case.

BTW - on that subject I do think JSF needs more
component-interdependent code (one component depending on one ore more
other components). This is especially true I think with components
that get turned on/off (visibility or disabled) using javascript. For
example, a check box that enables a text field -- that component
should only be required if the checkbox is checked.

On 6/29/07, Michael Heinen <mh...@recommind.com> wrote:
> Congratulations but you'll have much time from now on because you will
> not sleep late any more :-)) I'm experiencing this right now.
>
> Back to topic:
> The new component you mentioned sounds promising. I think it's important
> that you can specify multiple values in the for-attribute as we can do
> in the reRender-attribute.
>
> On the other hand I am afraid that this is not the ultimate solution.
> This component must be added to nearly all commands(button/links) and
> all those zones must be specified that could contain fields with
> conversion/validation errors that are not submitted with the current
> command. This could result in a maintenance nightmare, or ?
>
> Pls don't get me wrong Andrew, I think this component could help in
> screens with a small number of commands and components. But wouldn't it
> be difficult to use this component on complex screens with many
> commands, regions and rerenderAreas.
>
> Michael
>
> -----Original Message-----
> From: Andrew Robinson [mailto:andrew.rw.robinson@gmail.com]
> Sent: Freitag, 29. Juni 2007 16:23
> To: MyFaces Discussion
> Subject: Re: how to reset submitted values caused by validation errors ?
>
> You need to consider that changing values in action methods that
> UIInput components are bound to can get tricky with AJAX and partial
> updates. You are trying to create behavior that is against the JSF
> specification. Now, you site this as a downside, I view it as a lack
> of functionality that you desire that is easy to implement.
>
> What I advise, is to create a custom component, or action listener:
>
> <a4j:commandButton reRender="zoneA">
>   <my:clearSubmittedValues for="zoneA" />
> </a4j:commandButton>
>
> Then by looking at how the updateActionListener works in tomahawk, you
> can mirror the functionality. The body of this code would do the
> following:
>
> 1) use UIComponent.findComponent() to find the "for"
> 2) Search for all controls extending UIInput (or implementing
> EditableValueHolder) under that component
> 3) for all components found, erase the submitted value and local values.
>
> This way you can determine when you want this behavior and when you
> don't. Who knows, perhaps when I get some time I could make this a
> sandbox component. It would also work well with the subForm component
> (as that behaves similar to the a4j:region). Don't count on a quick
> turn around though, I just had my first child, so have almost no time
> now :-)
>
> -Andrew
>
> On 6/29/07, Michael Heinen <mh...@recommind.com> wrote:
> > Andrew,
> >
> > Thanks for discussing this with me.
> >
> > I think this is a major downside in the JSF implementation and makes
> the
> > usage with AJAX very difficult, inconvenient or even impossible. This
> > would mean that I have to use component bindings for all values that
> are
> > converted to Non-Strings or validated.
> >
> > (I don't like component bindings at all and I don't use them in any of
> > my JSF applications.
> > From my point of view they complicate development.
> > But I don't want to start a discussion regarding component bindings
> here
> > ;-) So back to my problem ... )
> >
> > I played a little bit with UIInput and removed _submittedValue from
> > stateSaving (saveState and restoreState).
> > This seems to work in my usecases.
> > a) If the form is submitted via ajax with an invalid date that is
> > *INSIDE* the submitted region then the submitted value is redisplayed
> > sucessfully.
> > b) If the form is submitted via ajax with an invalid date that is
> > *OUTSIDE* the submitted region then the new value that I set in my
> > ActionListener is displayed.
> >
> > As I mentioned I use serverside state saving.
> >
> > But currently I am not sure whether there are any sideeffects ...
> >
> > Any help is highly appreciated
> > Michael
> >
> > -----Original Message-----
> > From: Andrew Robinson [mailto:andrew.rw.robinson@gmail.com]
> > Sent: Freitag, 29. Juni 2007 15:33
> > To: MyFaces Discussion
> > Subject: Re: how to reset submitted values caused by validation errors
> ?
> >
> > Submitted values should not be transient. According to the JSF spec,
> > they are to be replaced during the decode phase. If the control is
> > never decoded (like with some use cases using an a4j:region), the
> > submitted value will never be changed.
> >
> > The idea of keeping the submitted value around is so that UIInput
> > controls can re-display the user's selected value when a validation
> > error occurs.
> >
> > I think your best bet, is to use binding on that component:
> >
> > <h:inputText id="theText" value="#{bean.value}" binding="#{bean.text}"
> > />
> >
> > <a4j:region>
> > <a4j:commandButton actionListener="#{bean.doit}" reRender="theText" />
> > </a4j:region>
> >
> > public class Bean {
> > private UIInput text;
> > private String value;
> > public String getValue() { return this.value; }
> > public void setValue(String value) { this.value = value; }
> > public UIInput getText() { return text; }
> > public void setText(UIInput text) { this.text = text; }
> > public void doit(ActionEvent evt) {
> >   value = "cleared";
> >   // clear any settings in text:
> >   text.setSubmittedValue(null);
> >   text.setLocalValue(null);
> >   text.setValid(true);
> >   text.setLocalValueSet(false);
> > }
> >
> > Now the input text should have a value of "cleared" instead of the
> > submitted value
> >
> > -Andrew
> >
> > On 6/29/07, Michael Heinen <mh...@recommind.com> wrote:
> > > Hi Andrew,
> > >
> > > yes, the control is reRendered and part of the reRendered attribute
> of
> > > the cancel-button.
> > > If I place a t:outputText with the identical valueBinding before the
> > > t:inputText then the right value is displayed as normal text.
> > > But the inputText contains the old submitted value, which is still
> set
> > > from the previous request.
> > > I debugged this many times and verified that the old submitted value
> > is
> > > still set and that the corresponding getter is called.
> > >
> > > The input component is not in the submitted region because it should
> > not
> > > be validated.
> > > I think this is exactly the problem, that the old submitted value is
> > not
> > > cleared.
> > >
> > > But even removing the region from the button and setting
> > ajaxSingle=true
> > > is no alternative.
> > > In this case the wrong date is set again as submitted value (is the
> > user
> > > does not clear it manually)
> > > My actionListener is called but the old view is rerendered
> containing
> > > all submitted values.
> > >
> > > Furthermore I can't create a new viewRoot in the called
> ActionListener
> > > because ajax would not work in this case and the whole page would be
> > > rerendered instead of just the defined outputpanels.
> > >
> > > What about Simon's idea in the previous answer, that submitted value
> > > should be transient ?
> > >
> > > Thanks,
> > > Michael
> > >
> > > -----Original Message-----
> > > From: Andrew Robinson [mailto:andrew.rw.robinson@gmail.com]
> > > Sent: Freitag, 29. Juni 2007 05:59
> > > To: MyFaces Discussion
> > > Subject: Re: how to reset submitted values caused by validation
> errors
> > ?
> > >
> > > Do you have that control in the reRender of the a4j:commandButton
> tag?
> > > Perhaps you just aren't re-rendering that component?
> > >
> > > Also, is that component in the region? If not, then that component
> > > will not be validated and updated, and thus will not have the
> > > submitted value and local values cleared.
> > >
> > > -Andrew
> > >
> > > On 6/28/07, Michael Heinen <mh...@recommind.com> wrote:
> > > >
> > > >
> > > >
> > > >
> > > > Hi,
> > > >
> > > >
> > > >
> > > > I have a serious conversion/validation problem and don't see any
> > > solution.
> > > >
> > > >
> > > >
> > > > My form contains an inputField for dates and a dateTime converter.
> > > >
> > > > If an invalid format is entered then the submitted value is not
> > erased
> > > and
> > > > the page is rerendered with the entered date.
> > > >
> > > > This is working fine so far.
> > > >
> > > >
> > > >
> > > > Now I execute a kind of cancel button via ajax.
> > > >
> > > > I use an a4j:commandButton with ajaxSingle=true and surrounded
> this
> > > button
> > > > by an a4j:region in order to process no input fields on
> serverside.
> > > >
> > > > The value that is bound via valueBinding to the inputField is set
> to
> > > null in
> > > > the invoked ActionListener.
> > > >
> > > > The problem is now that the old invalid date is rerendered on the
> > > page.
> > > >
> > > >
> > > >
> > > > This happens because the submitted value of the inputField is not
> > null
> > > but
> > > > still contains the old invalid date.
> > > >
> > > > Therefore the valueBinding is not evaluated in the getter.
> > > >
> > > >
> > > >
> > > > I can't set the submitted value to null in the converter because
> > > invalid
> > > > values should be rerendered in case that a normal processing
> button
> > > (not
> > > > cancel button) is clicked.
> > > >
> > > >
> > > >
> > > > Any help is highly appreciated.
> > > >
> > > > Michael
> > >
> > >
> >
> >
>
>

RE: how to reset submitted values caused by validation errors ?

Posted by Michael Heinen <mh...@recommind.com>.
Congratulations but you'll have much time from now on because you will
not sleep late any more :-)) I'm experiencing this right now.

Back to topic:
The new component you mentioned sounds promising. I think it's important
that you can specify multiple values in the for-attribute as we can do
in the reRender-attribute.

On the other hand I am afraid that this is not the ultimate solution.
This component must be added to nearly all commands(button/links) and
all those zones must be specified that could contain fields with
conversion/validation errors that are not submitted with the current
command. This could result in a maintenance nightmare, or ?

Pls don't get me wrong Andrew, I think this component could help in
screens with a small number of commands and components. But wouldn't it
be difficult to use this component on complex screens with many
commands, regions and rerenderAreas.

Michael

-----Original Message-----
From: Andrew Robinson [mailto:andrew.rw.robinson@gmail.com] 
Sent: Freitag, 29. Juni 2007 16:23
To: MyFaces Discussion
Subject: Re: how to reset submitted values caused by validation errors ?

You need to consider that changing values in action methods that
UIInput components are bound to can get tricky with AJAX and partial
updates. You are trying to create behavior that is against the JSF
specification. Now, you site this as a downside, I view it as a lack
of functionality that you desire that is easy to implement.

What I advise, is to create a custom component, or action listener:

<a4j:commandButton reRender="zoneA">
  <my:clearSubmittedValues for="zoneA" />
</a4j:commandButton>

Then by looking at how the updateActionListener works in tomahawk, you
can mirror the functionality. The body of this code would do the
following:

1) use UIComponent.findComponent() to find the "for"
2) Search for all controls extending UIInput (or implementing
EditableValueHolder) under that component
3) for all components found, erase the submitted value and local values.

This way you can determine when you want this behavior and when you
don't. Who knows, perhaps when I get some time I could make this a
sandbox component. It would also work well with the subForm component
(as that behaves similar to the a4j:region). Don't count on a quick
turn around though, I just had my first child, so have almost no time
now :-)

-Andrew

On 6/29/07, Michael Heinen <mh...@recommind.com> wrote:
> Andrew,
>
> Thanks for discussing this with me.
>
> I think this is a major downside in the JSF implementation and makes
the
> usage with AJAX very difficult, inconvenient or even impossible. This
> would mean that I have to use component bindings for all values that
are
> converted to Non-Strings or validated.
>
> (I don't like component bindings at all and I don't use them in any of
> my JSF applications.
> From my point of view they complicate development.
> But I don't want to start a discussion regarding component bindings
here
> ;-) So back to my problem ... )
>
> I played a little bit with UIInput and removed _submittedValue from
> stateSaving (saveState and restoreState).
> This seems to work in my usecases.
> a) If the form is submitted via ajax with an invalid date that is
> *INSIDE* the submitted region then the submitted value is redisplayed
> sucessfully.
> b) If the form is submitted via ajax with an invalid date that is
> *OUTSIDE* the submitted region then the new value that I set in my
> ActionListener is displayed.
>
> As I mentioned I use serverside state saving.
>
> But currently I am not sure whether there are any sideeffects ...
>
> Any help is highly appreciated
> Michael
>
> -----Original Message-----
> From: Andrew Robinson [mailto:andrew.rw.robinson@gmail.com]
> Sent: Freitag, 29. Juni 2007 15:33
> To: MyFaces Discussion
> Subject: Re: how to reset submitted values caused by validation errors
?
>
> Submitted values should not be transient. According to the JSF spec,
> they are to be replaced during the decode phase. If the control is
> never decoded (like with some use cases using an a4j:region), the
> submitted value will never be changed.
>
> The idea of keeping the submitted value around is so that UIInput
> controls can re-display the user's selected value when a validation
> error occurs.
>
> I think your best bet, is to use binding on that component:
>
> <h:inputText id="theText" value="#{bean.value}" binding="#{bean.text}"
> />
>
> <a4j:region>
> <a4j:commandButton actionListener="#{bean.doit}" reRender="theText" />
> </a4j:region>
>
> public class Bean {
> private UIInput text;
> private String value;
> public String getValue() { return this.value; }
> public void setValue(String value) { this.value = value; }
> public UIInput getText() { return text; }
> public void setText(UIInput text) { this.text = text; }
> public void doit(ActionEvent evt) {
>   value = "cleared";
>   // clear any settings in text:
>   text.setSubmittedValue(null);
>   text.setLocalValue(null);
>   text.setValid(true);
>   text.setLocalValueSet(false);
> }
>
> Now the input text should have a value of "cleared" instead of the
> submitted value
>
> -Andrew
>
> On 6/29/07, Michael Heinen <mh...@recommind.com> wrote:
> > Hi Andrew,
> >
> > yes, the control is reRendered and part of the reRendered attribute
of
> > the cancel-button.
> > If I place a t:outputText with the identical valueBinding before the
> > t:inputText then the right value is displayed as normal text.
> > But the inputText contains the old submitted value, which is still
set
> > from the previous request.
> > I debugged this many times and verified that the old submitted value
> is
> > still set and that the corresponding getter is called.
> >
> > The input component is not in the submitted region because it should
> not
> > be validated.
> > I think this is exactly the problem, that the old submitted value is
> not
> > cleared.
> >
> > But even removing the region from the button and setting
> ajaxSingle=true
> > is no alternative.
> > In this case the wrong date is set again as submitted value (is the
> user
> > does not clear it manually)
> > My actionListener is called but the old view is rerendered
containing
> > all submitted values.
> >
> > Furthermore I can't create a new viewRoot in the called
ActionListener
> > because ajax would not work in this case and the whole page would be
> > rerendered instead of just the defined outputpanels.
> >
> > What about Simon's idea in the previous answer, that submitted value
> > should be transient ?
> >
> > Thanks,
> > Michael
> >
> > -----Original Message-----
> > From: Andrew Robinson [mailto:andrew.rw.robinson@gmail.com]
> > Sent: Freitag, 29. Juni 2007 05:59
> > To: MyFaces Discussion
> > Subject: Re: how to reset submitted values caused by validation
errors
> ?
> >
> > Do you have that control in the reRender of the a4j:commandButton
tag?
> > Perhaps you just aren't re-rendering that component?
> >
> > Also, is that component in the region? If not, then that component
> > will not be validated and updated, and thus will not have the
> > submitted value and local values cleared.
> >
> > -Andrew
> >
> > On 6/28/07, Michael Heinen <mh...@recommind.com> wrote:
> > >
> > >
> > >
> > >
> > > Hi,
> > >
> > >
> > >
> > > I have a serious conversion/validation problem and don't see any
> > solution.
> > >
> > >
> > >
> > > My form contains an inputField for dates and a dateTime converter.
> > >
> > > If an invalid format is entered then the submitted value is not
> erased
> > and
> > > the page is rerendered with the entered date.
> > >
> > > This is working fine so far.
> > >
> > >
> > >
> > > Now I execute a kind of cancel button via ajax.
> > >
> > > I use an a4j:commandButton with ajaxSingle=true and surrounded
this
> > button
> > > by an a4j:region in order to process no input fields on
serverside.
> > >
> > > The value that is bound via valueBinding to the inputField is set
to
> > null in
> > > the invoked ActionListener.
> > >
> > > The problem is now that the old invalid date is rerendered on the
> > page.
> > >
> > >
> > >
> > > This happens because the submitted value of the inputField is not
> null
> > but
> > > still contains the old invalid date.
> > >
> > > Therefore the valueBinding is not evaluated in the getter.
> > >
> > >
> > >
> > > I can't set the submitted value to null in the converter because
> > invalid
> > > values should be rerendered in case that a normal processing
button
> > (not
> > > cancel button) is clicked.
> > >
> > >
> > >
> > > Any help is highly appreciated.
> > >
> > > Michael
> >
> >
>
>


Re: how to reset submitted values caused by validation errors ?

Posted by Andrew Robinson <an...@gmail.com>.
You need to consider that changing values in action methods that
UIInput components are bound to can get tricky with AJAX and partial
updates. You are trying to create behavior that is against the JSF
specification. Now, you site this as a downside, I view it as a lack
of functionality that you desire that is easy to implement.

What I advise, is to create a custom component, or action listener:

<a4j:commandButton reRender="zoneA">
  <my:clearSubmittedValues for="zoneA" />
</a4j:commandButton>

Then by looking at how the updateActionListener works in tomahawk, you
can mirror the functionality. The body of this code would do the
following:

1) use UIComponent.findComponent() to find the "for"
2) Search for all controls extending UIInput (or implementing
EditableValueHolder) under that component
3) for all components found, erase the submitted value and local values.

This way you can determine when you want this behavior and when you
don't. Who knows, perhaps when I get some time I could make this a
sandbox component. It would also work well with the subForm component
(as that behaves similar to the a4j:region). Don't count on a quick
turn around though, I just had my first child, so have almost no time
now :-)

-Andrew

On 6/29/07, Michael Heinen <mh...@recommind.com> wrote:
> Andrew,
>
> Thanks for discussing this with me.
>
> I think this is a major downside in the JSF implementation and makes the
> usage with AJAX very difficult, inconvenient or even impossible. This
> would mean that I have to use component bindings for all values that are
> converted to Non-Strings or validated.
>
> (I don't like component bindings at all and I don't use them in any of
> my JSF applications.
> From my point of view they complicate development.
> But I don't want to start a discussion regarding component bindings here
> ;-) So back to my problem ... )
>
> I played a little bit with UIInput and removed _submittedValue from
> stateSaving (saveState and restoreState).
> This seems to work in my usecases.
> a) If the form is submitted via ajax with an invalid date that is
> *INSIDE* the submitted region then the submitted value is redisplayed
> sucessfully.
> b) If the form is submitted via ajax with an invalid date that is
> *OUTSIDE* the submitted region then the new value that I set in my
> ActionListener is displayed.
>
> As I mentioned I use serverside state saving.
>
> But currently I am not sure whether there are any sideeffects ...
>
> Any help is highly appreciated
> Michael
>
> -----Original Message-----
> From: Andrew Robinson [mailto:andrew.rw.robinson@gmail.com]
> Sent: Freitag, 29. Juni 2007 15:33
> To: MyFaces Discussion
> Subject: Re: how to reset submitted values caused by validation errors ?
>
> Submitted values should not be transient. According to the JSF spec,
> they are to be replaced during the decode phase. If the control is
> never decoded (like with some use cases using an a4j:region), the
> submitted value will never be changed.
>
> The idea of keeping the submitted value around is so that UIInput
> controls can re-display the user's selected value when a validation
> error occurs.
>
> I think your best bet, is to use binding on that component:
>
> <h:inputText id="theText" value="#{bean.value}" binding="#{bean.text}"
> />
>
> <a4j:region>
> <a4j:commandButton actionListener="#{bean.doit}" reRender="theText" />
> </a4j:region>
>
> public class Bean {
> private UIInput text;
> private String value;
> public String getValue() { return this.value; }
> public void setValue(String value) { this.value = value; }
> public UIInput getText() { return text; }
> public void setText(UIInput text) { this.text = text; }
> public void doit(ActionEvent evt) {
>   value = "cleared";
>   // clear any settings in text:
>   text.setSubmittedValue(null);
>   text.setLocalValue(null);
>   text.setValid(true);
>   text.setLocalValueSet(false);
> }
>
> Now the input text should have a value of "cleared" instead of the
> submitted value
>
> -Andrew
>
> On 6/29/07, Michael Heinen <mh...@recommind.com> wrote:
> > Hi Andrew,
> >
> > yes, the control is reRendered and part of the reRendered attribute of
> > the cancel-button.
> > If I place a t:outputText with the identical valueBinding before the
> > t:inputText then the right value is displayed as normal text.
> > But the inputText contains the old submitted value, which is still set
> > from the previous request.
> > I debugged this many times and verified that the old submitted value
> is
> > still set and that the corresponding getter is called.
> >
> > The input component is not in the submitted region because it should
> not
> > be validated.
> > I think this is exactly the problem, that the old submitted value is
> not
> > cleared.
> >
> > But even removing the region from the button and setting
> ajaxSingle=true
> > is no alternative.
> > In this case the wrong date is set again as submitted value (is the
> user
> > does not clear it manually)
> > My actionListener is called but the old view is rerendered containing
> > all submitted values.
> >
> > Furthermore I can't create a new viewRoot in the called ActionListener
> > because ajax would not work in this case and the whole page would be
> > rerendered instead of just the defined outputpanels.
> >
> > What about Simon's idea in the previous answer, that submitted value
> > should be transient ?
> >
> > Thanks,
> > Michael
> >
> > -----Original Message-----
> > From: Andrew Robinson [mailto:andrew.rw.robinson@gmail.com]
> > Sent: Freitag, 29. Juni 2007 05:59
> > To: MyFaces Discussion
> > Subject: Re: how to reset submitted values caused by validation errors
> ?
> >
> > Do you have that control in the reRender of the a4j:commandButton tag?
> > Perhaps you just aren't re-rendering that component?
> >
> > Also, is that component in the region? If not, then that component
> > will not be validated and updated, and thus will not have the
> > submitted value and local values cleared.
> >
> > -Andrew
> >
> > On 6/28/07, Michael Heinen <mh...@recommind.com> wrote:
> > >
> > >
> > >
> > >
> > > Hi,
> > >
> > >
> > >
> > > I have a serious conversion/validation problem and don't see any
> > solution.
> > >
> > >
> > >
> > > My form contains an inputField for dates and a dateTime converter.
> > >
> > > If an invalid format is entered then the submitted value is not
> erased
> > and
> > > the page is rerendered with the entered date.
> > >
> > > This is working fine so far.
> > >
> > >
> > >
> > > Now I execute a kind of cancel button via ajax.
> > >
> > > I use an a4j:commandButton with ajaxSingle=true and surrounded this
> > button
> > > by an a4j:region in order to process no input fields on serverside.
> > >
> > > The value that is bound via valueBinding to the inputField is set to
> > null in
> > > the invoked ActionListener.
> > >
> > > The problem is now that the old invalid date is rerendered on the
> > page.
> > >
> > >
> > >
> > > This happens because the submitted value of the inputField is not
> null
> > but
> > > still contains the old invalid date.
> > >
> > > Therefore the valueBinding is not evaluated in the getter.
> > >
> > >
> > >
> > > I can't set the submitted value to null in the converter because
> > invalid
> > > values should be rerendered in case that a normal processing button
> > (not
> > > cancel button) is clicked.
> > >
> > >
> > >
> > > Any help is highly appreciated.
> > >
> > > Michael
> >
> >
>
>

RE: how to reset submitted values caused by validation errors ?

Posted by Michael Heinen <mh...@recommind.com>.
Andrew,

Thanks for discussing this with me.

I think this is a major downside in the JSF implementation and makes the
usage with AJAX very difficult, inconvenient or even impossible. This
would mean that I have to use component bindings for all values that are
converted to Non-Strings or validated.

(I don't like component bindings at all and I don't use them in any of
my JSF applications.
>From my point of view they complicate development. 
But I don't want to start a discussion regarding component bindings here
;-) So back to my problem ... )

I played a little bit with UIInput and removed _submittedValue from
stateSaving (saveState and restoreState).
This seems to work in my usecases.
a) If the form is submitted via ajax with an invalid date that is
*INSIDE* the submitted region then the submitted value is redisplayed
sucessfully.
b) If the form is submitted via ajax with an invalid date that is
*OUTSIDE* the submitted region then the new value that I set in my
ActionListener is displayed.

As I mentioned I use serverside state saving.

But currently I am not sure whether there are any sideeffects ...

Any help is highly appreciated
Michael

-----Original Message-----
From: Andrew Robinson [mailto:andrew.rw.robinson@gmail.com] 
Sent: Freitag, 29. Juni 2007 15:33
To: MyFaces Discussion
Subject: Re: how to reset submitted values caused by validation errors ?

Submitted values should not be transient. According to the JSF spec,
they are to be replaced during the decode phase. If the control is
never decoded (like with some use cases using an a4j:region), the
submitted value will never be changed.

The idea of keeping the submitted value around is so that UIInput
controls can re-display the user's selected value when a validation
error occurs.

I think your best bet, is to use binding on that component:

<h:inputText id="theText" value="#{bean.value}" binding="#{bean.text}"
/>

<a4j:region>
<a4j:commandButton actionListener="#{bean.doit}" reRender="theText" />
</a4j:region>

public class Bean {
private UIInput text;
private String value;
public String getValue() { return this.value; }
public void setValue(String value) { this.value = value; }
public UIInput getText() { return text; }
public void setText(UIInput text) { this.text = text; }
public void doit(ActionEvent evt) {
  value = "cleared";
  // clear any settings in text:
  text.setSubmittedValue(null);
  text.setLocalValue(null);
  text.setValid(true);
  text.setLocalValueSet(false);
}

Now the input text should have a value of "cleared" instead of the
submitted value

-Andrew

On 6/29/07, Michael Heinen <mh...@recommind.com> wrote:
> Hi Andrew,
>
> yes, the control is reRendered and part of the reRendered attribute of
> the cancel-button.
> If I place a t:outputText with the identical valueBinding before the
> t:inputText then the right value is displayed as normal text.
> But the inputText contains the old submitted value, which is still set
> from the previous request.
> I debugged this many times and verified that the old submitted value
is
> still set and that the corresponding getter is called.
>
> The input component is not in the submitted region because it should
not
> be validated.
> I think this is exactly the problem, that the old submitted value is
not
> cleared.
>
> But even removing the region from the button and setting
ajaxSingle=true
> is no alternative.
> In this case the wrong date is set again as submitted value (is the
user
> does not clear it manually)
> My actionListener is called but the old view is rerendered containing
> all submitted values.
>
> Furthermore I can't create a new viewRoot in the called ActionListener
> because ajax would not work in this case and the whole page would be
> rerendered instead of just the defined outputpanels.
>
> What about Simon's idea in the previous answer, that submitted value
> should be transient ?
>
> Thanks,
> Michael
>
> -----Original Message-----
> From: Andrew Robinson [mailto:andrew.rw.robinson@gmail.com]
> Sent: Freitag, 29. Juni 2007 05:59
> To: MyFaces Discussion
> Subject: Re: how to reset submitted values caused by validation errors
?
>
> Do you have that control in the reRender of the a4j:commandButton tag?
> Perhaps you just aren't re-rendering that component?
>
> Also, is that component in the region? If not, then that component
> will not be validated and updated, and thus will not have the
> submitted value and local values cleared.
>
> -Andrew
>
> On 6/28/07, Michael Heinen <mh...@recommind.com> wrote:
> >
> >
> >
> >
> > Hi,
> >
> >
> >
> > I have a serious conversion/validation problem and don't see any
> solution.
> >
> >
> >
> > My form contains an inputField for dates and a dateTime converter.
> >
> > If an invalid format is entered then the submitted value is not
erased
> and
> > the page is rerendered with the entered date.
> >
> > This is working fine so far.
> >
> >
> >
> > Now I execute a kind of cancel button via ajax.
> >
> > I use an a4j:commandButton with ajaxSingle=true and surrounded this
> button
> > by an a4j:region in order to process no input fields on serverside.
> >
> > The value that is bound via valueBinding to the inputField is set to
> null in
> > the invoked ActionListener.
> >
> > The problem is now that the old invalid date is rerendered on the
> page.
> >
> >
> >
> > This happens because the submitted value of the inputField is not
null
> but
> > still contains the old invalid date.
> >
> > Therefore the valueBinding is not evaluated in the getter.
> >
> >
> >
> > I can't set the submitted value to null in the converter because
> invalid
> > values should be rerendered in case that a normal processing button
> (not
> > cancel button) is clicked.
> >
> >
> >
> > Any help is highly appreciated.
> >
> > Michael
>
>


Re: how to reset submitted values caused by validation errors ?

Posted by Andrew Robinson <an...@gmail.com>.
Submitted values should not be transient. According to the JSF spec,
they are to be replaced during the decode phase. If the control is
never decoded (like with some use cases using an a4j:region), the
submitted value will never be changed.

The idea of keeping the submitted value around is so that UIInput
controls can re-display the user's selected value when a validation
error occurs.

I think your best bet, is to use binding on that component:

<h:inputText id="theText" value="#{bean.value}" binding="#{bean.text}" />

<a4j:region>
<a4j:commandButton actionListener="#{bean.doit}" reRender="theText" />
</a4j:region>

public class Bean {
private UIInput text;
private String value;
public String getValue() { return this.value; }
public void setValue(String value) { this.value = value; }
public UIInput getText() { return text; }
public void setText(UIInput text) { this.text = text; }
public void doit(ActionEvent evt) {
  value = "cleared";
  // clear any settings in text:
  text.setSubmittedValue(null);
  text.setLocalValue(null);
  text.setValid(true);
  text.setLocalValueSet(false);
}

Now the input text should have a value of "cleared" instead of the
submitted value

-Andrew

On 6/29/07, Michael Heinen <mh...@recommind.com> wrote:
> Hi Andrew,
>
> yes, the control is reRendered and part of the reRendered attribute of
> the cancel-button.
> If I place a t:outputText with the identical valueBinding before the
> t:inputText then the right value is displayed as normal text.
> But the inputText contains the old submitted value, which is still set
> from the previous request.
> I debugged this many times and verified that the old submitted value is
> still set and that the corresponding getter is called.
>
> The input component is not in the submitted region because it should not
> be validated.
> I think this is exactly the problem, that the old submitted value is not
> cleared.
>
> But even removing the region from the button and setting ajaxSingle=true
> is no alternative.
> In this case the wrong date is set again as submitted value (is the user
> does not clear it manually)
> My actionListener is called but the old view is rerendered containing
> all submitted values.
>
> Furthermore I can't create a new viewRoot in the called ActionListener
> because ajax would not work in this case and the whole page would be
> rerendered instead of just the defined outputpanels.
>
> What about Simon's idea in the previous answer, that submitted value
> should be transient ?
>
> Thanks,
> Michael
>
> -----Original Message-----
> From: Andrew Robinson [mailto:andrew.rw.robinson@gmail.com]
> Sent: Freitag, 29. Juni 2007 05:59
> To: MyFaces Discussion
> Subject: Re: how to reset submitted values caused by validation errors ?
>
> Do you have that control in the reRender of the a4j:commandButton tag?
> Perhaps you just aren't re-rendering that component?
>
> Also, is that component in the region? If not, then that component
> will not be validated and updated, and thus will not have the
> submitted value and local values cleared.
>
> -Andrew
>
> On 6/28/07, Michael Heinen <mh...@recommind.com> wrote:
> >
> >
> >
> >
> > Hi,
> >
> >
> >
> > I have a serious conversion/validation problem and don't see any
> solution.
> >
> >
> >
> > My form contains an inputField for dates and a dateTime converter.
> >
> > If an invalid format is entered then the submitted value is not erased
> and
> > the page is rerendered with the entered date.
> >
> > This is working fine so far.
> >
> >
> >
> > Now I execute a kind of cancel button via ajax.
> >
> > I use an a4j:commandButton with ajaxSingle=true and surrounded this
> button
> > by an a4j:region in order to process no input fields on serverside.
> >
> > The value that is bound via valueBinding to the inputField is set to
> null in
> > the invoked ActionListener.
> >
> > The problem is now that the old invalid date is rerendered on the
> page.
> >
> >
> >
> > This happens because the submitted value of the inputField is not null
> but
> > still contains the old invalid date.
> >
> > Therefore the valueBinding is not evaluated in the getter.
> >
> >
> >
> > I can't set the submitted value to null in the converter because
> invalid
> > values should be rerendered in case that a normal processing button
> (not
> > cancel button) is clicked.
> >
> >
> >
> > Any help is highly appreciated.
> >
> > Michael
>
>

RE: how to reset submitted values caused by validation errors ?

Posted by Michael Heinen <mh...@recommind.com>.
Hi Andrew,

yes, the control is reRendered and part of the reRendered attribute of
the cancel-button.
If I place a t:outputText with the identical valueBinding before the
t:inputText then the right value is displayed as normal text.
But the inputText contains the old submitted value, which is still set
from the previous request.
I debugged this many times and verified that the old submitted value is
still set and that the corresponding getter is called.

The input component is not in the submitted region because it should not
be validated.
I think this is exactly the problem, that the old submitted value is not
cleared.

But even removing the region from the button and setting ajaxSingle=true
is no alternative.
In this case the wrong date is set again as submitted value (is the user
does not clear it manually)
My actionListener is called but the old view is rerendered containing
all submitted values.

Furthermore I can't create a new viewRoot in the called ActionListener
because ajax would not work in this case and the whole page would be
rerendered instead of just the defined outputpanels.

What about Simon's idea in the previous answer, that submitted value
should be transient ?

Thanks,
Michael

-----Original Message-----
From: Andrew Robinson [mailto:andrew.rw.robinson@gmail.com] 
Sent: Freitag, 29. Juni 2007 05:59
To: MyFaces Discussion
Subject: Re: how to reset submitted values caused by validation errors ?

Do you have that control in the reRender of the a4j:commandButton tag?
Perhaps you just aren't re-rendering that component?

Also, is that component in the region? If not, then that component
will not be validated and updated, and thus will not have the
submitted value and local values cleared.

-Andrew

On 6/28/07, Michael Heinen <mh...@recommind.com> wrote:
>
>
>
>
> Hi,
>
>
>
> I have a serious conversion/validation problem and don't see any
solution.
>
>
>
> My form contains an inputField for dates and a dateTime converter.
>
> If an invalid format is entered then the submitted value is not erased
and
> the page is rerendered with the entered date.
>
> This is working fine so far.
>
>
>
> Now I execute a kind of cancel button via ajax.
>
> I use an a4j:commandButton with ajaxSingle=true and surrounded this
button
> by an a4j:region in order to process no input fields on serverside.
>
> The value that is bound via valueBinding to the inputField is set to
null in
> the invoked ActionListener.
>
> The problem is now that the old invalid date is rerendered on the
page.
>
>
>
> This happens because the submitted value of the inputField is not null
but
> still contains the old invalid date.
>
> Therefore the valueBinding is not evaluated in the getter.
>
>
>
> I can't set the submitted value to null in the converter because
invalid
> values should be rerendered in case that a normal processing button
(not
> cancel button) is clicked.
>
>
>
> Any help is highly appreciated.
>
> Michael


Re: how to reset submitted values caused by validation errors ?

Posted by Andrew Robinson <an...@gmail.com>.
Do you have that control in the reRender of the a4j:commandButton tag?
Perhaps you just aren't re-rendering that component?

Also, is that component in the region? If not, then that component
will not be validated and updated, and thus will not have the
submitted value and local values cleared.

-Andrew

On 6/28/07, Michael Heinen <mh...@recommind.com> wrote:
>
>
>
>
> Hi,
>
>
>
> I have a serious conversion/validation problem and don't see any solution.
>
>
>
> My form contains an inputField for dates and a dateTime converter.
>
> If an invalid format is entered then the submitted value is not erased and
> the page is rerendered with the entered date.
>
> This is working fine so far.
>
>
>
> Now I execute a kind of cancel button via ajax.
>
> I use an a4j:commandButton with ajaxSingle=true and surrounded this button
> by an a4j:region in order to process no input fields on serverside.
>
> The value that is bound via valueBinding to the inputField is set to null in
> the invoked ActionListener.
>
> The problem is now that the old invalid date is rerendered on the page.
>
>
>
> This happens because the submitted value of the inputField is not null but
> still contains the old invalid date.
>
> Therefore the valueBinding is not evaluated in the getter.
>
>
>
> I can't set the submitted value to null in the converter because invalid
> values should be rerendered in case that a normal processing button (not
> cancel button) is clicked.
>
>
>
> Any help is highly appreciated.
>
> Michael