tags:

views:

241

answers:

1

I'm try to upgrade my project using tapestry4 to tapestry5. And I'm looking for a component to use JSCookMenu in tapestry5.

A: 

Were you using JSCookMenu in Tapestry 4? What exactly do you need? If it's just the links that the menu options need to have to invoke code in your T5 pages, then you should inject a ComponentResources into your page so you can create the links you need and add them to a javascript fragment on the page. You can add the Javascript to create the menu variable and the invocation to cmDraw inside the setupRender() method of your page, using an injected RenderSupport instance, for example:

@Environmental
private RenderSupport renderSupport;
@Inject
private ComponentResources resources;

void setupRender() {
  renderSupport.addScript("var myMenu = [ ['icon', 'title', '%s', 'target', 'desc'], ['icon', 'title', '%s', 'target', 'desc'] ];",
    resources.createEventLink("event1"), resources.createEventLink("event2"));
  renderSupport.addScript("cmDraw('menuID', myMenu, 'hbr', cmThemeOffice);");
}

public void onEvent1() {
  //this method gets called from the first option
}
public void onEvent2() {
  //this method gets called from the second option
}

To include the JSCookMenu.js file in your page, add an annotation to your page class:

@IncludeJavaScriptLibrary("JSCookMenu.js")
public class MyPage {...}

The JSCookMenu.js need to be added as an asset to your T5 application.

Chochos