I try to create a DynamicForm where a Customer can be edited.
Each customer has a Title (Dr. or Prof) - and this should be selected with an SelectItem.
To solve that I have two classes - a Customer - and a Title.
Both are defined as a hibernate datasource (see below).
1) i do not get the content of the title shown (it is always a [object Object])
2) when loading the form i get the error "org.apache.commons.collections.map.LinkedMap cannot be cast to java.lang.Long"
what am i doing wrong - any idea - here are the Entitys - the datasource declaration and the client part - for better understanding!
PS: i do not want to change the field "title" into a String - as there still should be a database mapping (and the database is already used by another application - so i cannot change the field)
Each customer has a Title (Dr. or Prof) - and this should be selected with an SelectItem.
To solve that I have two classes - a Customer - and a Title.
Both are defined as a hibernate datasource (see below).
1) i do not get the content of the title shown (it is always a [object Object])
2) when loading the form i get the error "org.apache.commons.collections.map.LinkedMap cannot be cast to java.lang.Long"
what am i doing wrong - any idea - here are the Entitys - the datasource declaration and the client part - for better understanding!
PS: i do not want to change the field "title" into a String - as there still should be a database mapping (and the database is already used by another application - so i cannot change the field)
Code:
@Entity
public class Customer implements Serializable {
@Id
@Column(nullable = false)
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long cmtcustomerid;
private String firstName;
private String lastName;
@ManyToOne
@JoinTable(name = "CustomerTitle")
private Title title;
getters / setters
Code:
@Entity
public class Title implements Serializable{
@Id
@Column(nullable = false)
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long titleId;
private String titleName;
Code:
<DataSource ID="customer_title" serverType="hibernate" beanclassname="com.amergy.cmt.server.entity.Title" schemaBean="com.amergy.cmt.server.entity.Title"> <fields> <field name="titleId" type="sequence" primaryKey="true" canEdit="false" hidden="true" /> </fields> </DataSource>
Code:
<DataSource ID="customer" serverType="hibernate" beanclassname="com.amergy.cmt.server.entity.CMTCustomer" schemaBean="com.amergy.cmt.server.entity.CMTCustomer"> <fields> <field name="cmtcustomerid" type="sequence" primaryKey="true" canEdit="false" hidden="true" /> <field name="title" multiple="false" type="customer_title"/> </fields> </DataSource>
Code:
DynamicForm customerForm = new DynamicForm();
customerForm.setHeight100();
customerForm.setWidth("90%");
customerForm.setAutoFetchData(false);
customerForm.setDataSource(DataSource.get("customer"));
FormItem name = new FormItem("firstName");
name.setTitle("First Name");
FormItem lastname = new FormItem("lastName");
lastname.setTitle("Last Name");
SelectItem title = new SelectItem("title");
title.setTitle("Title");
title.setOptionDataSource(DataSource.get("customer_title"));
title.setDisplayField("titleName");
title.setValueField("titleId");
customerForm.setItems(name, lastname, title);