[JBoss Seam] - Can s:selectItems work in this scenario?
by chrismalan
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
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4071792#4071792
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4071792
18Â years, 8Â months
[JBoss Seam] - Re: convertEntity with non-Id key?
by starascendant
"pete.muir(a)jboss.org" wrote : I don't understand how this relates to legacy databases. The property you mark @Id is always the ID. Sure, the ID can have no meaning, but unless you want to do stuff using the dom, it doesn't really matter.
Because a database may have a relationship (enforced or not) to something other than the Id. I've run across more than one legacy app that has an autonumbering Id on a table, but stores the name or something else in a related table rather than the Id value. While it's not good practice it's not something you always have the option to remediate, which means that being able to accomodate it ends up being useful.
Perhaps the entityConverter itself isn't an appropriate place for this, but it really does need to be accomodated somehow.
It looks like I'm not the only one thinking this either. In doing some further searches, I found another JIRA that I think relates to the issue. It seems that one of your fellow developers is attempting to address this in http://jira.jboss.com/jira/browse/JBSEAM-1589.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4071789#4071789
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4071789
18Â years, 8Â months