Announcement

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

    MenuItem click-driven check toggle produces JavaScript error

    I'm trying to toggle the check on a MenuItem when clicked using the following code (snippet):

    MenuItemIfFunction headerIfFunc = new MenuItemIfFunction() {
    public boolean execute(Canvas target, Menu menu, MenuItem item)
    {
    return (itemIsVisible[j]);
    }
    };

    com.smartgwt.client.widgets.menu.events.ClickHandler menuItemClickHandler = new com.smartgwt.client.widgets.menu.events.ClickHandler()
    {
    public void onClick(MenuItemClickEvent event)
    {
    itemIsVisible[j] = !itemIsVisible[j];
    }
    };


    newMenuItem.setCheckIfCondition(headerIfFunc);
    newMenuItem.addClickHandler(menuItemClickHandler);

    .
    .
    .

    itemIsVisible is a class-level boolean array, and the setup is that these menu items are bound to a Menu that itself is a submenu.

    The JavaScript error occurs when the "parent" menu item is clicked. It pops up repeatedly, apparently for each menu item in the submenu:

    com.google.gwt.core.client.JavaScriptException: (TypeError): elem is null
    fileName: http://127.0.0.1:8888
    lineNumber: 122
    stack: (null,"__ref")@http://127.0.0.1:8888:122
    @:0
    (null,10813539,(void 0))@http://127.0.0.1:8888/ipgui/hosted.html?ipgui:56
    ((void 0),[object Object],[object Object])@http://127.0.0.1:8888:5
    ((function (target, menu, item) {var targetJ;if (__gwt_makeJavaInvoke(1)(null, 10813539, target)) {targetJ = __gwt_makeJavaInvoke(1)(null, 10813537, target);} else {targetJ = __gwt_makeJavaInvoke(1)(null, 131188, target);}var menuJ = __gwt_makeJavaInvoke(1)(null, 131188, menu);var itemJ = __gwt_makeJavaInvoke(1)(null, 7209026, item);return __gwt_makeJavaInvoke(3)(checkIf, 10878977, targetJ, menuJ, itemJ);}),[object Object],[object Object])@http://127.0.0.1:8888:6
    @:0
    (null,65563,(function (target, menu, item) {var targetJ;if (__gwt_makeJavaInvoke(1)(null, 10813539, target)) {targetJ = __gwt_makeJavaInvoke(1)(null, 10813537, target);} else {targetJ = __gwt_makeJavaInvoke(1)(null, 131188, target);}var menuJ = __gwt_makeJavaInvoke(1)(null, 131188, menu);var itemJ = __gwt_makeJavaInvoke(1)(null, 7209026, item);return __gwt_makeJavaInvoke(3)(checkIf, 10878977, targetJ, menuJ, itemJ);}),[object Object],[object Object])@http://127.0.0.1:8888/ipgui/hosted.html?ipgui:56
    ((void 0),[object Object],[object Object])@http://127.0.0.1:8888:24
    ((void 0),[object Object],[object Object])@http://127.0.0.1:8888:13
    anonymous()@http://127.0.0.1:8888/ipgui/sc/modules/ISC_Grids.js?isc_version=7.0.js:2924
    isc_Menu_show()@http://127.0.0.1:8888/ipgui/sc/modules/ISC_Grids.js?isc_version=7.0.js:2862
    isc_Menu_placeSubmenu([object Object],[object Object])@http://127.0.0.1:8888/ipgui/sc/modules/ISC_Grids.js?isc_version=7.0.js:2911
    isc_Menu_showSubmenu([object Object])@http://127.0.0.1:8888/ipgui/sc/modules/ISC_Grids.js?isc_version=7.0.js:2902
    isc_Menu_changeSubmenu()@http://127.0.0.1:8888/ipgui/sc/modules/ISC_Grids.js?isc_version=7.0.js:2899
    isc_c_Class_fireCallback([object Object],(void 0),[object Array],[object Object],true)@http://127.0.0.1:8888/ipgui/sc/modules/ISC_Core.js?isc_version=7.0.js:301
    isc_c_Timer__fireTimeout("$ir641")@http://127.0.0.1:8888/ipgui/sc/modules/ISC_Core.js?isc_version=7.0.js:1187
    @http://127.0.0.1:8888/ipgui/sc/modules/ISC_Core.js?isc_version=7.0.js:1182
    : null[Ljava.lang.StackTraceElement;@2a3d8cdc

    #2
    Have you tried commenting out the return (itemIsVisible[j]); does this still produce the error? The parent click should force the call of that function for each child.

    Comment


      #3
      Same issue

      @svjard, thanks -- I can't completely comment out the return, it won't compile if I do that. However, I replaced it with a return false and also tried return true with no luck. The same thing happened.

      Comment


        #4
        Ok one more thing, are you on the latest SmartGwt version?

        Comment


          #5
          If you're not on Smart GWT 2.2, please upgrade as there was a fix related to this. Also always post the version of Smart GWT you're using. This is clearly mentioned when you're posting and in the FAQ.

          Sanjiv

          Comment


            #6
            More 411

            Thanks for the posts, fellas. We are using 2.2. Have their been incremental releases for this version? We started using our current smartgwtee-2.2 zip file around May 11.

            Comment


              #7
              The fix was made around a week ago so please pick up the latest nightly of EE or wait till the official 2.2 release of EE is out.

              Sanjiv

              Comment


                #8
                Still no luck

                I've tried this again using the latest nightly build. Unfortunately, I am getting the same javascript error popup (elem is null).

                Here is the test code I am using below. (As before b is just a class level boolean variable.)

                Are you able to drill down to the menu item in your current environment?

                Code:
                public void onModuleLoad() {
                
                		mainLayout = new VLayout();
                		
                		Menu menu = new Menu();
                		menu.setShowShadow(true);
                		menu.setShadowDepth(10);
                		
                		MenuItem subMenu = new MenuItem("SubMenu");
                		
                		Menu mySubMenu = new Menu();
                		MenuItem item1 = new MenuItem("Item 1");
                		
                		item1.addClickHandler(new com.smartgwt.client.widgets.menu.events.ClickHandler() {
                			@Override
                			public void onClick(MenuItemClickEvent event) {
                				b = !b;
                			}
                		});
                		
                		MenuItemIfFunction ifFunc = new MenuItemIfFunction() {
                			@Override
                			public boolean execute(Canvas target, Menu menu, MenuItem item) {
                				if (b)
                					return true;
                				return false;
                			}
                    	};
                    	item1.setCheckIfCondition(ifFunc);
                    	mySubMenu.addItem(item1);
                		
                    	subMenu.setSubmenu(mySubMenu);
                    	menu.addItem(subMenu);
                    	
                    	MenuButton mb = new MenuButton("Menu", menu);
                    	
                    	mainLayout.addMember(mb);
                		mainLayout.draw();
                	}

                Comment


                  #9
                  I can confirm the problem even in the nightly build from June 16. Furthermore, I have located the problem: commenting out setCheckIfCondition or setEnableIfCondition does not throw the exception anymore, but now I cannot enable/disable menu item dynamically.

                  This has worked under SmartGWT 2.1 and previous.

                  I have tried to overwrite enableIf method of MenuItem, but without luck, it is not invoked at all.

                  Comment


                    #10
                    I've confirmed this. Please file an issue in tracker with a link to this post.

                    Comment


                      #11
                      Done.

                      http://code.google.com/p/smartgwt/issues/detail?id=476

                      Comment


                        #12
                        Just to add a wrinkle to this, I'm getting the exact same error, but my setup is different. I have a TreeGrid with an attached contextual menu, as well as a MenuButton that pops up the same Menu instance. The error occurs only when I click the MenuButton before I've right-clicked anywhere in the tree; otherwise, it's fine. Does the tree's context-click handler initialize something that the MenuButton doesn't?

                        Comment


                          #13
                          Also FYI: overriding a MenuItem's enableIf() does work, so that's a working alternative to setEnableIfCondition(). (I haven't yet confirmed the same for checkIf().)

                          Comment


                            #14
                            Originally posted by NRitH
                            Also FYI: overriding a MenuItem's enableIf() does work, so that's a working alternative to setEnableIfCondition(). (I haven't yet confirmed the same for checkIf().)
                            I spoke too soon. enableIf() doesn't appear to get called at all. :(

                            Comment


                              #15
                              Any progress on this front? I've got the same issue. Stack trace:

                              Uncaught exception escaped : com.google.gwt.core.client.JavaScriptException
                              (TypeError): elem is null
                              fileName: http://127.0.0.1:8888
                              lineNumber: 344
                              stack: (null,"__ref")@http://127.0.0.1:8888:344
                              @:0
                              (null,10748003,(void 0))@http://127.0.0.1:8888/templatemaker/hosted.html?templatemaker:56
                              ((void 0),[object Object],[object Object])@http://127.0.0.1:8888:94
                              ((function (target, menu, item) {var targetJ;if (__gwt_makeJavaInvoke(1)(null, 10748003, target)) {targetJ = __gwt_makeJavaInvoke(1)(null, 10748000, target);} else {targetJ = __gwt_makeJavaInvoke(1)(null, 131189, target);}var menuJ = __gwt_makeJavaInvoke(1)(null, 131189, menu);var itemJ = __gwt_makeJavaInvoke(1)(null, 7340098, item);return __gwt_makeJavaInvoke(3)(checkIf, 10813441, targetJ, menuJ, itemJ);}),[object Object],[object Object])@http://127.0.0.1:8888:12
                              @:0
                              (null,65563,(function (target, menu, item) {var targetJ;if (__gwt_makeJavaInvoke(1)(null, 10748003, target)) {targetJ = __gwt_makeJavaInvoke(1)(null, 10748000, target);} else {targetJ = __gwt_makeJavaInvoke(1)(null, 131189, target);}var menuJ = __gwt_makeJavaInvoke(1)(null, 131189, menu);var itemJ = __gwt_makeJavaInvoke(1)(null, 7340098, item);return __gwt_makeJavaInvoke(3)(checkIf, 10813441, targetJ, menuJ, itemJ);}),[object Object],[object Object])@http://127.0.0.1:8888/templatemaker/hosted.html?templatemaker:56
                              ((void 0),[object Object],[object Object])@http://127.0.0.1:8888:41
                              ((void 0),[object Object],[object Object])@http://127.0.0.1:8888:13
                              anonymous()@http://127.0.0.1:8888/templatemaker/sc/modules/ISC_Grids.js:2903
                              isc_Menu_show()@http://127.0.0.1:8888/templatemaker/sc/modules/ISC_Grids.js:2841
                              isc_Menu_placeSubmenu([object Object],[object Object])@http://127.0.0.1:8888/templatemaker/sc/modules/ISC_Grids.js:2890
                              isc_Menu_showSubmenu([object Object])@http://127.0.0.1:8888/templatemaker/sc/modules/ISC_Grids.js:2881
                              isc_Menu_changeSubmenu()@http://127.0.0.1:8888/templatemaker/sc/modules/ISC_Grids.js:2878
                              isc_c_Class_fireCallback([object Object],(void 0),[object Array],[object Object],true)@http://127.0.0.1:8888/templatemaker/sc/modules/ISC_Core.js:282
                              isc_c_Timer__fireTimeout("$ir269")@http://127.0.0.1:8888/templatemaker/sc/modules/ISC_Core.js:1153
                              @http://127.0.0.1:8888/templatemaker/sc/modules/ISC_Core.js:1148

                              Comment

                              Working...
                              X