Announcement

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

    js exception "self.clearValue is not a function" on FilterBuilder item

    Hi,
    When clicking FormItemIcon to clear item value I get java script error:
    Code:
    Uncaught exception escaped : com.google.gwt.core.client.JavaScriptException
    (TypeError): self.clearValue is not a function
     fileName: http://localhost:8080
     lineNumber: 85
     stack: ()@http://localhost:8080:85
    @:0
    ([object GWTJavaObject],4980790,[object GWTJavaObject])@http://localhost:8080/TestFilterImageItem/hosted.html?org_yournamehere_Main:56
    ([object Object],[object Object],[object Object])@http://localhost:8080:8
    ((function () {var param = {form: arguments[0], item: arguments[1], icon: arguments[2]};var event = __gwt_makeJavaInvoke(1)(null, 7340061, param);__gwt_makeJavaInvoke(1)(selfJ, 4980790, event);}),[object Object],[object Object])@http://localhost:8080:72
    @:0
    (null,65563,(function () {var param = {form: arguments[0], item: arguments[1], icon: arguments[2]};var event = __gwt_makeJavaInvoke(1)(null, 7340061, param);__gwt_makeJavaInvoke(1)(selfJ, 4980790, event);}),[object Object],[object Object])@http://localhost:8080/TestFilterImageItem/hosted.html?org_yournamehere_Main:56
    ([object Object],[object Object],[object Object])@http://localhost:8080:42
    isc_FormItem__iconClick("_0")@http://localhost:8080/TestFilterImageItem/sc/modules/ISC_Forms.js:1406
    isc_DynamicForm_handleClick([object Object],(void 0))@http://localhost:8080/TestFilterImageItem/sc/modules/ISC_Forms.js:643
    isc_c_EventHandler_bubbleEvent([object Object],"click")@http://localhost:8080/TestFilterImageItem/sc/modules/ISC_Core.js:1515
    isc_c_EventHandler_handleClick([object Object])@http://localhost:8080/TestFilterImageItem/sc/modules/ISC_Core.js:1363
    isc_c_EventHandler__handleMouseUp([object MouseEvent],(void 0))@http://localhost:8080/TestFilterImageItem/sc/modules/ISC_Core.js:1350
    isc_c_EventHandler_handleMouseUp([object MouseEvent])@http://localhost:8080/TestFilterImageItem/sc/modules/ISC_Core.js:1341
    isc_c_EventHandler_dispatch(isc_c_EventHandler_handleMouseUp,[object MouseEvent])@http://localhost:8080/TestFilterImageItem/sc/modules/ISC_Core.js:1578
    anonymous([object MouseEvent])@http://localhost:8080/TestFilterImageItem/sc/modules/ISC_Core.js:38
    
    See the Development console log for details.
    Register a GWT.setUncaughtExceptionHandler(..) for custom uncaught exception handling.
    The test case is simple enough:
    Code:
    package org.yournamehere.client;
    
    import com.google.gwt.core.client.EntryPoint;
    import com.smartgwt.client.data.DataSource;
    import com.smartgwt.client.data.fields.DataSourceTextField;
    import com.smartgwt.client.widgets.form.FilterBuilder;
    import com.smartgwt.client.widgets.form.fields.FormItemIcon;
    import com.smartgwt.client.widgets.form.fields.TextItem;
    import com.smartgwt.client.widgets.form.fields.events.FormItemClickHandler;
    import com.smartgwt.client.widgets.form.fields.events.FormItemIconClickEvent;
    import com.smartgwt.client.widgets.layout.VLayout;
    
    public class MainEntryPoint implements EntryPoint {
    
        public MainEntryPoint() {
        }
    
        public void onModuleLoad() {
    
            DataSource ds = new DataSource();
    
            DataSourceTextField textField = new DataSourceTextField("text");
    
            ds.setFields(textField);
    
            FilterBuilder filter = new FilterBuilder();
           
            final TextItem item = new TextItem();
            FormItemIcon clearIcon = new FormItemIcon();
            clearIcon.setSrc("[SKIN]/actions/remove.png");
            clearIcon.addFormItemClickHandler(new FormItemClickHandler() {
    
                public void onFormItemClick(FormItemIconClickEvent event) {
                    item.clearValue();
                }
            });
            item.setIcons(clearIcon);
    
            textField.setEditorType(item);
    
            filter.setDataSource(ds);
    
            VLayout main = new VLayout();
            main.addMember(filter);
            main.draw();
        }
    }
    Tested on SGWT nightly 2011-03-15. No messages on the Developer Console. Firefox 3.6; Gentoo Linux; Development/Debug mode.
    MichalG
    Last edited by michalg; 22 Mar 2011, 00:56.

    #2
    Hi Michal,
    The issue here is that when you do 'setEditorType()' and pass in a form item, you're essentially passing in a template set of form item properties which will be applied when editing the field in question. The distinction is important because it means when an editor is actually showing for the field the live FormItem instance is not the same object as the 'item' you originally specified.
    The reason there is such a distinction is that setEditorType() allows you to specify essentially a configuration block that is applied to potentially multiple items on the screen - every editor shown for the DataSourceField.

    To get at the live item you typically want to make use of the event object passed into your event handler - so in this case if you call "item.clearValue()" you're calling clearValue on your prototype item which has never actually been initialized as a live item on the page - hence the script error. If instead you call "event.getItem().clearValue()" you are calling clearValue on the live formItem where the event was generated.

    Comment


      #3
      OK.
      Thank you for the clear explanation.
      MichalG

      Comment

      Working...
      X