As I am still new to Seam (read the book twice, looked at a lot of the docs and examples), I decided to build an application to get my feet wet. The application is based on the hotel booking demo, but quite different.
One by one the problems have yielded, sometimes not without spirited resistance.
The hotels in my application are in different countries. There is a Country persistence object which is merely the String country name and an Integer primary key. This populates a select which is used when entering a new hotel. State and City are String members of Hotel.
When a person searches for hotels, I don't want to display countries without hotels in the database. So I get countries selected from Country joined to Hotel on Country. This is no problem. I then use s:selectItems to create the select list. This works well, too. The problem is that the only country in that list (this is right, I have only one hotel entered) is seen as an invalid value. Here is what is printed in the console:
09:57:42,030 INFO [STDOUT] Hibernate: select country0_.ID as ID24_0_, country0_.country as country24_0_ from Country country0_ where country0_.ID=? 09:57:42,530 INFO [lifecycle] WARNING: FacesMessage(s) have been enqueued, but may not have been displayed. SourceId=countries:j_id12:countrySelect[severity=(ERROR 2), summary=(countries:j_id12:countrySelect: Validation Error: Value is not valid), detail=(countries:j_id12:countrySelect: Validation Error: Value is not valid)]
Here is the code of the generated html:
<form id="countries:j_id12" name="countries:j_id12" method="post" action="/bookings/search.seam" enctype="application/x-www-form-urlencoded"> <input type="hidden" name="countries:j_id12" value="countries:j_id12" /> <select id="countries:j_id12:countrySelect" name="countries:j_id12:countrySelect" size="1"> <option value="org.jboss.seam.ui.NoSelectionConverter.noSelectionValue">Choose...</option> <option value="0">Australia</option> </select>
I know that the value 0 against Australia is only a placeholder. In the database 12 is the actual primary key for Australia. This placeholder, 0, most likely maps somewhere in memory to the right value, which is 12.
When I used the whole list of countries instead of only the countries with hotels in the database, everyting worked fine. In the whole list, Australia is allocated its rightful value of 12.
What could I do? I ditched s:selectItems and replaced it with f:selectItems with which I can control both the label and the value. Now everything works as it is intended to. One first selects a country, then a second select with states in that country with hotels in the database is, displayed. Then one selects a state which causes a select with cities displayed. And so forth.
Is there a way to have more control over the actual values with s:selectItems? Can this(explanation above) be done with s:selectItems?
s:selectItems also produced a select with just the state names as labels, and no values, for the list of String, states. State is not a persistent object, just a member of Hotel. The TreeMap with key and value of 'state' worked fine with f:selectItems.
Is this a scenario where s:selectItems cannot be used? Is the placeholder paradigm an unnecessary complication?
JBoss 4.2.0 and Seam 1.2.1.GA