Try this:
Have your MenuBuilder component implement IDirect.
IRequestCycle cycle = this.getPage().getRequestCycle();
Object[] parameters = new Object[] { menuItem }; // Here is where you would indicate the menu item
String url = cycle.getEngine().getService(Tapestry.DIRECT_SERVICE).getLink(cycle, this, parameters).getURL();
The link will fire the trigger(IRequestCycle cycle) method of your IDirect object.
Does that answer your question?
Paul
Patrick Casey wrote:
Hi Folks,
Yet another (hopefully) simple question.
I have a component on my form which uses javascript to build a spiffy tree view. The actual "tree" is built by building some javascript on the fly inside the component. Here's a snipped of code from the component's getMenu() method that should give you an idea of what I mean.
public String getMenu() { // debug StringWriter sw = new StringWriter(); PrintWriter w = new PrintWriter(sw); w.println("USETEXTLINKS = 1;"); w.println("STARTALLOPEN = 0;"); w.println("ICONPATH = '/Corinna/menu/';"); w.println("foldersTree = gFld('Menu Tree', '');"); w.println("aux1 = insFld(foldersTree, gFld('Tapestry Demo', ''));"); w.println("insDoc(aux1 , gLnk('R', 'Dictionary', '***Link to dictionary dictionary***'));"); w.println("insDoc(aux1 , gLnk('R', 'Dictionary', 'http://www.cnn.com'));"); return sw.toString(); }
The gotcha with this approach is that my java code (above), which is writing javascript code, has to embed the links it wants on the menu inside the javascript as string literals (the section marked '*** Link to dictionary ***'). See the second link where I link to cnn.com as an example of what it looks like when it works :).
I can't for the life of me though figure out how to generate a tapestry link on the fly here. I don't actually want to go out to cnn when the user selects something off the menu. Instead I want tapestry to handle the menu event and respond to it, but I can't figure out how to build a link back to tapestry here.
All I really want to do is embed a link to a generic "menu listener" with a parameter referencing which menu item was selected. From there I'm quite comfortable cycling to a new page.
Any suggestions (or an alternate approach if that's a better way to go), would be appreciated.
--- Pat
PS In case it's not clear how the above relates to tapestry, here's the menu component and it's html.
<component-specification class="presentation.MenuBuilder" allow-body="yes"
allow-informal-parameters="yes">
<context-asset name="ua_js" path="/menu/ua.js"/>
<context-asset name="ftiens4_js" path="/menu/ftiens4.js"/> <component id="uaScript" type="Any">
<static-binding name="element" value="script"/>
<binding name="src" expression="assets.ua_js"/>
</component>
<component id="fScript" type="Any">
<static-binding name="element" value="script"/>
<binding name="src" expression="assets.ftiens4_js"/>
</component> </component-specification>
<span jwcid="$content$">
<body jwcid="@Body">
<script jwcid="uaScript" language="JavaScript"
type="text/javascript"/> <script jwcid="fScript" language="JavaScript"
type="text/javascript"/> <script>
<span jwcid="@Insert" value="ognl:Menu" />
</script>
</body>
</span>
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
