1. #1
    Sencha User
    Join Date
    Apr 2008
    Posts
    141
    Vote Rating
    0
    armandoxxx is on a distinguished road

      0  

    Default 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<CustomercustomersCombo     = 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<CustomercustomersCombo = (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

  2. #2
    Sencha User
    Join Date
    Apr 2008
    Posts
    141
    Vote Rating
    0
    armandoxxx is on a distinguished road

      0  

    Default


    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

  3. #3
    Sencha User
    Join Date
    Apr 2008
    Posts
    141
    Vote Rating
    0
    armandoxxx is on a distinguished road

      0  

    Default


    don't tell me nobody is doing remote calls and selects data in comboboxes ..

    KInd regards

    Armando

  4. #4
    Ext User
    Join Date
    Jun 2008
    Posts
    365
    Vote Rating
    0
    sdc is on a distinguished road

      0  

    Default


    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);
    
        }
    
    
    
    
    }

  5. #5
    Sencha User
    Join Date
    Apr 2008
    Posts
    141
    Vote Rating
    0
    armandoxxx is on a distinguished road

      0  

    Default


    Hey man ..

    thank you for your reply ..

    can you please post also CustomerBeanModel class ?

    Thanx

    Armando

  6. #6
    Software Architect
    Join Date
    Sep 2007
    Posts
    13,971
    Vote Rating
    132
    sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light

      0  

    Default


    Code:
    @BEAN(Customer.class)
    public interface CustomerBeanModel extends BeanModelMarker {
     
    }

  7. #7
    Sencha User
    Join Date
    Apr 2008
    Posts
    141
    Vote Rating
    0
    armandoxxx is on a distinguished road

      0  

    Default


    thank you again for your help ..

    will try to figure out how to solve my problem ...

    Kind regards

    Armando

  8. #8
    Sencha User
    Join Date
    Apr 2008
    Posts
    141
    Vote Rating
    0
    armandoxxx is on a distinguished road

      0  

    Default


    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
    PHP 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
    Kind regards
    Armando

  9. #9
    Sencha User
    Join Date
    Apr 2008
    Posts
    141
    Vote Rating
    0
    armandoxxx is on a distinguished road

      0  

    Default


    and .. not with Dozer ...

  10. #10
    Sencha User Shawn.in.Tokyo's Avatar
    Join Date
    Feb 2009
    Posts
    42
    Vote Rating
    0
    Shawn.in.Tokyo is on a distinguished road

      0  

    Default


    Quote Originally Posted by armandoxxx View Post
    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 ?

    JSON STRING EXAMPLE for customer list in combo
    PHP 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
    Kind regards
    Armando
    You have json data coming from the server?

    I'd use the getters and setters you have in your bean.

    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;
    For example (see the api to handle an array):

    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.
    
    
    }
    If you are getting back json as a String and not JavaScriptObject, then you'll have to parse it into a JavaScriptObject first.

    Is that what you were asking?

    Shawn

Thread Participants: 3