File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSF and the fly likes valueChangeListener Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » JSF
Bookmark "valueChangeListener" Watch "valueChangeListener" New topic
Author

valueChangeListener

James Ellis
Ranch Hand

Joined: Oct 14, 2004
Posts: 205
If I want to bind a valueChangeListener to a textbox, do I have to bind this to a class that implements ValueChangeListener (as in the example in http://java.sun.com/j2ee/1.4/docs/tutorial/doc/JSFPage8.html) or can I bind it to a method on a managed bean (one that does not implement ValueChangeListener)?

Further, does the syntax for valueChange listener include the pound sign and brackets as in



or is the syntax



without the pound sign and brackets?

Thanks,
Jim
Priti Shah
Ranch Hand

Joined: May 10, 2005
Posts: 43
I am also new to JSF but I have done something like this before.

<h:selectBooleanCheckbox ... valueChangeListener="#{bean.someValueChanged}" />

hope this helps.
James Ellis
Ranch Hand

Joined: Oct 14, 2004
Posts: 205
So does the bean class (the class to which the method someValueChanged is a member of) have to implement ValueChangeListener? I've seen some examples of where it does...others where it doesn't. I'm not sure if it varies between versions (1.0 versus 1.1).
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Originally posted by James Ellis:
So does the bean class (the class to which the method someValueChanged is a member of) have to implement ValueChangeListener? I've seen some examples of where it does...others where it doesn't. I'm not sure if it varies between versions (1.0 versus 1.1).


No, you can either create a class that extends ValueChangeListener and implement your methods there or you can use the backing-bean with a valueChange method and use that.



GenRocket - Experts at Building Test Data
Matt Lehning
Greenhorn

Joined: Sep 02, 2005
Posts: 2
This is right down the same alley that I am perplexed over.

I have a page with 3 combo-boxes (selectOneMenu) on it. They are interrelated. By that I mean initially, box #1 is initialized and enabled while boxes #2 & 3 are disabled. There also is a submit button labeled "Go" which has a doGoBtnAction method.

Selecting a value in box #1 submits the page's form (via JavaScript onchange) which then triggers the handleBox1ValueChange method to be executed. In that method, I want to issue a JDBC query using the value in box #1 to get list items for box #2.

IF the list for box #2 comes back with only one item, I want to go ahead and issue a JDBC query for box #3 using the values from boxes #1 and 2. Otherwise, box #3 remains disabled.

Boxes #2 and 3 each have a JavaScript onchange to submit the form and each have a handleBoxXValueChange method.

Assume box #2 only had one list item so now box #3 is populated and enabled. The goofy thing I'm seeing is that if I now make a selection in box #3, when the form gets submitted, JSF executes the handleBox2ValueChange method instead of the handleBox3ValueChange.

The same would occur if I clicked the "Go" button to submit the form. Initially, the handleBox2ValueChange method would execute, THEN the doGoBtnAction method.

What makes it even weirder (to me, anyway) is the values that are stored in the valueChangeEvent newValue and oldValue properties. They are NOT necessarily the previous and current values in the combo-box!! Sometimes they're a value or two behind (i.e. the 'oldValue' is two selections ago, the 'newValue' is the previous selection, not what's currently in the combo-box).

So.......that's a lot of detail and background to get to my question, which is this:

Does anyone know where JSF stores the 'oldValue' or what it uses as the oldValue to compare with the 'newValue'? And where is that newValue obtained from since like I said, it's not always what I have currently selected.

All the combo-boxes are mapped to a property in a bean with a scope of session. The backing bean used on my page retrieves those values in the beginning.

I'm really confused and I hope this explanation makes some sense.

Thanks for your help,
Matt
[ September 06, 2005: Message edited by: Matt Lehning ]
 
GeeCON Prague 2014
 
subject: valueChangeListener