[jboss-user] [JBoss Seam] - <h:selectOneMenu> with <s:convertEntity/> and <s:selectItems

davidfed do-not-reply at jboss.com
Wed Jun 20 18:45:51 EDT 2007


I'm trying to present a drop-down list for users to select from which is built from a list queried from the database. I will attach the selected entity to another entity.

The problem is that I get value="0" for every  in the list and I get this exception (full dump at bottom) when submitting the form with a selected value:

javax.servlet.ServletException: Provided id of the wrong type. Expected: class java.lang.Long, got class java.lang.String

So I put a breakpoint in EntityConverter.getAsString and see that whereas the examples have the value parameter set to an object of an actual class (e.g. Continent in seam-ui), I have a Provider_$$_javassist_21 object.  Looking into the object, the handler.target object is the data that I care about.  Yet the getIdFromEntity() call returns null as found directly in the javassist subclass.

Given that all my code is very similar to the example code I don't know where to look from here.  

thanks

Web page:

  | <s:decorate id="recentDecor" template="/WEB-INF/template/edit.txml">
  |   <ui:define name="label">#{messages.referralSpecialistLabelRecent}</ui:define>
  |   <h:selectOneMenu value="#{referralController.recentChoice}">
  |     <s:convertEntity/>
  |     <s:selectItems value="#{recentSpecialists}" var="spec" label="#{spec.lastName}, #{spec.firstName} #{spec.middleInitial}, #{spec.suffixName}" noSelectionLabel="#{messages.referralSpecialistNoRecent}"/>
  |     <a:support event="onchange" action="#{referralController.pickRecentSpecialist}"/>
  |   </h:selectOneMenu>
  | </s:decorate>
  | 

Controller:

  | @DataModel
  | @SuppressWarnings("unused")
  | private List<Provider>			recentSpecialists;
  | 	
  | @Factory("recentSpecialists")
  | @SuppressWarnings("unchecked")
  | public void loadRecentSpecialists()
  | 	{
  | 	recentSpecialists = entityManager.createQuery("select p from Provider p")
  | 							 .setMaxResults(25)
  | 							 .getResultList();
  | 	}
  | 

