You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Wojtek Ciesielski <cc...@interia.pl> on 2007/04/04 12:12:49 UTC

So a simple question in place of earlier one...

Hi can I obtain full textual (ie. as a String) URL to a page with some 
parameters? Let's say that I have a page PageBeingCalled with a string 
property:

public class PageBeingCalled extends BasePage {
   public abstract void setMyProperty(String prop);
   public abstract String getMyProperty();

   ....
}

I want to call that page using JavaScript. Within a page that is calling 
the one above I can do something like:

@InjectPage("PageBeingCalled")
public abstract PageBeingCalled getCalledPage();

public String getJsLink() {
   PageBeingCalled pbc = getCalledPage();
   pbc.setMyProperty("some value I need");
   String jsLink = ............. // what should I put here??
   return jsLink;
}


What service (as I expect that is needed) should I get to perform 
encoding? How to perform it?

Any help would be greatly appreciated.

Wojtek

----------------------------------------------------------------------
Wideofelietony Tadeusza Mosza.
O biznesie dla wszystkich. Oglądaj >> http://link.interia.pl/f1a3c


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


Re: So a simple question in place of earlier one...

Posted by Wojtek Ciesielski <cc...@interia.pl>.
Sam Gendler wrote:
> Generally, you would make sure the page implements the IExternalPage
> interface.  That allows you to specify parameters in a link and
...
> 
> --sam


Thanks a lot

Wojtek

----------------------------------------------------------------------
Wideofelietony Tadeusza Mosza.
O biznesie dla wszystkich. Oglądaj >> http://link.interia.pl/f1a3c


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


Re: So a simple question in place of earlier one...

Posted by Sam Gendler <sg...@ideasculptor.com>.
Generally, you would make sure the page implements the IExternalPage
interface.  That allows you to specify parameters in a link and
receive them when the page is activated.  If you just need to generate
the URL, you can create an instance of an ILink via the
ExternalService and then get the URL from the Link and pass that to
your js.  It is quite a bit more complicated than it probably should
be, and I absolutely hate that it breaks the standard
?name=value&name=value structure of a normal HTTP query string, but it
does work.  Not having named parameters really makes life awkward when
you want to be able to call a page with varying sets of parameters.
You have to maintain a certain parameter order or else you have to
include an identifying parameter at the start of the parameters array
which will allow parameter parsing code to know the incoming order.

Basically, any page that you want to be able to access directly from a
URL must implement the IExternalPage interface is you want to be able
to pass it parameters.  The IExternalPage interface requires that all
parameters are passed to it as an Object[].  The ExternalService will
call activateExternalPage() with you array of params when the page is
activated by that service.  You can then take actions based on the
params that are passed in.  You can use an ExternalLink component to
generate links to the page in your html, or you can get a URL in java
code by getting an ILink from the ExternalService and calling getUrl()
on it.  You specify the array of params when you retrieve the ILink
from the service.  If you need access to such a URL from javascript,
you will almost certainly have to generate the js from a .script
template, so that you can pass the URL in as a parameter.  Finally,
creating parameters on the fly within javascript can be difficult
because you must encode each parameter with its type - ie the string
"hello" would be encoded as Shello, etc.

Its a lot of work, but making sure all of your pages can be opened in
any state via an ExternalLink has a lot of advantages, since it can
allow you to redirect after post operations, and if you use ajax
updates to a page, it allows you to modify back button behaviour so
that the back button will step back through each stage that a page has
passed through.

Finally, you can write a custom URL encoder/decoder which will do
nifty things like place parameters into the path rather than using the
ugly urls that tapestry uses by default.

http://my.app.com/app?page=ShowItem&service=external&sp=1234

can become

http://my.app.com/ShowItem.page/1234

--sam


On 4/4/07, Wojtek Ciesielski <cc...@interia.pl> wrote:
> Hi can I obtain full textual (ie. as a String) URL to a page with some
> parameters? Let's say that I have a page PageBeingCalled with a string
> property:
>
> public class PageBeingCalled extends BasePage {
>    public abstract void setMyProperty(String prop);
>    public abstract String getMyProperty();
>
>    ....
> }
>
> I want to call that page using JavaScript. Within a page that is calling
> the one above I can do something like:
>
> @InjectPage("PageBeingCalled")
> public abstract PageBeingCalled getCalledPage();
>
> public String getJsLink() {
>    PageBeingCalled pbc = getCalledPage();
>    pbc.setMyProperty("some value I need");
>    String jsLink = ............. // what should I put here??
>    return jsLink;
> }
>
>
> What service (as I expect that is needed) should I get to perform
> encoding? How to perform it?
>
> Any help would be greatly appreciated.
>
> Wojtek
>
> ----------------------------------------------------------------------
> Wideofelietony Tadeusza Mosza.
> O biznesie dla wszystkich. Oglądaj >> http://link.interia.pl/f1a3c
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>