JSF value change Simple problem

I am having a small difficulty understanding which approach should be used to initialize data in JSF.

Take this simple example:

There is a drop down with 2 items: 1, 2

<h:selectOneMenu value="#{bean.value}"

valueChangeListener="#{bean.change}" onchange="submit()">

<f:selectItem itemLabel="1" itemValue="1"/>

<f:selectItem itemLabel="2" itemValue="1"/>

</h:selectOneMenu>

Now, when page loads, it really shows the second value of the drop down selected.

But, when I simply add a "valueChangeListener" method, I can see that there is a problem:

publicvoid change(ValueChangeEvent event)

{

System.out.println("I was here");

}

Whenever switching from value: 1 to: value: 2, the event is not activate. Since I was setting each time the constructor is built, the value "manually".

The problem gets much deeper when, for exmaple, I would like to show a table that changes according to several filters. Initially the data is loaded on the constructor. But when filter changes, the data should be reloaded. So I load it twice: Once in the constructor, then I have to rebuild data in the event itself.

Am I missing here something ? Or the JSF mechanism is missing somthing ... ;-)

[1623 byte] By [guy.bashana] at [2007-10-2 8:55:45]
# 1

It's beacuse its ValueChangeListener :) no a "LabelChangeListener".

Value for those two items should be different :)

Itemlabel is what you see in combobox, and itemValue is real value for item.

If you change your code to :

<f:selectItem itemLabel="1" itemValue="1"/>

<f:selectItem itemLabel="2" itemValue="2"/>

it will work :)

Martin

mandrzeja at 2007-7-16 22:59:49 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

Sorry ...

In my code it shows this:

<f:selectItem itemLabel="1" itemValue="1"/>

<f:selectItem itemLabel="2" itemValue="2"/>

I just altered it a little and forgot to make the proper changes ... ;-)

guy.bashana at 2007-7-16 22:59:49 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
How many form tags you have in your JSF page?
SYESa at 2007-7-16 22:59:49 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
One
guy.bashana at 2007-7-16 22:59:49 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...