简体   繁体   中英

JSF selectOneButton with ajax update - setter 2 times invoked

I use Primefaces 3.2 with ApacheMyfaces on WebSphere Application Server 8.

I have a selectOneButton with an ajax update inside. When I switch the button, my setter firsts sets the value (int) to 0 and then to the value which is selected:

<p:selectOneButton value="#{graph.view}" id="view">
    <f:selectItem itemLabel="W" itemValue="1" />
    <f:selectItem itemLabel="M" itemValue="2" />
    <f:selectItem itemLabel="Y" itemValue="3" />
    <p:ajax event="change" update=":optform:datecol"/>
</p:selectOneButton>

datecol is another selectComponent inside my form (optform).

Why does JSF first set the value to 0 and then to eg 2?

SOLUTION It is a PrimeFaces selectOneButton Bug. See My question here .

Best Regards Veote

Likely what you are seeing is that the managed bean graph is being instantiated early in the JSF lifecycle, and only later in the APPLY_REQUEST_VALUES phase is the appropriate value being set for the managed property view . The managed bean regardless of scope, will be reinstantiated after each request due to the inherently stateless nature of the web.

For more information, BalusC has a great article on debugging the JSF Lifecycle with a step-by-step walkthrough on how to implement a custom PhaseListener that will help you understand and debug behavior like this in your application.

http://balusc.blogspot.com/2006/09/debug-jsf-lifecycle.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM