Announcement

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

    Bug in MenuItem.setDynamicTitleFunction

    This assuming that the MenuItem item argument in the execute method's signature ought to contain the MenuItem currently being evaluated?

    What I see is that item is always null (okay, it's probably more accurate to say that there seems to be a bug in whatever thing issues the callback (the menu?))

    Code:
    public void onModuleLoad() {  
      
            Canvas main = new Canvas();  
      
            final Menu mCategory = new Menu();
            mCategory.setTitle("Do something");
            mCategory.setCanSelectParentItems(true);
            
            DataSource ds = SupplyCategoryXmlDS.getInstance();
            
            ds.fetchData(new Criteria(), new DSCallback() {
    			public void execute(DSResponse response, Object rawData, DSRequest request) {
    			  Record[] records = response.getData();
    			  for (Record r : records ) {
    				  MenuItem mi = new MenuItem(r.getJsObj());
    				  mi.setDynamicTitleFunction(new MenuItemStringFunction() {
    					public String execute(Canvas target, Menu menu, MenuItem item) {
    						return item == null ? "null" : "not null";
    					}
    				  });
    				  mCategory.addItem(mi);
    			  }
    			}
    		});
            
            mCategory.addItemClickHandler(new ItemClickHandler() {  
                public void onItemClick(ItemClickEvent event) {  
                    MenuItem item = event.getItem();  
                    SC.say(item.getAttributeAsString("someOtherColumn"));  
                }  
            });  
      
            IMenuButton bCategory = new IMenuButton("Go to category", mCategory);  
            
            
            main.addChild(bCategory);  
            main.draw();  
        }
    SmartGWT eval 2.5-NIGHTLY-2011-03-16

    #2
    I meant to try it this way before I posted but it somehow slipped my mind.

    If I change the menuItem construction from
    Code:
    MenuItem mi = new MenuItem(r.getJsObj());
    to
    Code:
    MenuItem mi = new MenuItem("foo");
    String[] fields = r.getAttributes();
    for (String field : fields) {
        mi.setAttribute(field, r.getAttribute(field));
    }
    MenuItem is not null in the callback.

    Comment

    Working...
    X