type MenuBar or MenuItem with addClickHandler(new ClickHandler()

1,076 views
Skip to first unread message

Assiya EL

unread,
Jul 5, 2012, 9:11:14 AM7/5/12
to google-we...@googlegroups.com

hi all,

i have a problem with  MenuBar or MenuItem , addClickHandler(new ClickHandler()

i can't add a event in my MenuItem or  MenuBar ???

any idea PLZ


-- 
 
Assiya EL
Master Qualité du Logiciel 



Plz consider environment - Only print this if necessary


Jens

unread,
Jul 5, 2012, 9:56:42 AM7/5/12
to google-we...@googlegroups.com
You have to use the Command interface. A Command will be executed then a MenuItem is activated. See JavaDoc for MenuBar/MenuItem.

-- J.

Ali Thabet

unread,
Jul 5, 2012, 9:58:41 AM7/5/12
to google-we...@googlegroups.com
Form MenuItem i set the command witch execute the same code of the ClickHandler. why you want tu add a ClickHandler to the MenuBar?

2012/7/5 Jens <jens.ne...@gmail.com>
You have to use the Command interface. A Command will be executed then a MenuItem is activated. See JavaDoc for MenuBar/MenuItem.

-- J.

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/1o_U4YFxWbEJ.

To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

Assiya EL

unread,
Jul 5, 2012, 10:00:17 AM7/5/12
to google-we...@googlegroups.com
hi ,

thank you for your reply but my problem it is not just a message error !!!!

i have a function with parameter like that :

public MenuBar generateMenuBar(List<Menu> menuBeanList , final Long id) {   //  function execute can't have a parameters , you see ??

MenuBar menuBarPrincipale = new MenuBar();     or  MenuItem 
 menuBarPrincipale.addClickHandler(new ClickHandler() {   // here i have a problem :( :( 

@Override
public void onClick(ClickEvent event) {
GreetingServiceAsync greetingService = GWT.create(GreetingService.class);

greetingService.loadCategoryPage(id,new AsyncCallback<GridPageModel>() {

@Override
public void onFailure(Throwable caught) {
}

@Override
public void onSuccess(GridPageModel grid) {

GridPageBuilder.build(grid);

}
});
}
});

2012/7/5 Ali Thabet <thabet...@gmail.com>

Assiya EL

unread,
Jul 5, 2012, 10:00:01 AM7/5/12
to google-we...@googlegroups.com
hi  ,

thank you for your reply but my problem it is not just a message error !!!!

i have a function with parameter like that :

public MenuBar generateMenuBar(List<Menu> menuBeanList , final Long id) {   //  function execute can't have a parameters , you see ??

MenuBar menuBarPrincipale = new MenuBar();     or  MenuItem 
 menuBarPrincipale.addClickHandler(new ClickHandler() {   // here i have a problem :( :( 

@Override
public void onClick(ClickEvent event) {
GreetingServiceAsync greetingService = GWT.create(GreetingService.class);

greetingService.loadCategoryPage(id,new AsyncCallback<GridPageModel>() {

@Override
public void onFailure(Throwable caught) {
}

@Override
public void onSuccess(GridPageModel grid) {

GridPageBuilder.build(grid);

}
});
}
});

2012/7/5 Jens <jens.ne...@gmail.com>
You have to use the Command interface. A Command will be executed then a MenuItem is activated. See JavaDoc for MenuBar/MenuItem.

-- J.

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/1o_U4YFxWbEJ.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

Ali Thabet

unread,
Jul 5, 2012, 10:03:41 AM7/5/12
to google-we...@googlegroups.com
But the command can have fields so you must create your command class witch implements the Command interface and put your parameters in the constructor to set fields

Assiya EL

unread,
Jul 5, 2012, 10:08:13 AM7/5/12
to google-we...@googlegroups.com
thank you , you have an example of class Command  PLZ ?

2012/7/5 Ali Thabet <thabet...@gmail.com>
But the command can have fields so you must create your command class witch implements the Command interface and put your parameters in the constructor to set fields

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

Ali Thabet

unread,
Jul 5, 2012, 10:16:32 AM7/5/12
to google-we...@googlegroups.com
class MyCommand implements Command
   {
      private String _id;

      public MyCommand(String id)
      {
         _id = id;
      }

      @Override
      public void execute()
      {
         GreetingServiceAsync greetingService = GWT.create(GreetingService.class);

         greetingService.loadCategoryPage(_id,new AsyncCallback<GridPageModel>() {

             @Override
             public void onFailure(Throwable caught) {
             }

             @Override
             public void onSuccess(GridPageModel grid) {

                 GridPageBuilder.build(grid);

             }
         });

      }
   }
   
   public void addItemToMenuBar(MenuBar menuBar)
   {
      menuBar.addItem("firstItem", new MyCommand("firstId"));
      menuBar.addItem("secondItem", new MyCommand("secondId"));
   }

Assiya EL

unread,
Jul 5, 2012, 10:42:33 AM7/5/12
to google-we...@googlegroups.com
Okey thank you so much 

2012/7/5 Ali Thabet <thabet...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

Assiya EL

unread,
Jul 8, 2012, 7:30:58 AM7/8/12
to google-we...@googlegroups.com
hello,

_id in the constructor is compile but returns null after the click on the menu, I think we should pass it to paramettrs function which is calling server in this case it is execute , it is possible to add a event to menu with other solution ?


thank you

2012/7/5 Ali Thabet <thabet...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

Vivek Ghavle

unread,
Jul 5, 2012, 9:19:47 AM7/5/12
to google-we...@googlegroups.com
Hi Assiya,
no need to use handlers there
you can use the below code


MenuItem mntmNewItem = new MenuItem("Vivek", false, new Command() {
            public void execute() {
               
        Window.alert("Hi Vivek");
               
            }
        });
        menuBar.addItem(mntmNewItem);



Hope this code will satisfy your need

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.



--
Regards
Vivek Ghavle

Assiya EL

unread,
Jul 10, 2012, 5:24:18 PM7/10/12
to google-we...@googlegroups.com
Hi Vivek ,

but i want to  add a parameter in my function execute it is possible ?

2012/7/5 Vivek Ghavle <vivek...@gmail.com>
Reply all
Reply to author
Forward
0 new messages