This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes JSF and the fly likes A Problem with events Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "A Problem with events" Watch "A Problem with events" New topic
Author

A Problem with events

tazkirah laskdjf
Greenhorn

Joined: Sep 21, 2008
Posts: 3
Hi, first of all, sorry for my poor english

My problem is:
Have a page jsf with 2 SelectOneMenu and 1 commandButton like this
<h:selectOneMenu binding="#{nuevoExpediente.cbObra}" valueChangeListener="# {bean.cbObra_OnChange}" onchange="submit()" >
<f:selectItem itemLabel="Nuevo" itemValue="-1" itemDescription="Introducir nuevo poseedor" />
<f:selectItems binding="#{bean.listobras}" />
</h:selectOneMenu>

<h:selectOneMenu binding="#{bean.cbCliente}" valueChangeListener="# {bean.cbCliente_OnChange}" onchange="submit()" >
<f:selectItem itemLabel="Nuevo" itemValue="-1" itemDescription="Introducir nuevo poseedor" />
<f:selectItems binding="#{bean.listclientes}" />
</h:selectOneMenu>

<h:commandButton id="cmdInsertar" value="Aceptar" action="#{bean.cmdInsertar_OnClick}" />

Cool, now, when the pages FIRST time that i select one item on selectonemenu or click button, page fires ALL events. I think this it because when initialize SelectOneMenu with value="#....", an one event onChange wait on a queue and when any object of form make submit() all event on a queue are throws.
this is:
1� time when page load
- click on a button
- cbObra_OnChange fire ( on queue for give values? )
- cbCliente_OnChange fire ( on queue for give values? )
- cmbInsertar_OnClick fire ( yes, im clicked )


how i can do this? i want that when click on the button first time, only event of button fires.

thanks for all
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Crossposted at Sun forum: http://forums.sun.com/thread.jspa?messageID=10432472#10432472

Please be forthright when crossposting: http://faq.javaranch.com/java/BeForthrightWhenCrossPostingToOtherSites
[ September 21, 2008: Message edited by: Bauke Scholtz ]
tazkirah laskdjf
Greenhorn

Joined: Sep 21, 2008
Posts: 3
try to create a project with this config and try
because the selectonemenu allready have a items on JSF tag, and when load items, modify initials and fires
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
I already answered this over there at sun.com. The valueChangeListener will be invoked if the new value differs from the old value.
tazkirah laskdjf
Greenhorn

Joined: Sep 21, 2008
Posts: 3
ok men, i read all your posts but, try on a new project, because not work...
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
It doesn't matter if you use a new or old project.

All what matters is that the valueChangeListener will be invoked if the new value differs from the old value. If you think logically, then you should realize that the solution is to make sure that the h:selectOneMenu value is the same as the default value of the f:selectItems. You can prepare that in the constructor of the backing bean or maybe during the filling of the list behind f:selectItems or so.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: A Problem with events