Entity Definition (getters/setters removed but completely standard):

  | 
  | @Entity
  | public class Provider extends PracticeStaff {
  | 	
  | 	// private fields ******************************
  | 
  | 	// Should never be null.  Cannot create dbms contstraint because superclasses do
  | 	// allow null in this field and we are using single table inheritance.
  | 	@Column(length = 10, unique = true)
  | 	private String individualNpi;
  | 	
  | 	@org.hibernate.annotations.CollectionOfElements
  | 	@JoinTable(name = "provider_specialties")
  | 	@Column(name = "specialty", length = 64)
  | 	@Enumerated(EnumType.STRING)
  | 	private Set<Specialty> specialties = new HashSet<Specialty>();
  | 	
  | 	@org.hibernate.annotations.CollectionOfElements
  | 	@JoinTable(name = "provider_attachRequests")
  | 	@org.hibernate.annotations.MapKey(
  | 			columns = @Column(name = "docType", length = 32))
  | 	@Enumerated(EnumType.STRING)
  | 	@Column(name = "providerNote", length = 255)
  | 	private Map<Document.DocType, String> attachRequests = new HashMap<Document.DocType, String>();
  | 	
  | 	@Column(length = 600)
  | 	private String areasOfInterest;
  | 	
  | 	@Column(length = 128)
  | 	private String picturePath;
  | 	
  | 	@Column(length = 600)
  | 	private String education;
  | 	
  | 	@Column(length = 600)
  | 	private String certification;
  | 	
  | 	// Constructors ******************************
  | 	
  | 	public Provider() {
  | 	}
  | 	
  | 	public Provider(String prefixName, String firstName, String middleName, String lastName, String suffixName,
  | 					Calendar birthDate, Gender gender, String individualNpi) {
  | 		super(prefixName, firstName, middleName, lastName, suffixName,
  | 				birthDate, gender);
  | 		if (individualNpi == null)
  | 			throw new IllegalArgumentException("individualNpi cannot be null");
  | 		setIndividualNpi(individualNpi);
  | 	}
  | 
  |     // Accessors ******************************
  | }
  | 
  | 
  | @Entity
  | public class PracticeStaff extends Person {
  | 
  | 	// private fields ******************************
  | 	
  | 	@ManyToMany(cascade = {CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH})
  | 	@JoinTable(name = "staff_location")
  | 	private Set<Location> locations = new HashSet<Location>();
  | 	
  | 	@ManyToOne(cascade = {CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH},
  | 			fetch = FetchType.LAZY)
  | 	@org.hibernate.annotations.ForeignKey(name = "FK_PRACTICE")  // friendly name
  | 	private Practice practice;
  | 		
  | 	// Constructors ******************************
  | 	
  | 	public PracticeStaff() {
  | 	}
  | 	
  | 	public PracticeStaff(String prefixName, String firstName, String middleName, String lastName, String suffixName,
  | 					Calendar birthDate, Gender gender) {
  | 		super(prefixName, firstName, middleName, lastName, suffixName,
  | 				birthDate, gender);
  | 	}
  | 
  | 	// Accessors ******************************
  | }
  | 
  | 
  | @Entity
  | @org.hibernate.annotations.Entity(dynamicInsert = true, dynamicUpdate = true) // faster updates and inserts
  | @Table(uniqueConstraints = {
  | 		@UniqueConstraint(columnNames = {
  | 				"firstName", "middleName", "lastName", "birthDate", "gender"} )
  | 	}
  | )
  | @Inheritance(strategy = InheritanceType.SINGLE_TABLE)
  | public class Person implements Serializable {
  | 
  | 	// private fields ******************************
  | 
  | 	@Id @GeneratedValue
  | 	private Long id = null;
  | 	
  | 	@SuppressWarnings("unused") // hibernate uses for optimistic locking
  | 	@Version
  | 	private int version = 0;
  | 
  | 	@Column(length = 16)
  | 	private String prefixName;
  | 
  | 	@Column(length = 32, nullable = false)
  | 	private String firstName;
  | 
  | 	@Column(length = 32)
  | 	private String middleName;
  | 
  | 	@Column(length = 32, nullable = false)
  | 	private String lastName;
  | 
  | 	@Column(length = 16)
  | 	private String suffixName;
  | 
  | 	@Temporal(TemporalType.DATE)
  | 	@Column(nullable = false)
  | 	private Calendar birthDate;
  |     
  | 	@Column(nullable = false)
  | 	private Gender gender;
  |     
  | 	@Column(length = 9, unique = true)
  | 	private String ssn;
  | 	
  | 	@Embedded
  | 	private Address homeAddress;
  | 
  | 	@Column(length = 32)
  | 	private String homePhone;
  | 
  | 	@Column(length = 32)
  | 	private String workPhone;
  | 
  | 	@Column(length = 32)
  | 	private String cellPhone;
  | 
  | 	@Column(length = 64)
  | 	private String altEmail;  // additional email used to contact this person.  primary email is account.loginName 
  | 
  | 	@Temporal(TemporalType.TIMESTAMP)
  | 	private Date demographicsVerified;  // TODO - last time user verified their demographic info
  |     
  | 	@Column(length = 32)
  | 	private String plan1Id;
  | 
  | 	@Column(length = 32)
  | 	private String plan1Group;
  | 	
  | 	@ManyToOne(cascade = {CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH},
  | 			fetch = FetchType.LAZY)
  | 	@org.hibernate.annotations.ForeignKey(name = "FK_PLAN1_SUBSCRIBER")  // friendly name
  | 	private Person plan1Subscriber;  // if null, the patient is the subscriber
  | 
  | 	@Column(length = 32)
  | 	private String plan2Id;
  | 
  | 	@Column(length = 32)
  | 	private String plan2Group;
  | 	
  | 	@ManyToOne(cascade = {CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH},
  | 			fetch = FetchType.LAZY)
  | 	@org.hibernate.annotations.ForeignKey(name = "FK_PLAN2_SUBSCRIBER")  // friendly name
  | 	private Person plan2Subscriber;  // if null, the patient is the subscriber
  | 
  | 	@OneToMany(mappedBy = "person",
  | 			cascade = CascadeType.ALL)
  | 	@org.hibernate.annotations.Cascade(
  | 			org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
  | 	private Set<Account> accounts = new HashSet<Account>();
  | 
  | 	// Constructors ******************************
  | 	
  | 	public Person() {
  | 	}
  | 	
  | 	public Person(String prefixName, String firstName, String middleName, String lastName, String suffixName,
  | 					Calendar birthDate, Gender gender) {
  | 		setPrefixName(prefixName);
  | 		setFirstName(firstName);
  | 		setMiddleName(middleName);
  | 		setLastName(lastName);
  | 		setSuffixName(suffixName);
  | 		setBirthDate(birthDate);
  | 		setGender(gender);
  | 	}
  | 
  | 	// Accessors ******************************
  | 
  | 	// Common methods ******************************
  | 
  | 	public boolean equals(Object o) {
  |         if (this == o) return true;
  |         if (!(o instanceof Person)) return false;
  | 
  |         final Person person = (Person) o;
  | 
  | 		if (!firstName.equals(person.firstName)) return false;
  | 		if (!middleName.equals(person.middleName)) return false;
  | 		if (!lastName.equals(person.lastName)) return false;
  | 		if (!gender.equals(person.gender)) return false;
  | 		if (!birthDate.equals(person.birthDate)) return false;
  | 
  |         return true;
  |     }
  | 
  |     public int hashCode() {
  | 		int result;
  | 		result = firstName.hashCode();
  | 		result = 29 * result + middleName.hashCode();
  | 		result = 29 * result + lastName.hashCode();
  | 		result = 29 * result + gender.hashCode();
  | 		result = 29 * result + birthDate.hashCode();
  | 		return result;
  |     }
  | }
  | 
  | 

The exception:

  | org.hibernate.TypeMismatchException: Provided id of the wrong type. Expected: class java.lang.Long, got class java.lang.String
  | 	at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:84)
  | 	at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:878)
  | 	at org.hibernate.impl.SessionImpl.get(SessionImpl.java:815)
  | 	at org.hibernate.impl.SessionImpl.get(SessionImpl.java:808)
  | 	at org.hibernate.ejb.AbstractEntityManagerImpl.find(AbstractEntityManagerImpl.java:174)
  | 	at org.jboss.seam.persistence.EntityManagerProxy.find(EntityManagerProxy.java:78)
  | 	at org.jboss.seam.ui.EntityConverter.loadEntityFromPersistenceContext(EntityConverter.java:224)
  | 	at org.jboss.seam.ui.EntityConverter.getAsObject(EntityConverter.java:200)
  | 	at org.jboss.seam.ui.PrioritizableConverter.getAsObject(PrioritizableConverter.java:61)
  | 	at org.jboss.seam.ui.ConverterChain.getAsObject(ConverterChain.java:105)
  | 	at org.apache.myfaces.shared_impl.renderkit.RendererUtils.getConvertedUIOutputValue(RendererUtils.java:651)
  | 	at org.apache.myfaces.shared_impl.renderkit.html.HtmlMenuRendererBase.getConvertedValue(HtmlMenuRendererBase.java:111)
  | 	at javax.faces.component.UIInput.getConvertedValue(UIInput.java:395)
  | 	at javax.faces.component.UIInput.validate(UIInput.java:349)
  | 	at javax.faces.component.UIInput.processValidators(UIInput.java:183)
  | 	at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:624)
  | 	at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:624)
  | 	at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:624)
  | 	at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:624)
  | 	at javax.faces.component.UIForm.processValidators(UIForm.java:70)
  | 	at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:624)
  | 	at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:146)
  | 	at org.ajax4jsf.framework.ajax.AjaxViewRoot.access$201(AjaxViewRoot.java:53)
  | 	at org.ajax4jsf.framework.ajax.AjaxViewRoot$3.invokeRoot(AjaxViewRoot.java:302)
  | 	at org.ajax4jsf.framework.ajax.JsfOneOneInvoker.invokeOnRegionOrRoot(JsfOneOneInvoker.java:54)
  | 	at org.ajax4jsf.framework.ajax.AjaxContext.invokeOnRegionOrRoot(AjaxContext.java:176)
  | 	at org.ajax4jsf.framework.ajax.AjaxViewRoot.processValidators(AjaxViewRoot.java:315)
  | 	at org.apache.myfaces.lifecycle.LifecycleImpl.processValidations(LifecycleImpl.java:262)
  | 	at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:76)
  | 	at javax.faces.webapp.FacesServlet.service(FacesServlet.java:137)
  | 	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
  | 	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
  | 	at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:63)
  | 	at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:57)
  | 	at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:49)
  | 	at org.jboss.seam.debug.hot.HotDeployFilter.doFilter(HotDeployFilter.java:60)
  | 	at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:49)
  | 	at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
  | 	at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:49)
  | 	at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:79)
  | 	at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:49)
  | 	at org.jboss.seam.web.SeamFilter.doFilter(SeamFilter.java:84)
  | 	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
  | 	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
  | 	at org.ajax4jsf.framework.ajax.xmlfilter.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:96)
  | 	at org.ajax4jsf.framework.ajax.xmlfilter.BaseFilter.doFilter(BaseFilter.java:220)
  | 	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
  | 	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
  | 	at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
  | 	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
  | 	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
  | 	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
  | 	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
  | 	at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:175)
  | 	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:432)
  | 	at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
  | 	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
  | 	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
  | 	at org.jboss.web.tomcat.tc5.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:156)
  | 	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
  | 	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
  | 	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
  | 	at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
  | 	at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
  | 	at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
  | 	at java.lang.Thread.run(Thread.java:619)
  | 

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4056222#4056222

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4056222



More information about the jboss-user mailing list