You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by "Mayne, Peter" <Pe...@ap.spherion.com> on 2003/06/16 01:28:50 UTC

Building dynamic links with client-side JavaScript

I'm trying to use the tree menu at http://www.treemenu.com/ to build a
client-side menu. This is done by using JavaScript code in the browser:

menu = new MTMenu();
menu.addItem('Item1');
sub = new MTMenu();
sub.addItem('subItem1', url1);
sub.addItem('subItem2', url2);
menu.makeLastSubmenu(sub);

The catch is figuring out what the URLs are. The additem() method takes a
URL and builds an <a> by hand.

Currently I'm doing this to let Tapestry build an <a>, then extract the URL
from it:

function undoHref(a)
{
  var p = a.indexOf('"');
  var q = a.indexOf('"', p+1);
  var href = a.slice(p+1, q);
  return href;
}

pg  = undoHref('<a jwcid="@PageLink" page="ThePage">text</a>');
sub.addItem("subItem3", pg);

Tapestry doesn't seem to mind that the link in a string in a script.
However, this seems rather awkward.

I've looked for a way of just generating a URL for a page, but can't find
one (which may just mean I haven't looked hard enough). Is there a better
way of integrating client-side script and URL generation with Tapestry?

Thanks.

PJDM
-- 
Peter Mayne
Technology Consultant
Spherion Technology Solutions
Level 1, 243 Northbourne Avenue, Lyneham, ACT, 2602
T: 61 2 62689727  F: 61 2 62689777

The information contained in this email and any attachments to it:

(a) may be confidential and if you are not the intended recipient, any interference with, 
use, disclosure or copying of this material is unauthorised and prohibited; and

(b) may contain personal information of the recipient and/or the sender as defined 
under the Privacy Act 1988 (Cth). Consent is hereby given by the recipient(s) to 
collect, hold and use such information and any personal information contained in a 
response to this email, for any reasonable purpose in the ordinary course of 
Spherion's 
business, including forwarding this email internally or disclosing it to a third party. All 
personal information collected by Spherion will be handled in accordance with 
Spherion's Privacy Policy. If you have received this email in error, please notify the 
sender and delete it.

(c) you agree not to employ or arrange employment for any candidate(s) supplied in 
this email and any attachments without first entering into a contractual agreement with 
Spherion. You further agree not to divulge any information contained in this document 
to any person(s) or entities without the express permission of Spherion.