aspose file tools*
The moose likes JSF and the fly likes Two ValueChangeListener don't work on same JSF Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Two ValueChangeListener don Watch "Two ValueChangeListener don New topic
Author

Two ValueChangeListener don't work on same JSF

Rahul Shivsharan
Ranch Hand

Joined: Jun 17, 2009
Posts: 83
I added ValueChangeListener property on radio and dropdownbox, but only that method registered with radio selection is getting called even if i change the dropdown value

this is the code

my NewPage.jsp



My BackingBeans

CustomerPOJO.java



and backing bean NewCustomerPOJO.java



faces-config.xml





whats happening is , once i click on <h:selectOneRadio> selection to "YES", method getIt() of NewCustomerPOJO.java is called,
now the problem is if i change the value of <h:selectOneMenu>, the same getIt() method of NewCustomerPOJO.java is called,

but what i was trying to achive is to invoke is method getIt() of CustomerPOJO.java .

Why is this happening ?

Why valuechangeListener for same method is called.

What i want is for <h:selectOneRadio>, method getIt() of NewCustomerPOJO.java should be called,
and for <h:selectOneMenu>, method getIt() of CustomerPOJO.java should be called

how can i achive that

Can you please tell me were i'm going wrong

Ilari Moilanen
Ranch Hand

Joined: Apr 15, 2008
Posts: 198
I see you send your form with javascript using submit() function. Is this a normal way of doing this or have you decided this approach yourself? If you let JSF handle the form submitting would the code work as you intended?
Rahul Shivsharan
Ranch Hand

Joined: Jun 17, 2009
Posts: 83
But we cant submit the form without javascript "submit()" in onchange.
I thought in JSF either we submit form using <f:commandButton type="submit" ...... /> or if we want to submit form on onchange event, we have to use javascript.

now if we have two valuechangeListener in same form , and if i want to call two different function for each valuechange, what should i do ?

Ilari Moilanen
Ranch Hand

Joined: Apr 15, 2008
Posts: 198
You are right. It was my mistake. But as I understand it you can still use commandButton to send the form and it should still fire the correct method executions in backin bean.

And it should be possible to have more than one valueChangeListeners in one form since it is possible to have more than one valuechangelisteners on a single element.

If you want to check whether your problem lies on the fact that there are two valuechangelisteners then you can remove the other one temporarily to see if after that the other starts working...

But your valuechangelisteners need not be on a same form! Since you submit the form right away after you change either value it means basically that you are interested only in one value change at a time. So you can also use two forms if nothing else helps
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Two ValueChangeListener don't work on same JSF