selectOneListbox - strange problem - selectitems

Hello,

I have been playing with such a thing in selectOneListbox:

I encouter problem if I select an option in a selectOneListbox. In such a case, the page (bean) runs without any error or exception but it is terminated somewhere quite early (before the getSelectedItem() method or button_action() method come to processing) - and the page is displayed as if everything was ok...

If I fill in the form and skip the listbox (do not select anything), everything goes well!

Here is the jsp code:

<h:selectOneListbox id="name" size="7" styleClass="listbox" value="#{insert.selectedTaxon}" title="select one option">

<f:selectItems value="#{insert.taxons}"/>

</h:selectOneListbox>

[891 byte] By [honzaa] at [2007-11-27 4:55:34]
# 1

The problem should not be with the selectItems because the items are displayed allright.

The problem might be in the setSelectedTaxon() setter because it is not called:

public void setSelectedTaxon(String taxon)

{

selectedTaxon = taxon;

}

But this seems to be allright too...

honzaa at 2007-7-12 10:10:32 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
The same behavior in the case of static items in the listbox.
honzaa at 2007-7-12 10:10:32 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
Most likely there's a conversion error occurred. Add <h:messages /> to the form and see if you retrieve a validation or conversion error.
BalusCa at 2007-7-12 10:10:32 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
It surely has something to do with the setter method. I removed the "value" attribute of the listbox and the works fine (except the listbox of course :( ).
honzaa at 2007-7-12 10:10:33 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
Thank you very much. You are right: "Validation error" but I do not understand it as I have not been applying validation at the time being.
honzaa at 2007-7-12 10:10:33 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6
At least you need to make sure that the object types of the selectItems and selectedItem fits in each other.
BalusCa at 2007-7-12 10:10:33 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7

Ok, now it seems to be working!

The problem was my setter/getter method was for the Type of Integer (I used a piece of code from RadioButtonList which I had already got work and it uses Integer).

Shame as I carefully read this http://java.sun.com/javaee/javaserverfaces/1.1/docs/tlddocs/h/selectOneListbox.html several times - mainly the paragraph related to the "value" attribute. It must be STRING.

But what is strange is that JSF accepted the Integer whereas e.g. SelectItem not (threw an error page). Perhaps due to toString() method which is quite "straightforward" in the case of Integer.

Thank you,

Jan

honzaa at 2007-7-12 10:10:33 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 8

Correction - message for the next generations :-):

Actually, the problem was in the SelectItem list! As I wrote in my previous post, the SelectOneListbox requires an object of type String as a value of the value attribute.

Therefore your SelectItem list (taxons in my case) must be of type [String, String].

I had [Integer, String] which was incorrect but no exception was thrown. Just while (automatic) validation.

honzaa at 2007-7-12 10:10:33 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...