You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Anthony Hong <an...@gmail.com> on 2006/03/15 02:47:50 UTC

JSF value Change Listener Problem

I encounter a problem with JSF value change listener

I have a selection box
<h:selectOneMenu id="selDebtorType" converter="javax.faces.Integer"
                                           
validator="#{DebtorController.validateDebtorType}"
                                           
valueChangeListener="#{DebtorController.changeDebtorType}"
                                            onchange="this.form.submit();"
                                                    
value="#{DebtorController.currentDebtor.debtorType}">
                                        <f:selectItems
value="#{DebtorController.debtorTypes}"/>
                                    </h:selectOneMenu>

Aslo I have a input box
 <h:inputText id="txtDebtorID" size="20" required="true"
                                                
value="#{DebtorController.currentDebtor.debtorPK.debtorID}"/>

Managed bean: DebtorController is in request scope
In select one box there is value change listener. I want to set debtor
ID in there.

But I tried  in that method:
public void changeDebtorType(ValueChangeEvent event) {
        log.info("Debtor Type has been changed");
        log.info("New value is:" + event.getNewValue());
        log.info("Debtor ID is:" + currentDebtor.getDebtorPK().getDebtorID());
        currentDebtor.getDebtorPK().setDebtorID("abc");
    }

log output for debtor ID is null
and after I setting debtor ID, it doesn't display abc in input box
when page rendered.

But I have put something in debtor ID input text box, after changing
selection box, its value is same as I input. Neither I can get this by
get method nor set it by set method.

Is listener has different life cycle? Say it doesn't have update model phase

--

Anthony Hong

AW: JSF value Change Listener Problem

Posted by Matthias Kahlau <mk...@web.de>.
> Hi again!
> > Hi!
> >
> >> Does that mean all listener happens BEFORE the update model phase?
> >> Include action listener
> >>
> >>
> > No, the action listener fires after the invoke-application phase, which
> > is after the update model.
> >
> All this "after" and "before" ;-)
> In fact the action listener fires "during" the invoke-application phase.
>

If the UICommand component is configured with immediate=true, the
ActionEvent will be processed at the end of the Apply Request Values Phase.

-Matthias

> Havent had some tee today .... thanks Dennis for keeping an eye
> on me :-) !
>
>
> Ciao,
> Mario
>


Re: JSF value Change Listener Problem

Posted by Mario Ivankovits <ma...@ops.co.at>.
Hi again!
> Hi!
>   
>> Does that mean all listener happens BEFORE the update model phase?
>> Include action listener
>>   
>>     
> No, the action listener fires after the invoke-application phase, which
> is after the update model.
>   
All this "after" and "before" ;-)
In fact the action listener fires "during" the invoke-application phase.

Havent had some tee today .... thanks Dennis for keeping an eye on me :-) !


Ciao,
Mario


Re: JSF value Change Listener Problem

Posted by Mario Ivankovits <ma...@ops.co.at>.
Hi!
> Does that mean all listener happens BEFORE the update model phase?
> Include action listener
>   
No, the action listener fires after the invoke-application phase, which
is after the update model.

See here for details about the lifecycle:
http://java.sun.com/javaee/5/docs/tutorial/doc/JSFIntro9.html

Ciao,
Mario


Re: JSF value Change Listener Problem

Posted by Anthony Hong <an...@gmail.com>.
Does that mean all listener happens BEFORE the update model phase?
Include action listener

On 3/15/06, Mario Ivankovits <ma...@ops.co.at> wrote:
> Hi Anthony!
> > I encounter a problem with JSF value change listener
> >
> The valueChangeListener stuff happens BEFORE the update model phase.
> So you cant read the updated value from the model, nor you can change it
> (or any other model value) simply by setting it.
>
> Now you have two options:
> *) set the value through a binding of your component
> *) or - even bettery - use the valueChangeNotifier you can find in
> tomahawk-sandbox.
>
> The valueChangeNotifier will delay the delivery of the valueChange event
> to the "after-model-update" phase and so you can work with your model as
> you might expect it :-)
>
> Ciao,
> Mario
>
>


--

Anthony Hong

Re: JSF value Change Listener Problem

Posted by Mario Ivankovits <ma...@ops.co.at>.
Hi Anthony!
> I encounter a problem with JSF value change listener
>   
The valueChangeListener stuff happens BEFORE the update model phase.
So you cant read the updated value from the model, nor you can change it
(or any other model value) simply by setting it.

Now you have two options:
*) set the value through a binding of your component
*) or - even bettery - use the valueChangeNotifier you can find in
tomahawk-sandbox.

The valueChangeNotifier will delay the delivery of the valueChange event
to the "after-model-update" phase and so you can work with your model as
you might expect it :-)

Ciao,
Mario