Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    ListGrid onRecordClick - Uncaught JavaScript exception

    Hi,
    I am trying to assign a cell value to a TextItem during onRecordClick of a ListGrid.

    Getting the error - Uncaught JavaScript exception [error has no properties] in http://localhost:8888/com.mycompany.HelloWorld/sc/client/debug/debug.js, line 281 from GWT.

    Am I missing something here. Can anyone help in resolving the issue. Thanks in advance.

    Code is as follows
    EntryPoint
    Code:
    package com.mycompany.client;
    
    import com.google.gwt.core.client.EntryPoint;
    import com.mycompany.client.sampledata.countryXmlDS;
    import com.smartgwt.client.widgets.form.DynamicForm;
    import com.smartgwt.client.widgets.form.fields.TextItem;
    import com.smartgwt.client.widgets.grid.ListGrid;
    import com.smartgwt.client.widgets.grid.events.RecordClickEvent;
    import com.smartgwt.client.widgets.grid.events.RecordClickHandler;
    import com.smartgwt.client.widgets.layout.HLayout;
    import com.smartgwt.client.widgets.tab.Tab;
    import com.smartgwt.client.widgets.tab.TabSet;
    import com.smartgwt.client.data.DataSource;
    
    /**
     * Entry point classes define <code>onModuleLoad()</code>.
     */
    public class HelloWorld implements EntryPoint {
    
      /**
       * This is the entry point method.
       */
      public void onModuleLoad() {
      
    	  DataSource countryDS = countryXmlDS.getInstance();	  
    	  ListGrid grid = new ListGrid();  
          grid.setWidth("250");	      
          grid.setHeight("20%");  
          grid.setDataSource(countryDS);  
          grid.setAutoFetchData(true);
          
          final TextItem myText = new TextItem("Country");
    
          grid.addRecordClickHandler(new RecordClickHandler(){
    		public void onRecordClick(RecordClickEvent event) {    	  
    			Country Message = (Country) event.getRecord();					
    			myText.setValue(Message.getCountry());		
    		}		
          });
          
          final TabSet countryTabSet = new TabSet();
          countryTabSet.setWidth("250");
          countryTabSet.setHeight("20%");
    
          Tab tTab1 = new Tab("Country");
    
          final DynamicForm countryForm = new DynamicForm();          
          countryForm.setFields(myText);
    
          tTab1.setPane(countryForm);
          countryTabSet.addTab(tTab1);
          
          HLayout mainLayout = new HLayout();  
          mainLayout.setLayoutMargin(15);  
          mainLayout.setWidth("100%");  
          mainLayout.setHeight("100%"); 
          mainLayout.setMembersMargin(5);
          mainLayout.addMember(grid);      
          mainLayout.addMember(countryTabSet);
          mainLayout.draw();
      }  
      
    }
    CountryXMLDS.java
    Code:
    package com.mycompany.client.sampledata;
    
    import com.smartgwt.client.data.DataSource;
    import com.smartgwt.client.data.fields.*;
    
    public class countryXmlDS extends DataSource {
    
        private static countryXmlDS instance = null;
    
        public static countryXmlDS getInstance() {
            if (instance == null) {
                instance = new countryXmlDS("countryDS");
            }
            return instance;
        }
    
        public countryXmlDS(String id) {
            setID(id);
            setRecordXPath("/List/country");
            
            DataSourceIntegerField pkField = new DataSourceIntegerField("pk");
            pkField.setHidden(true);
            pkField.setPrimaryKey(true);
            
            DataSourceTextField countrycodeField = new DataSourceTextField("countrycode", "Code");
            countrycodeField.setRequired(true);
            
            DataSourceTextField countryField = new DataSourceTextField("country", "Country");
            countrycodeField.setRequired(true);
                    		
            setFields(pkField, countrycodeField, countryField);
    
            setDataURL("ds/test_data/country.data.xml");
            setClientOnly(true);
        }
    }
    Country.java
    Code:
    package com.mycompany.client;
    
    import com.smartgwt.client.widgets.grid.ListGridRecord;
    
    public class Country extends ListGridRecord {
    
        public Country() {
        }
    
        public Country(String countrycode, String country) {
            setCountryCode(countrycode);
            setCountry(country);        
            
        }
      
        public void setCountryCode(String countrycode) {
            setAttribute("countrycode", countrycode);
        }
    
        public String getCountryCode() {
            return getAttributeAsString("countrycode");
        }
    
        public void setCountry(String country) {
            setAttribute("country", country);
        }
    
        public String getCountry() {
            return getAttributeAsString("country");
        }
            
    }
    Country.data.xml
    Code:
    <List>
    
    <country>
        <countrycode>001</countrycode>
        <country>United States</country>    
    </country>
    <country>
        <countrycode>002</countrycode>
        <country>India</country>    
    </country>
    <country>
        <countrycode>003</countrycode>
        <country>United Kingdom</country>    
    </country>
    
    </List>
    From a standalone browser it is not working and Firebug gives the following errors,

    Unknown property 'text-overflow'. Declaration dropped.
    http://localhost:8888/com.mycompany.HelloWorld/sc/skins/Enterprise/skin_styles.css
    Line 1075

    Unknown property 'text-overflow'. Declaration dropped.
    http://localhost:8888/com.mycompany.HelloWorld/sc/skins/Enterprise/skin_styles.css
    Line 1168

    Error in parsing value for property 'filter'. Declaration dropped.
    http://localhost:8888/com.mycompany.HelloWorld/sc/skins/Enterprise/skin_styles.css
    Line 1231

    Error in parsing value for property 'filter'. Declaration dropped.
    http://localhost:8888/com.mycompany.HelloWorld/sc/skins/Enterprise/skin_styles.css
    Line 1236

    Unknown property 'text-overflow'. Declaration dropped.
    http://localhost:8888/com.mycompany.HelloWorld/sc/skins/Enterprise/skin_styles.css
    Line 1387

    Unknown property 'text-overflow'. Declaration dropped.
    http://localhost:8888/com.mycompany.HelloWorld/sc/skins/Enterprise/skin_styles.css
    Line 1394

    Unknown property 'text-overflow'. Declaration dropped.
    http://localhost:8888/com.mycompany.HelloWorld/sc/skins/Enterprise/skin_styles.css
    Line 1401

    Error in parsing value for property 'filter'. Declaration dropped.
    http://localhost:8888/com.mycompany.HelloWorld/sc/skins/Enterprise/skin_styles.css
    Line 1716

    Error in parsing value for property 'filter'. Declaration dropped.
    http://localhost:8888/com.mycompany.HelloWorld/sc/skins/Enterprise/skin_styles.css
    Line 1720

    Error in parsing value for property 'filter'. Declaration dropped.
    http://localhost:8888/com.mycompany.HelloWorld/sc/skins/Enterprise/skin_styles.css
    Line 1724

    Selector expected. Ruleset ignored due to bad selector.
    http://localhost:8888/com.mycompany.HelloWorld/HelloWorld.css
    Line 6

    Unexpected end of file while searching for closing } of invalid rule set.
    http://localhost:8888/com.mycompany.HelloWorld/HelloWorld.css
    Line 6

    Unknown property 'wrap'. Declaration dropped.
    http://localhost:8888/com.mycompany.HelloWorld/HelloWorld.html
    Line 0

    #2
    The source data is in xml, so there's no way to know that you want to map your xml data to the Country class. So you cant cast event.getRecord() to your Country class.

    Code:
     grid.addRecordClickHandler(new RecordClickHandler(){
    		public void onRecordClick(RecordClickEvent event) {    	  
    			Country Message = (Country) event.getRecord();					
    			myText.setValue(Message.getCountry());		
    		}		
          });
    You could change the above code to

    Code:
     grid.addRecordClickHandler(new RecordClickHandler(){
    		public void onRecordClick(RecordClickEvent event) {    	  
    			ListGridRecord Message = event.getRecord();					
    			myText.setValue(Message.getAttribute("countryCode));		
    		}		
          });
    or

    convert the ListGridRecord to your County class object

    ListGridRecord record = event.getRecord();
    Country countryRecord = new Country(record.getJsObj());

    and add a constructor Country(JavaScriptObject jsObj);

    Comment


      #3
      It works now

      Smartgwt.dev,
      Thanks, changed to the below code and it works.

      Code:
       grid.addRecordClickHandler(new RecordClickHandler(){
      		public void onRecordClick(RecordClickEvent event) {    	  
      			ListGridRecord Message = event.getRecord();					
      			myText.setValue(Message.getAttribute("countryCode));		
      		}		
            });

      Comment


        #4
        Cast a ListGridRecord to other Class on DataSource

        And why not cast ListGridRecord to other Class on DataSource from @Override of :

        Code:
        protected void transformResponse(DSResponse response, DSRequest request, Object data) {
        
        	ListGridRecord lgrA[] = response.getData();
        	Country lgrB[] = new Country[lgrA.length];
        
        	for(int i=0; i<lgrA.length; i++) {
        		ListGridRecord lgr = lgrA[i];
        
        		lgrB[i] = new Country (lgr);
        	}
        
        	response.setData(lgrB);
        
        }
        If your Country class extends ListGridRecord, you can cast you data as you try in your first post.

        Comment


          #5
          Yes, this is a good solution.

          Comment


            #6
            Type mismatch: cannot convert from Record to ListGridRecord

            Hi,



            For TreeGrid, inside onRecordClick(), this command
            ListGridRecord record = event.getRecord();

            compile OK on SmartGWT 1.0 (release 391)
            but fail on SmartGWT 1.1 with error message:
            Type mismatch: cannot convert from Record to ListGridRecord

            Anyone has similar problem ?

            Comment


              #7
              Simply change
              ListGridRecord record = event.getRecord();
              to
              ListGridRecord record = (ListGridRecord) event.getRecord();

              seem fix the issue.

              Comment

              Working...
              X