Announcement

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

    Migrating fron Smartgwt 3.1 to Smartgwt 5.0 Shortcut for MenuItem problem

    Hello,

    we use SmartGWT 3.1 (v8.3p_2014-02-24/PowerEdition) to have shortcuts (like Alt+Ctrl+B) on MenuItems which work flawlessly.

    Migrating the project to use SmartGwt 5.0p (v10.0p_2015-02-11) it does not work anymore.

    Tested with IE 11, Firefox 35 and Chrome 40

    I can see an error in the Developer Console, I cannot interpret:

    tack from error.stack:
    Menu.setDynamicItems(<no args: exited>) on [Menu ID:isc_CamMenu_7] @ ISC_Grids.js:3180:26
    Menu.menuKey(<no args: exited>) on [Menu ID:isc_CamMenu_7] @ ISC_Grids.js:3202:166
    eval(<no args: exited>) @ [no file]:3:15
    [c]Page.handleKeyPress(<no args: exited>) @ ISC_Core.js:1303:9
    [c]EventHandler.handleKeyPress(<no args: exited>) @ ISC_Core.js:1345:35
    EventHandler._handleNativeKeyUp(<no args: exited>) @ ISC_Core.js:1332:78
    [c]EventHandler.dispatch(_1=>[c]EventHandler.$kb(), _2=>[object KeyboardEvent]) @ ISC_Core.js:1637:108
    HTMLDocument.eval(event=>[object KeyboardEvent]) @ [no file]:3:123

    Here our code:

    MenuItem removeNodeMenuItem = new MenuItem("Remove <u>B</u>ranch");
    removeNodeMenuItem.setKeyTitle("Cltr+Alt+B");
    KeyIdentifier key = new KeyIdentifier();
    key.setCtrlKey(true);
    key.setAltKey(true);
    key.setKeyName("B");
    removeNodeMenuItem.setKeys(key);

    Thank you for your help in advance.

    #2
    We're not seeing this error - if we drop your MenuItem definition into a Menu with an ItemClickHandler, then we see that handler fire as expected when we press Alt-Ctrl-B.

    So, if you think there's a framework problem, we'll need to see a stand-alone sample that incorporates your MenuItem and shows the issue.

    Comment


      #3
      Hello,

      I had a look at the javascript code of the stacktrace.

      11:00:50.099:KUP0:WARN:Log:TypeError: Cannot read property 'length' of undefined
      Stack from error.stack:
      Menu.setDynamicItems(<no args: exited>) on [Menu ID:isc_CamMenu_7] @ ISC_Grids.js:3180:26
      Menu.menuKey(<no args: exited>) on [Menu ID:isc_CamMenu_7] @ ISC_Grids.js:3202:166
      eval(<no args: exited>) @ [no file]:3:15
      [c]Page.handleKeyPress(<no args: exited>) @ ISC_Core.js:1303:9
      [c]EventHandler.handleKeyPress(<no args: exited>) @ ISC_Core.js:1345:35
      EventHandler._handleNativeKeyUp(<no args: exited>) @ ISC_Core.js:1332:78
      [c]EventHandler.dispatch(_1=>[c]EventHandler.$kb(), _2=>[object KeyboardEvent]) @ ISC_Core.js:1637:108
      HTMLDocument.eval(event=>[object KeyboardEvent]) @ [no file]:3:123

      I modified the IS_Grid.js and changed
      for(var i=0,_10=this.data.length;i<_10;++i){...}
      to
      if(this.data){for(var i=0,_10=this.data.length;i<_10;++i){...}}

      Now my shortcut works. So I kindly like to ask you to add this to your code. Can you inform me, when it is in?

      I do not understand why this problem happens. But my application destroys the old context menu on the grid regularly and recreates a new (when data changes). And the component named in the stacktrace is not found when I use the developer tools in Chrome. As I said, my code works well under SmartGWT 3.1. So how would I best destroy/replace a context meno on a tree grid in SmartGWT 5.0p?

      I hope to here from you soon, about the fix I suggested. Many thanks.

      Comment


        #4
        We've gone ahead and added a null check in this code - you can test this out in the latest builds at smartclient.com/builds.

        To help with the implementation of your menu destroy code, we'd need to see a standalone version of it that shows an issue.

        Comment


          #5
          Hi,

          here a minimal testcase which shows the error. I also attached a screenshot, showing the error in Firefox console.

          Code:
          Menu menu = new Menu();
              
              @Override
          	public void onModuleLoad() {
              	// build a grid with three dummy entries and a context menu, based on the selected record
              	final ListGrid grid = new ListGrid();
              	grid.setFields(new ListGridField("nodeName"));
              	grid.setRecords(new ListGridRecord[] {
              			new ListGridRecord() {{ setAttribute("nodeName", "Node 1"); }}, 
              			new ListGridRecord() {{ setAttribute("nodeName", "Node 2"); }}, 
              			new ListGridRecord() {{ setAttribute("nodeName", "Node 3"); }}
              	});
              	
              	grid.addRecordClickHandler(new RecordClickHandler() {
          			@Override
          			public void onRecordClick(final RecordClickEvent event) {
          				// remove the old menu and set a new one
          				if (menu != null) {
          					try {
          						menu.removeFromParent();
          			        } catch(Exception e) {
          						// do nothing
          					}
          					menu.destroy();
          					grid.setContextMenu(null);
          					menu = null;
          				}
          				// build the menu, based on record specific settings
          				menu = buildMenu(event.getRecord());
          				grid.setContextMenu(menu);
          			}
          		});
          		grid.draw();
          	}
          
              private Menu buildMenu(Record r) {
              	
              	Menu menu = new Menu();
          		final MenuItem myMenuItem = new MenuItem("S<u>h</u>ortcut to " + r.getAttribute("nodeName"));
          		myMenuItem.addClickHandler(new com.smartgwt.client.widgets.menu.events.ClickHandler() {
          			@Override
          			public void onClick(MenuItemClickEvent event) {
          				SC.say("clicked");
          			}
          		});
          		
          		final KeyIdentifier key = new KeyIdentifier();
          		key.setCtrlKey(true);
          		key.setAltKey(true);
          		key.setKeyName("h");
          		myMenuItem.setKeys(key);
          		menu.addItem(myMenuItem);
          		
          		return menu;
              }
          Attached Files

          Comment


            #6
            Are you saying you still have an issue after updating to the latest patched build? You have have missed our reply above stating that we added a null check that should prevent your error, even though we were not actually able to reproduce it.

            Comment

            Working...
            X