You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Henrik Schlanbusch <he...@intermedia.uib.no> on 2005/04/13 16:09:09 UTC

Passing parameters with tapestry

Hi, I have tried to find an aswer to this for a 
long time now, but cannot find it.

A form can submit parameters and bind the submitted 
values directly to the page
class. Is this possible with a link as well??

I would like to send the parameter "username" 
when i trigger a link in my html
page. 
In my listener method I do *not* want to use the 
getServiceParameters()
array and "guess" which index my username parameter is located. 
I would like to
do one of the two following:

1. the setUsername(String username) has been invoked on 
my javapage before the
listener method has been called. 
By doing this I can program as i normally do by
calling getUsername in my listenermethod

2. if the above is absolutely not possible. 
I would like to have some way of
retrieving a parameter by its name from the requestcycle object.

Can anybody help me a bit on the way here???!!??

In Struts, it was fairly simple to extract parameters and values from the
request, 
I hope and guess this is extremely simple in tapestry as well, but I
simply cannof find the solution!

Henrik




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


Re: Passing parameters with tapestry

Posted by Erik Hatcher <er...@ehatchersolutions.com>.
On Apr 13, 2005, at 10:09 AM, Henrik Schlanbusch wrote:
> Hi, I have tried to find an aswer to this for a
> long time now, but cannot find it.
>
> A form can submit parameters and bind the submitted
> values directly to the page
> class. Is this possible with a link as well??
>
> I would like to send the parameter "username"
> when i trigger a link in my html
> page.
> In my listener method I do *not* want to use the
> getServiceParameters()
> array and "guess" which index my username parameter is located.
> I would like to
> do one of the two following:

You are not alone in your desire here.  I've been ranting and raving 
about this topic for a while now.  Look at the recent archives in the 
past month about my work with a custom ParamLink component.  It's not 
quite what you're asking for, rather it makes clean named parameters on 
the URL and sends a Map into the listener as the first parameter with 
those names as keys.

I do like the idea of having the names correspond to properties on the 
page and set them.  It would be pretty easy to create a custom service 
that would do that.

> 1. the setUsername(String username) has been invoked on
> my javapage before the
> listener method has been called.
> By doing this I can program as i normally do by
> calling getUsername in my listenermethod
>
> 2. if the above is absolutely not possible.
> I would like to have some way of
> retrieving a parameter by its name from the requestcycle object.
>
> Can anybody help me a bit on the way here???!!??

My ParamLink does #2.  It's not ready for addition back to Tapestry, as 
I'd like to have an even more general purpose link component that frees 
us from having to know the details about PageLink, ExternalLink, 
DirectLink, etc, etc.

Keep in mind that you can simply pull named parameters from the 
request.  I do this to achieve nice URL's in many cases.

> In Struts, it was fairly simple to extract parameters and values from 
> the
> request,
> I hope and guess this is extremely simple in tapestry as well, but I
> simply cannof find the solution!

Such direct mapping, though, can be the cause of issues.  In #1, What 
if you have properties on a page that should not be set by the URL?  
You've now given hackers a way to set things that shouldn't be settable 
from the outside.

	Erik


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


Re: Passing parameters with tapestry

Posted by Nathan Kopp <nk...@mailshell.com>.
Ahhh... now that it is morning, let me try to answer that question a little
better...

> > 1. the setUsername(String username) has been invoked on
> > my javapage before the
> > listener method has been called.
> > By doing this I can program as i normally do by
> > calling getUsername in my listenermethod
>
> This is really easy if you use an "ActionLink".  See the component
> reference:
> http://jakarta.apache.org/tapestry/doc/ComponentReference/ActionLink.html

ActionLink works well if your setters/getters are going to be called
automatically during the rewind (replay) cycle, as shown in the example.
Often this will only work with persistent page properties or when you're
using properties of your visit, which means it is probably not what your
looking for.

What you might be looking for, though, is a link component that sumbits a
form that contains hidden inputs.  If so, try this:
http://jakarta.apache.org/tapestry/doc/ComponentReference/LinkSubmit.html

Note that with both of these you allow Tapestry to generate and read the
parameters for you and bind them into your object properties.

> > 2. if the above is absolutely not possible.
> > I would like to have some way of
> > retrieving a parameter by its name from the requestcycle object.
>
> You can go straight to the HttpServletRequest if you want, but you might
> find it difficult to determine the parameter name that you want to read.

If you are, instead, coming from an external source where you want to (or
must) manually control the parameter names, then you might want to use this
approach.  The HttpServletRequest can be accessed by calling
cycle.getRequestContext().getRequest().

Hopefully this helps a little bit more.

-Nathan Kopp


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


Re: Passing parameters with tapestry

Posted by Nathan Kopp <nk...@mailshell.com>.
> 1. the setUsername(String username) has been invoked on
> my javapage before the
> listener method has been called.
> By doing this I can program as i normally do by
> calling getUsername in my listenermethod

This is really easy if you use an "ActionLink".  See the component
reference:
http://jakarta.apache.org/tapestry/doc/ComponentReference/ActionLink.html

> 2. if the above is absolutely not possible.
> I would like to have some way of
> retrieving a parameter by its name from the requestcycle object.

You can go straight to the HttpServletRequest if you want, but you might
find it difficult to determine the parameter name that you want to read.

-Nathan


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