-
1. Re: Seam newbie: drop down list value does not persist
dzakharov.dmitri.zakharov.gmail.com Apr 30, 2009 3:13 PM (in response to dzakharov.dmitri.zakharov.gmail.com)Sorry, did not finish my question in the previous post. Here it goes.
Next thing, I've made the following changes in my Claim.java class (similar to Round.java):
... import com.fedextnc.domain.credits.model.enums.Province; ... @Entity @Table(name = "CLAIM") public class Claim implements java.io.Serializable { ... private Province importerProvince; ... @Enumerated(EnumType.STRING) @NotNull public Province getImporterProvince() { return this.importerProvince; } public void setImporterProvince(Province importerProvince) { this.importerProvince = importerProvince; } ...
In my ClaimHome.java (similar to RoundHome.java) I added the following code:
... @Factory(value = "provinceList", scope = ScopeType.CONVERSATION) public Province[] getProvinceList() { return Province.values(); } ...
In my ClaimEdit.xhtml (similar to RoundEdit.xhtml) I added the following code:
... <s:decorate id="importerProvinceField" template="layout/edit.xhtml"> <ui:define name="label">#{messages['claim.importerProvince']}</ui:define> <h:selectOneMenu id="importerProvince" value="#{claimHome.instance.importerProvince}" required="true"> <s:selectItems var="_importerProvince" value="#{provinceList}" label="#{_importerProvince.label}" noSelectionLabel="-- Select --"/> <s:convertEnum/> </h:selectOneMenu> </s:decorate> ...
This perfectly generates the select HTML drop down list as expected on
Claim Add
form. The HTML source on the generated pages looks like this:...<select id="claim:importerProvinceField:importerProvince" name="claim:importerProvinceField:importerProvince" size="1"> <option value="org.jboss.seam.ui.NoSelectionConverter.noSelectionValue" selected="selected">-- Select --</option> <option value="AB">AB - Alberta</option> <option value="BC">BC - British Columbia</option> <option value="MB">MB - Manitoba</option> <option value="NB">NB - New Brunswick</option> <option value="NF">NF - Newfoundland and Labrador</option> <option value="NS">NS - Nova Scotia</option> <option value="NT">NT - Northwest Territories</option> <option value="NU">NU - Nunavut</option> <option value="ON">ON - Ontario</option> <option value="PE">PE - Prince Edward Island</option> <option value="QC">QC - Quebec</option> <option value="SK">SK - Saskatchewan</option> <option value="YK">YK - Yukon Territory</option> </select>...
But when I fill up and
Claim Add
form and clickSave
button I get the following exception:Exception during request processing: Caused by javax.servlet.ServletException with message: "#{claimHome.persist}: javax.persistence.PersistenceException: org.hibernate.exception.ConstraintViolationException: could not insert: [com.fedextnc.domain.credits.model.Claim]"
It seams that Hibernate doesn't know how to persist Province enum value. Am I missing something here?
Any leads and suggestion are appreciated.
-
2. Re: Seam newbie: drop down list value does not persist
dzakharov.dmitri.zakharov.gmail.com Apr 30, 2009 4:44 PM (in response to dzakharov.dmitri.zakharov.gmail.com)OK, here's what solved my problem. I returned persistence @Column annotation in the Claim.java, which was initially there after 'seam generate', as follows:
@Column(name = "IMPORTER_PROVINCE", nullable = false, length = 2) @Enumerated(EnumType.STRING) @NotNull public Province getImporterProvince() { return this.importerProvince; }
I am not sure how is it handled in open18 (ch13 - Seam in Action Book) for Weather in Round.java, because there is no @Column anotation there:
@Enumerated(EnumType.STRING) @NotNull public Weather getWeather() { return this.weather; }
And I did not find any other indications in theopen18
(ch13) project sample code. There must be some other trick I am not aware yet about.Any comments are appreciated.