Did you ever find a solution to this? I'm running into pretty much precisely the same problem. I get it running so far that the drop down is filled but it doesn't select the right element and it always results in Seam thinking that (null) was selected.
The only reason my app isn't crashing is that I prevent null from being set on the specific @NotNull item.
my components.xml
<?xml version="1.0" encoding="UTF-8"?>
<components xmlns="http://jboss.com/products/seam/components"
xmlns:core="http://jboss.com/products/seam/core"
xmlns:persistence="http://jboss.com/products/seam/persistence"
xmlns:drools="http://jboss.com/products/seam/drools"
xmlns:bpm="http://jboss.com/products/seam/bpm"
xmlns:security="http://jboss.com/products/seam/security"
xmlns:mail="http://jboss.com/products/seam/mail"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ui="http://jboss.com/products/seam/ui"
xmlns:framework="http://jboss.com/products/seam/framework"
xsi:schemaLocation=
"http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.1.xsd
http://jboss.com/products/seam/persistence http://jboss.com/products/seam/persistence-2.1.xsd
http://jboss.com/products/seam/drools http://jboss.com/products/seam/drools-2.1.xsd
http://jboss.com/products/seam/bpm http://jboss.com/products/seam/bpm-2.1.xsd
http://jboss.com/products/seam/security http://jboss.com/products/seam/security-2.1.xsd
http://jboss.com/products/seam/mail http://jboss.com/products/seam/mail-2.1.xsd
http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.1.xsd">
<core:init debug="@debug@" jndi-pattern="@jndiPattern@"/>
<core:manager concurrent-request-timeout="500"
conversation-timeout="120000"
conversation-id-parameter="cid"
parent-conversation-id-parameter="pid"/>
<persistence:managed-persistence-context name="entityManager"
auto-create="true"
persistence-unit-jndi-name="java:/HermesEntityManagerFactory"/>
<security:rule-based-permission-resolver security-rules="#{securityRules}"/>
<!-- security:identity authenticate-method="#{authenticator.authenticate}" remember-me="true" /-->
<!-- security:identity authenticate-method="#{identity.login}" remember-me="true" / -->
<security:identity-manager identity-store="#{jpaIdentityStore}" />
<security:jpa-identity-store name="jpaIdentityStore"
user-class="org.nycentral.hermes.entity.User"
role-class="org.nycentral.hermes.entity.Role" />
<security:jpa-permission-store
user-permission-class="org.nycentral.hermes.entity.UserPermission" />
<drools:rule-base name="securityRules">
<drools:rule-files>
<value>/security.drl</value>
</drools:rule-files>
</drools:rule-base>
<event type="org.jboss.seam.security.notLoggedIn">
<action execute="#{redirect.captureCurrentView}"/>
</event>
<event type="org.jboss.seam.security.loginSuccessful">
<action execute="#{redirect.returnToCapturedView}"/>
</event>
<mail:mail-session host="localhost" port="2525" username="test" password="test" />
<ui:jpa-entity-loader entity-manager="#{entityManager}" />
<framework:entity-query name="allCountries"
ejbql="select country from Country country"
order="country.name" />
<!-- For use with jBPM pageflow or process management -->
<!--
<bpm:jbpm>
<bpm:process-definitions></bpm:process-definitions>
<bpm:pageflow-definitions></bpm:pageflow-definitions>
</bpm:jbpm>
-->
</components>
The data/entity I want to be rendered in the dropbox:
package org.nycentral.hermes.entity;
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import org.hibernate.validator.Length;
import org.hibernate.validator.NotNull;
@Entity
@Table(name="Countries")
public class Country implements Serializable {
private static final long serialVersionUID = -5515171854078135507L;
//private String id;
private Long id;
private String name;
@Id
@GeneratedValue
public Long getId() {
return this.id;
}
public void setId( Long id ) {
this.id = id;
}
/*@Id
@Length(max=2)
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}*/
@NotNull
@Length(max=64)
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Transient
@Override
public String toString() {
return this.name;
}
@Transient
@Override
public int hashCode() {
// FIXME non-optimal hash-code
return (this.id+this.name).hashCode();
}
@Transient
@Override
public boolean equals(Object o) {
Country c;
if ( !( o instanceof Country )) {
return false;
}
c = (Country) o;
if ( c.getId() == this.getId() ) {
return true;
}
return false;
}
}
I initially had a String as primary key and changed that to Long, just to be sure it's not caused by that. However, that didn't work either.
The xhtml file rendering:
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:s="http://jboss.com/products/seam/taglib"
xmlns:a="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich"
template="companydetail.xhtml">
<ui:define name="details">
<s:decorate id="fieldCompanyName" template="../layout/edit.xhtml">
<ui:define name="label">Name:</ui:define>
<h:inputText id="CompanyName" value="#{company.name}" required="true" />
</s:decorate>
<s:decorate id="fieldCompanyStreet" template="../layout/edit.xhtml">
<ui:define name="label">Street:</ui:define>
<h:inputText id="CompanyStreet" value="#{company.address.street}" required="true" />
</s:decorate>
<s:decorate id="fieldCompanyCity" template="../layout/edit.xhtml">
<ui:define name="label">City:</ui:define>
<h:inputText id="CompanyCity" value="#{company.address.city}" required="true" />
</s:decorate>
<s:decorate id="fieldCompanyZIP" template="../layout/edit.xhtml">
<ui:define name="label">ZIP:</ui:define>
<h:inputText id="CompanyZIP" value="#{company.address.zip}" required="true" />
</s:decorate>
<s:decorate id="fieldCompanyState" template="../layout/edit.xhtml">
<ui:define name="label">State:</ui:define>
<h:inputText id="CompanyState" value="#{company.address.state}" required="true" />
</s:decorate>
<s:decorate id="fieldCompanyCountry" template="../layout/edit.xhtml">
<ui:define name="label">Country:</ui:define>
<h:selectOneMenu id="CompanyCountry" value="#{company.address.country}">
<s:selectItems value="#{allCountries}"
var="choice"
label="#{choice.name}"
hideNoSelectionLabel="true" />
<s:convertEntity />
</h:selectOneMenu>
</s:decorate>
</ui:define>
<ui:define name="actionButtons">
<h:commandButton value="Save Changes" action="#{companyEdit.saveCompany}" />
<h:commandButton value="Cancel" action="#{companyEdit.cancel}" />
</ui:define>
</ui:composition>
It's really weird. I don't understand why it's so damn difficult to render a stupid dropdown box??? I even tried to implement my own converter, that didn't work either:
package org.nycentral.hermes.session.helper;
import java.io.Serializable;
import javax.faces.component.UIComponent;
import javax.persistence.EntityManager;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Transactional;
import org.jboss.seam.annotations.faces.Converter;
import org.jboss.seam.faces.FacesContext;
import org.nycentral.hermes.entity.Country;
@Name("countryConverter")
@Converter(forClass = Country.class)
public class CountryConverter implements Serializable {
private static final long serialVersionUID = 4329423846512375269L;
@In
private EntityManager entityManager;
public Class<?> forClass() {
return Country.class;
}
@Transactional
public Object getAsObject(FacesContext context, UIComponent component,
String value) {
if (value != null) {
try {
return entityManager.find(Country.class, Long.parseLong( value ));
} catch ( NumberFormatException e ) {
return null;
}
}
return null;
}
public String getAsString(FacesContext context, UIComponent component,
Object value) {
if (value instanceof Country) {
Country c = (Country) value;
return c.getId().toString();
} else {
return null;
}
}
}
That thing never gets called. I had a couple of breakpoints set - never was called at all. Does anyone have a clue what could be wrong with this??
any help is really appreciated
chris