aspose file tools*
The moose likes JSF and the fly likes MyFaces -  HtmlSelectOneMenu and ValueChangeEvent Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "MyFaces -  HtmlSelectOneMenu and ValueChangeEvent" Watch "MyFaces -  HtmlSelectOneMenu and ValueChangeEvent" New topic
Author

MyFaces - HtmlSelectOneMenu and ValueChangeEvent

Paul Smiley
Ranch Hand

Joined: Jun 02, 2000
Posts: 244
I have a HtmlSelectOne component on a form. My value-changed listener is not working - never enters the method in the backing bean. I have registered the property in the faces-config.xml:

<managed-property>
<property-name>classIfSelItem</property-name>
<null-value/>
</managed-property>

<h:selectOneMenu id="classification" value="#{form.classIfSelItem}" converter="ItemConverter" valueChangeListener="#{form.processValueChange}"
immediate="true" >
<f:selectItems value="#{list.classifList}" />
</h:selectOneMenu>

And my method:

public void processValueChange(ValueChangeEvent event){
HtmlSelectOneMenu selOne = (HtmlSelectOneMenu)event.getComponent();
System.out.println(selOne.getValue());
System.out.println(selOne.getId());
event.getOldValue();
event.getNewValue();
}

This method never gets entered. Any ideas?
Mauro Castaldo
Greenhorn

Joined: Jul 18, 2005
Posts: 22
Originally posted by Paul Smiley:
I have a HtmlSelectOne component on a form. My value-changed listener is not working - never enters the method in the backing bean. I have registered the property in the faces-config.xml:

<managed-property>
<property-name>classIfSelItem</property-name>
<null-value/>
</managed-property>

<h:selectOneMenu id="classification" value="#{form.classIfSelItem}" converter="ItemConverter" valueChangeListener="#{form.processValueChange}"
immediate="true" >
<f:selectItems value="#{list.classifList}" />
</h:selectOneMenu>

And my method:

public void processValueChange(ValueChangeEvent event){
HtmlSelectOneMenu selOne = (HtmlSelectOneMenu)event.getComponent();
System.out.println(selOne.getValue());
System.out.println(selOne.getId());
event.getOldValue();
event.getNewValue();
}

This method never gets entered. Any ideas?


Did you post the form (with a h:commandButton/h:commandLink or javascript)?
if so, did you use a h:messages tag to show eventuals conversion or validation errors?

Mauro.
Paul Smiley
Ranch Hand

Joined: Jun 02, 2000
Posts: 244
Thanks for the reply, Mauro. Yes, this issue is related to the other post you replied to. Same problem, 2 different parts.

Yes, I put this in a form, but did not do the submission - isn't event handling supposed to occur right away, and not at form submission? I set immediate="true" on the component.

But yes, when I do a submit, I do get validation errors. I'm not at work right now, but I believe it has to do with conversion - although the data element and the list contain the same type of object. I've been searching the web for some time to find more details on events in JSF, but can't find much about this.....

Thanks!

Paul
Paul Smiley
Ranch Hand

Joined: Jun 02, 2000
Posts: 244
"... Error during model data update." is the validation error when I submit the form.
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Originally posted by Paul Smiley:
"... Error during model data update." is the validation error when I submit the form.


My guess. Your exception stack trace would be something like IllegalArgumentException in selectItemsIterator().
??
Mauro Castaldo
Greenhorn

Joined: Jul 18, 2005
Posts: 22
Can you show all your code (form bean and list bean)?
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Originally posted by Mauro Castaldo:
Can you show all your code (form bean and list bean)?


Surely, I am here to help you out mate, if I can. But for code, I'm sorry to say its proprietry.

BTW, you didn't respond to my question. It might be helpful for me to tell you the real reason or solve your problem.
Mauro Castaldo
Greenhorn

Joined: Jul 18, 2005
Posts: 22
Originally posted by Adeel Ansari:


Surely, I am here to help you out mate, if I can. But for code, I'm sorry to say its proprietry.

BTW, you didn't respond to my question. It might be helpful for me to tell you the real reason or solve your problem.


Sorry Andeel,
I'm Mauro and I'm asking code to Paul!
Paul Smiley
Ranch Hand

Joined: Jun 02, 2000
Posts: 244
Mauro,
Thank you for your time. It was a stupid mistake (aren't they almost always? ) I have a custom component that I used for 2 different types of data and used the same converter - therefore my conversion back to object failed. I wrote another converter and all is fine. I'll probably clean them up at some point to get the source and then do a runtime comparision to find out what the data is and reuse the converter for type, but a second converter gets me over the hump for right now. I did write it down for my next refactor...

Ankur Thakur
Greenhorn

Joined: Nov 12, 2009
Posts: 3
two ways we have here
One is here described below and another one with hep of renedered

<h:selectOneMenu id="catagoreyEmail"
value="#{managedEmailRespondent.selectCatagoreyEmail}" valueChangeListener="#{managedEmailRespondent.selectCatagoreyEmailValue}" [color=red]onchange="this.form.submit();"[/color] :D >
<f:selectItems id="selectionCatagoreyEmailBody"
value="#{managedEmailRespondent.selectSelectionCatagoreyEmail}" />
</h:selectOneMenu>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: MyFaces - HtmlSelectOneMenu and ValueChangeEvent