I have a changeValuelistener associated with a dropdown item. The problem is when I do a refresh its changing the value of dropdown item to the old value. But the user tried to change it. In order to show the latest selected value to the user, I am calling a setter on the dropdown item field in the backing bean.
Here is the code snippet:
public void refresh() {
FacesContext context = FacesContext.getCurrentInstance();
Application application = context.getApplication();
ViewHandler viewHandler = application.getViewHandler();
UIViewRoot viewRoot = viewHandler.createView(context, context.getViewRoot().getViewId());
context.setViewRoot(viewRoot);
}
public void statusChanged(ValueChangeEvent event) throws SQLException, Exception{
System.out.println("In the status changed value change listener");
FacesContext context = FacesContext.getCurrentInstance();
String prevCategorySelected = (String)event.getOldValue();
String newCategorySelected = (String)event.getNewValue();
if(!newCategorySelected.equalsIgnoreCase(prevCategorySelected)){
// Value changed. Change the drop down values.
System.out.println("The values are: "+prevCategorySelected+" - "+newCategorySelected);
if(newCategorySelected.equals("Other")){
otherStatusSelected = true;
}
else{
otherStatusSelected = false;
}
refresh();
status = newCategorySelected;
context.renderResponse();
}
}
Also please note that I moved renderResponse call out of the refresh method. We want to set the dropdown to the latest value just before transferring the control to the page. Hope that makes sense.
Thanks,
Hemanth
Jeff Bischoff <[EMAIL PROTECTED]> wrote:
Meghana,
Can you go into a little more detail about what you were trying to do,
how it didn't work, and how you solved it? If it is something that
others may run into, then we should update the wiki page to include it. :)
Regards,
Jeff Bischoff
Kenneth L Kurz & Assoc, Inc.
Meghana wrote:
> The link to ClearInputComponents works like a charm. Just one
> modification though. It was resetting the changed field value to the old
> value. So I had to do call its setter from the change value method
> before calling renderResponse().
>
> Hope it helps,
> -M
>
> */Jeff Bischoff <[EMAIL PROTECTED]>/* wrote:
>
> I had a similar problem in the last few days, and someone pointed me to
> this wiki page (which has some alternative solutions compared to the
> link you posted) [1]
>
> As for why...?
>
> [1] http://wiki.apache.org/myfaces/ClearInputComponents
>
> David Boyd wrote:
> > :) I know how the component works assuming he just queues the
> > valueChangedEvent
> >
> > I have blogged alternate solutions as well
> >
> >
> http://java-server-faces.blogspot.com/2006/04/valuechangelisteners-what-
> > you-need-to.html
> >
> > but what I want to know is why?
> >
> > Why does this happen is it a bug? An error in the specification etc?
> >
> > Why does it update for output components and not for input
> components?
> > :)
> >
> >
> >
> >
> >
> >
> > -----Original Message-----
> > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
> Behalf Of
> > Matthias Wessendorf
> > Sent: Wednesday, June 14, 2006 3:19 PM
> > To: MyFaces Discussion
> > Subject: [SPAM] Re: Re: inputText not updating from
> valueChangedListener
> >
> b=uiHnFQ/OI6ffgtiEOG3tJasR/b3KIloGE0HVZIA/gXjDXV5uj+brPkcfAA1+oua/vOI4od
> >
> r6PVJv/WBc9KI6BmuIpaX89n48F32n/eWZylcJ6jCZ3joEMg1XLwoFt0CH5NV3gbN2tbhjly
> > fvLRq38xG16WMYpPTuTxQSvd/eCkE= b=e8e1XF
> >
> > that guy deliveres the event later. (custom event)
> >
> > Regards,
> > Matthias
> >
> > On 6/13/06, David Boyd wrote:
> >
> >>But then you have the problem where the setter methods are called
> >
> > after
> >
> >>valueChanged code
> >>
> >>i.e
> >>
> >>Any variables in your beans you change in your valueChanged methods
> >
> > will
> >
> >>be overwritten by your setter methods
> >>
> >>
> >>This is a common problem
> >>
> >>Just check out
> >>
> >>http://www.irian.at/myfaces-sandbox/valueChangeNotifier.jsf
> >>
> >>There is even a component to overcome the deficiencies in value
> >
> > Changed
> >
> >>methods
> >>
> >>I am more curious to know why this happens? I have a found solutions
> >
> > to
> >
> >>fix this problem e.g sandbox valueChangeNoifier
> >>
> >>
> >>
> >>
> >>
> >>-----Original Message-----
> >>From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf
> >
> > Of
> >
> >>Matthias Wessendorf
> >>Sent: Wednesday, June 14, 2006 2:50 PM
> >>To: MyFaces Discussion
> >>Subject: [SPAM] Re: inputText not updating from valueChangedListener
> >>
> >
> >
> b=uiHnFQ/OI6ffgtiEOG3tJasR/b3KIloGE0HVZIA/gXjDXV5uj+brPkcfAA1+oua/vOI4od
> >
> >
> r6PVJv/WBc9KI6BmuIpaX89n48F32n/eWZylcJ6jCZ3joEMg1XLwoFt0CH5NV3gbN2tbhjly
> >
> >>fvLRq38xG16WMYpPTuTxQSvd/eCkE=
> >>
> >>have you tried without responsecomplete() ?
> >>
> >>On 6/13/06, David Boyd wrote:
> >>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>Hey all,
> >>>
> >>>
> >>>
> >>>I know this problem most likely would have been addressed before but
> >>
> >>was
> >>
> >>>just wondering if there has been any solution for it?
> >>>
> >>>
> >>>
> >>>Say you had
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>> valueChangeListener="#{bean.changedMethod}">
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>and you have the value change method
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>private userName;
> >>>
> >>>//getters and setters for userName
> >>>
> >>>
> >>>
> >>>public void changedMethod(ValueChangeEvent event)
> >>>
> >>> {
> >>>
> >>> userName = "someValue";
> >>>
> >>> FacesContext.getCurrentInstance().renderResponse();
> >>>
> >>> }
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>Just wondering why does the outputText update but the inputText does
> >>
> >>not?
> >>
> >>>i.e why does the outputText display "someValue" and the inputText is
> >>
> >>still
> >>
> >>>empty?
> >>>
> >>>
> >>>
> >>>I know if you bind the inputText and call the setSubmittedValue()
> >
> > you
> >
> >>can
> >>
> >>>update the inputText
> >>>
> >>>
> >>>
> >>>Just wondering if I can get an explanation of why this problem
> >
> > occurs?
> >
> >>>
> >>>
> >>>
> >>
> >>--
> >>Matthias Wessendorf
> >>Aechterhoek 18
> >>48282 Emsdetten
> >>blog: http://jroller.com/page/mwessendorf
> >>mail: mwessendorf-at-gmail-dot-com
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >
> >
> >
>
>
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
>
[EMAIL PROTECTED]>
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

