You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Patrick Casey <pa...@adelphia.net> on 2005/04/17 22:54:38 UTC

Code Generated Links

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: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


RE: Code Generated Links

Posted by Patrick Casey <pa...@adelphia.net>.
	Thanks Paul, worked like a champ.

	--- Pat

-----Original Message-----
From: Paul Ferraro [mailto:pmf8@columbia.edu] 
Sent: Sunday, April 17, 2005 2:41 PM
To: Tapestry users
Subject: Re: Code Generated Links

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
<snip>



---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: Code Generated Links

Posted by Paul Ferraro <pm...@columbia.edu>.
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: tapestry-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>  
>


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org