You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Remo Liechti <re...@swisslog.com> on 2006/06/01 15:21:29 UTC

JSF Livecycle Problem - Events before setters!

Hi All

THE JSF livecycle is like this
Faces Request -> Restore View -> Apply Request Values (call all the
setters) -> process events -> ...

There are two possible ways how to configure to submit a form: With a
button(and its action) or with the javascript onchange property on any
element. 
But the JSF Livecycles are DIFFERENT!!!

I got a setter and an event called updater. The updater uses the
variable "currentKpiGroup" which is set by the setter.


By button:
==========
<h:selectOneMenu
  id="selectedKpiGroup"
value="#{flowScope.KPIBrowserBean.currentKpiGroup}">
<f:selectItems value="#{flowScope.KPIBrowserBean.kpiGroups}" />
</h:selectOneMenu>

<h:commandButton action="#{flowScope.KPIBrowserBean.kpiGroupChanged}"
value="Change" styleClass="button" />

By onchange-property:
=====================
<h:selectOneMenu
  id="selectedKpiGroup"
value="#{flowScope.KPIBrowserBean.currentKpiGroup}"
  valueChangeListener="#{flowScope.KPIBrowserBean.kpiGroupChanged}"
  onchange="submit()">
<f:selectItems value="#{flowScope.KPIBrowserBean.kpiGroups}" />
</h:selectOneMenu>



So, everything works fine if I use the button to submit the form(console
oputput):

SETTER currentKpiGroup grp: 3
UPDATER(event) currentKpiGroup: 3

The setters are called before the events.




If I use the onchange property, the console output is this:

UPDATER(event) currentKpiGroup: 2
SETTER currentKpiGroup grp: 3

my application performs wrong because of the old
value(currentKpiGroup=2).
The event is process before the new value(currentKpiGroup=3) are set.



Does sombody know anything about this behavior? I need to submit the
form by onchange...

I'm looking forward to your answers!

Thanks,

Remo


Re: JSF Livecycle Problem - Events before setters!

Posted by Ondrej Svetlik <on...@svetlik.info>.
Remo Liechti wrote:
> Hi All
> 
> THE JSF livecycle is like this
> Faces Request -> Restore View -> Apply Request Values (call all the
> setters) -> process events -> ...
> 
> There are two possible ways how to configure to submit a form: With a
> button(and its action) or with the javascript onchange property on any
> element. 
> But the JSF Livecycles are DIFFERENT!!!
> 
> I got a setter and an event called updater. The updater uses the
> variable "currentKpiGroup" which is set by the setter.
> 
> 
> By button:
> ==========
> <h:selectOneMenu
>   id="selectedKpiGroup"
> value="#{flowScope.KPIBrowserBean.currentKpiGroup}">
> <f:selectItems value="#{flowScope.KPIBrowserBean.kpiGroups}" />
> </h:selectOneMenu>
> 
> <h:commandButton action="#{flowScope.KPIBrowserBean.kpiGroupChanged}"
> value="Change" styleClass="button" />
> 
> By onchange-property:
> =====================
> <h:selectOneMenu
>   id="selectedKpiGroup"
> value="#{flowScope.KPIBrowserBean.currentKpiGroup}"
>   valueChangeListener="#{flowScope.KPIBrowserBean.kpiGroupChanged}"
>   onchange="submit()">
> <f:selectItems value="#{flowScope.KPIBrowserBean.kpiGroups}" />
> </h:selectOneMenu>
> 
> 
> 
> So, everything works fine if I use the button to submit the form(console
> oputput):
> 
> SETTER currentKpiGroup grp: 3
> UPDATER(event) currentKpiGroup: 3
> 
> The setters are called before the events.
> 
> 
> 
> 
> If I use the onchange property, the console output is this:
> 
> UPDATER(event) currentKpiGroup: 2
> SETTER currentKpiGroup grp: 3
> 
> my application performs wrong because of the old
> value(currentKpiGroup=2).
> The event is process before the new value(currentKpiGroup=3) are set.
> 
> 
> 
> Does sombody know anything about this behavior? I need to submit the
> form by onchange...
> 
> I'm looking forward to your answers!
> 
> Thanks,
> 
> Remo
> 

Hello Remo,

again, I'd suggest using immediate like this:


<t:selectOneMenu
   id="selectedKpiGroup"
   immediate="true"
   value="#{flowScope.KPIBrowserBean.currentKpiGroup}"
   valueChangeListener="#{flowScope.KPIBrowserBean.kpiGroupChanged}"
   onchange="submit()">
   <f:selectItems value="#{flowScope.KPIBrowserBean.kpiGroups}" />
</t:selectOneMenu>

This is what the documentation says about immediate:

... cite from http://myfaces.apache.org/tomahawk/tlddoc/index.html
A boolean value that identifies the phase during which value change 
events should fire. During normal event processing, value change events 
are fired during the "invoke application" phase of request processing. 
If this attribute is set to "true", these methods are fired instead at 
the end of the "apply request values" phase.
... cite from http://myfaces.apache.org/tomahawk/tlddoc/index.html

Best regards

Ondrej Svetlik

Re: JSF Livecycle Problem - Events before setters!

Posted by Val Blant <va...@yahoo.ca>.
Unfortunately, valueChangeNotifier doesn't work properly in dataTables. I
described the problem here:

http://www.nabble.com/s%3AvalueChangeNotifier+and+dataTables-t1678106.html#a4550580 
--
View this message in context: http://www.nabble.com/JSF+Livecycle+Problem+-+Events+before+setters%21-t1716763.html#a4664771
Sent from the MyFaces - Users forum at Nabble.com.


Re: JSF Livecycle Problem - Events before setters!

Posted by Cagatay Civici <ca...@gmail.com>.
Hi,

Setters are called at update model actually, not at apply request phase.

I don't see anything wrong about the console print out because value change
events are not like button action events. They are called after process
validations(before setter) phase whereas button action events are called at
invoke application(after setter). They are different.

Cagatay,