Is there an example how to change the text of a menu item every time the menu was clicked.
I already tried the setTitle method in the onClick method of the ClickHandler but the text won’t change. I also tried setDynamicTitleFunction but the execute method was never called.
This is the part where I create the MenuItem and set the setDynamicTitleFunction method. I only see the text that I use in the Constructor of MenuItem, the execute methode is never called.
Maybe I have a probelm understanding the mechanism behind this. When and from where is the execute method of the MenuItemStringFunction called?
The text should change everytime the onClick Method of the ClickHandler is called.
final MenuItem activateMenu = new MenuItem( "Activate" );
activateMenu.setDynamicTitleFunction( new MenuItemStringFunction() {
public String execute( final Canvas aTarget, final Menu aMenu, final MenuItem aItem ) {
System.out.println( "execute called" );
if ( ddiVh.isUseBlacklist() ) {
return "De-Activate Blacklist";
}
else {
return "Activate Blacklist";
}
}
} );
activateMenu.addClickHandler( new ClickHandler() {
public void onClick( final MenuItemClickEvent event ) {
processStateChangeEvent();
}
} );
and each time I click the “File” MenuButton, the activateMenu’s dynamic function is invoked as expected and the String returned is the new MenuItem title.
I tried this on the latest build but nothing related to this has changed since 1.0b1. Which build are you using?
If you’re still having troubles, please post a simple standalone testcase.
Thanks,
Sanjiv
final MenuItem activateMenu = new MenuItem("Activate");
activateMenu.setDynamicTitleFunction(new MenuItemStringFunction() {
public String execute(final Canvas aTarget, final Menu aMenu, final MenuItem aItem) {
System.out.println("execute called");
if (Math.random() > 0.5) {
return "De-Activate Blacklist";
} else {
return "Activate Blacklist";
}
}
});
I can confirm this bug too. Sorry I don’t have any sample code to post but I suspect it has something to do with menuitems that are added to the menu dynamically (i.e. for example as a result of user action).
I tested this with a menu which is initialized normally and made visible and it works (as in showcase). But I have some code that fetches data from server with datasource and manually builds proper menuitems from the data returned from the server and after this this method is never called. Even if it’s identically set as in the former case.
This with gwt 2.0.4 + smartgwt lgpl 2.3 2010-10-08 nightly build.