-
11 Feb 2009 1:12 PM #1
java.lang.ClassCastException
java.lang.ClassCastException
I have a combo with customers data
Customer model
PHP Code:public class Customer extends BaseModelData {
private static final long serialVersionUID = 7597532522321819355L;
private String id;
private String name;
private Integer idAgency;
private Integer idCustomerType;
private Integer idCountry;
private Integer idLanguage;
private Integer connectionSpeed;
private Integer inboxSize;
private String email;
private String tel;
private String fax;
private String street;
private String city;
private Integer post;
private String contact;
private String contactMobile;
private Integer activeFilters;
private Integer isActive;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getIdAgency() {
return idAgency;
}
public void setIdAgency(Integer idAgency) {
this.idAgency = idAgency;
}
public Integer getIdCustomerType() {
return idCustomerType;
}
public void setIdCustomerType(Integer idCustomerType) {
this.idCustomerType = idCustomerType;
}
public Integer getIdCountry() {
return idCountry;
}
public void setIdCountry(Integer idCountry) {
this.idCountry = idCountry;
}
public Integer getIdLanguage() {
return idLanguage;
}
public void setIdLanguage(Integer idLanguage) {
this.idLanguage = idLanguage;
}
public Integer getConnectionSpeed() {
return connectionSpeed;
}
public void setConnectionSpeed(Integer connectionSpeed) {
this.connectionSpeed = connectionSpeed;
}
public Integer getInboxSize() {
return inboxSize;
}
public void setInboxSize(Integer inboxSize) {
this.inboxSize = inboxSize;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getTel() {
return tel;
}
public void setTel(String tel) {
this.tel = tel;
}
public String getFax() {
return fax;
}
public void setFax(String fax) {
this.fax = fax;
}
public String getStreet() {
return street;
}
public void setStreet(String street) {
this.street = street;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public Integer getPost() {
return post;
}
public void setPost(Integer post) {
this.post = post;
}
public String getContact() {
return contact;
}
public void setContact(String contact) {
this.contact = contact;
}
public String getContactMobile() {
return contactMobile;
}
public void setContactMobile(String contactMobile) {
this.contactMobile = contactMobile;
}
public Integer getActiveFilters() {
return activeFilters;
}
public void setActiveFilters(Integer activeFilters) {
this.activeFilters = activeFilters;
}
public Integer getIsActive() {
return isActive;
}
public void setIsActive(Integer isActive) {
this.isActive = isActive;
}
}
Combo ...
PHP Code:ComboBox<Customer> customersCombo = new ComboBox<Customer>();
customersCombo.setFieldLabel("Customer");
customersCombo.setEmptyText("Search for the customer ...");
customersCombo.setDisplayField("name");
customersCombo.setWidth(250);
customersCombo.setMinChars(2);
customersCombo.setStore(this.getCustomerStore());
customersCombo.setTypeAhead(true);
customersCombo.addListener(Events.Select, new Listener<FieldEvent>() {
public void handleEvent(FieldEvent be) {
ComboBox<Customer> customersCombo = (ComboBox<Customer>)be.component;
Dialog d = new Dialog();
d.setHeading("Exit Warning!");
Customer customer = customersCombo.getValue();
if(customer != null) {
d.addText(customer.getName()+":"+customer.getId());
} else {
d.addText("null");
}
d.addText("<br />");
d.addText(customersCombo.getRawValue());
d.show();
}
});
and I get .. java.lang.ClassCastException on getValue() .. how come !?!?
Kind regards
Armando
-
11 Feb 2009 2:29 PM #2
Strugling with the problem .. I think there might be something wrong with my model class ..
can somebody please post their model class and Combo setup ?
might be usefull to see httprequest handling also ...
thanx
Armando
-
12 Feb 2009 1:09 AM #3
don't tell me nobody is doing remote calls and selects data in comboboxes ..
KInd regards
Armando
-
12 Feb 2009 2:15 AM #4
Hi armando,
Here is a complete example for a ComboBox of customers. I use the Customer class from the GXT samples resources which is a pure Java bean (POJO). It also requires the CustomerBeanModel class.
Code:public class Test implements EntryPoint { private static void getCustomers(AsyncCallback<List<Customer>> callback) { ArrayList<Customer> res = new ArrayList<Customer>(); res.add(new Customer("Me", "hehe", 27)); res.add(new Customer("Someone", "hehe", 72)); callback.onSuccess(res); } public void onModuleLoad() { Viewport viewport = new Viewport(); RpcProxy proxy = new RpcProxy() { @Override public void load(Object loadConfig, AsyncCallback callback) { getCustomers(callback); } }; ListLoader loader = new BaseListLoader(proxy, new BeanModelReader()); ListStore<BeanModel> store = new ListStore<BeanModel>(loader); final ComboBox<BeanModel> comboBox = new ComboBox<BeanModel>(); comboBox.setFieldLabel("Profile"); comboBox.setPropertyEditor(new ListModelPropertyEditor<BeanModel>( "customName") { public String getStringValue(BeanModel value) { return ((Customer) value.getBean()).getName() + "!!"; } }); comboBox.getView().setModelProcessor(new ModelProcessor<BeanModel>() { @Override public BeanModel prepareData(BeanModel model) { if (model != null) model.set("customName", ((Customer) model.getBean()) .getName() + "!!"); return model; } }); comboBox.setStore(store); final FormPanel loginPanel = new FormPanel(); loginPanel.add(comboBox); loginPanel.layout(); viewport.add(loginPanel); RootPanel.get().add(viewport); } }
-
12 Feb 2009 2:24 AM #5
Hey man ..
thank you for your reply ..
can you please post also CustomerBeanModel class ?
Thanx
Armando
-
12 Feb 2009 2:28 AM #6
Code:@BEAN(Customer.class) public interface CustomerBeanModel extends BeanModelMarker { }
-
12 Feb 2009 2:39 AM #7
thank you again for your help ..
will try to figure out how to solve my problem ...
Kind regards
Armando
-
14 Feb 2009 12:04 AM #8
I figured out the BeanModel part and how to make it work .. is there a way of doing this with JSON data returned from the server ?
my data is a List<Customer> represented in JSON string and I would like to convert it to my Customer objects and show it on the list in combobox ...
I'm doing it like this, because my backend are several different applications and they all return JSON string representing objects
so now I'm stuck in converting my JSON strings to my real Customer object ..
any help would be appreciated ..
JSON STRING EXAMPLE for customer list in combo
Kind regardsPHP Code:{"data":[{"post":0,"fax":"","idCustomerType":1,"idLanguage":0,"tel":"","street":"","inboxSize":4194304
,"idCountry":0,"idAgency":1,"contact":"","isActive":1,"id":286,"email":"","name":"UVI","connectionSpeed"
:131072,"contactMobile":"","activeFilters":1}],"total":1}
Armando
-
14 Feb 2009 1:10 AM #9
-
14 Feb 2009 5:18 AM #10
You have json data coming from the server?
I'd use the getters and setters you have in your bean.
For example (see the api to handle an array):Code:import com.google.gwt.core.client.JavaScriptObject; import com.google.gwt.json.client.JSONArray; import com.google.gwt.json.client.JSONObject; import com.google.gwt.json.client.JSONValue;
If you are getting back json as a String and not JavaScriptObject, then you'll have to parse it into a JavaScriptObject first.Code:JSONObject dataHolder; public String handleData(JavaScriptObject jsData) { Customer = new Customer();//You have a customer bean right!?! dataHolder = new JSONObject(jsData); setPost((int)dataHolder.get("data").isObject().get("post").isNumber().doubleValue()); setEmail(dataHolder.get("data").isObject().get("email").isString().toString()); etc etc. }
Is that what you were asking?
Shawn


Reply With Quote