You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by Eric Fesler <er...@hubmethods.com> on 2001/06/08 14:50:25 UTC

Multiple request parameter for the html:link tag

In a recent project, we had to face quite often the fact that we wanted to
use a <html:link> tag with multiple request parameters. I know that this tag
allows the use of a Map with all the parameters. However, we found its usage
quite difficult specially when the <html:link<> tag was embedded in a
<logic:iterate> tag and when the request parameters were dynamic.

So I write an extension to the <html:link> tag so that we can add parameter
tags in its body. Actually, I have rewrite the <html:link> tag because the
new tag had to extend BodyTagSupport and not TagSupport.

I have hereby attached both tags (the link tag and the linkparam tag) if
somebody is interested. I let you decide to put them in the standard Struts
core functionality (I would be very happy :-))) ).

The link tag works exactly the same as the standard struts tag. The
linkparam tag does not include the Struts philosophy (I mean being able to
refer directly to a bean and its properties for the value) but the
attributes could be computed at runtime.

Here is an example (too simple to be representative) of use:

<hm:link href="request.do">
    <hm:paramlink name="action" value="read" />
    <hm:paramlink name="docref" value="55363" />
    This is the link for the request.
</hm:link>



Eric



Re: Multiple request parameter for the html:link tag

Posted by Oleg V Alexeev <go...@penza.net>.
Hello Eric,

Friday, June 08, 2001, 4:50:25 PM, you wrote:

EF> In a recent project, we had to face quite often the fact that we wanted to
EF> use a <html:link> tag with multiple request parameters. I know that this tag
EF> allows the use of a Map with all the parameters. However, we found its usage
EF> quite difficult specially when the <html:link<> tag was embedded in a
EF> <logic:iterate> tag and when the request parameters were dynamic.

Good idea.

EF> So I write an extension to the <html:link> tag so that we can add parameter
EF> tags in its body. Actually, I have rewrite the <html:link> tag because the
EF> new tag had to extend BodyTagSupport and not TagSupport.

EF> I have hereby attached both tags (the link tag and the linkparam tag) if
EF> somebody is interested. I let you decide to put them in the standard Struts
EF> core functionality (I would be very happy :-))) ).

EF> The link tag works exactly the same as the standard struts tag. The
EF> linkparam tag does not include the Struts philosophy (I mean being able to
EF> refer directly to a bean and its properties for the value) but the
EF> attributes could be computed at runtime.

EF> Here is an example (too simple to be representative) of use:

EF> <hm:link href="request.do">
EF>     <hm:paramlink name="action" value="read" />
EF>     <hm:paramlink name="docref" value="55363" />
EF>     This is the link for the request.
EF> </hm:link>

Tag in your sample uses static values only - may be more flexible
approach is to use such construction as -

 <hm:link href="request.do">
     <hm:paramlink name="action" value="read" />
     <hm:paramlink name="docref" sourceName="doc" sourceProperty="ref" />
     This is the link for the request.
 </hm:link>

 sourceName - name of the bean and sourceProperty is property name to
 retrieve value of docref parameter.

-- 
Best regards,
 Oleg                            mailto:gonza@penza.net



RE: Multiple request parameter for the html:link tag

Posted by Eric Fesler <er...@hubmethods.com>.
Hi Ted,

here follows a example of the tag usage with iterate.
We assume that there is a collection ('catalog') of Book bean available in
the page context. A book bean has 3 properties: a title, a publisher and a
reference at the publisher (I know it exists a unique book reference names
ISBN but this is just an example - ;-) )

A catalog list can be implemented as follow:

<ul>
<logic:iterate id="book" name="catalog" type="Book">
<li>
	<hm:link href="http://myserver/order.do">
		<hm:linkparam name="publisher" value="<%= book.getPublisher() %>" />
		<hm:linkparam name="reference" value="<%= book.getReference() %>" />
		<bean:write name="book" property="title" />
	</hm:link>
</li>
</logic:iterate>
</ul>

This would generate a list of lines like:

<li><a
href="http://myserver/order.do?publisher=apublisher&reference=45553">The
title of the book</a>
</li>

Assuming the publisher property is 'apublisher' and reference property is
'45553'.

Of course there is a weak point in the example above: we used jsp scriplet
to initialize the parameter values.

I think that this could be improved by being able to refer directly to a
bean property as it is in most of the Struts tag.

However, in the meantime, I've made a little improvement to the linkparam
tag (new source attached) to be able to define the value in the body part of
the tag.

The example above would then become:

<ul>
<logic:iterate id="book" name="catalog" type="Book">
<li>
	<hm:link href="http://myserver/order.do">
		<hm:linkparam name="publisher">
			<bean:write name="book" property="publisher" />
		</hm:linkparam>
		<hm:linkparam name="reference">
			<bean:write name="book" property="reference" />
		<:hm:linkparam>
		<bean:write name="book" property="title" />
	</hm:link>
</li>
</logic:iterate>
</ul>

Personnaly, I found the later example better because there is not jsp
scriplet embedded in the jsp tags (something I usually try to avoid be able
to process my JSP through an XSL processor when I will find it usefull in
the future - to provide several interface layout).

Eric





> -----Message d'origine-----
> De : Ted Husted [mailto:husted@apache.org]
> Envoye : vendredi 8 juin 2001 17:41
> A : struts-dev@jakarta.apache.org
> Objet : Re: Multiple request parameter for the html:link tag
>
>
> An alternative to maps for multiple dynamic parameters would be helpful.
>
> Could you provide some representative examples of using the tag with
> iterate, and the HTML rendered?
>
> I imagine the one provide would generate
>
> <a href="request.do?action=read&docref=55363">This is the link for the
> rquest.</a>
>
> -- Ted Husted, Husted dot Com, Fairport NY USA.
> -- Custom Software ~ Technical Services.
> -- Tel 716 737-3463.
> -- http://www.husted.com/about/struts/
>
> > Eric Fesler wrote:
> > In a recent project, we had to face quite often the fact that we
> > wanted to use a <html:link> tag with multiple request parameters. I
> > know that this tag allows the use of a Map with all the parameters.
> > However, we found its usage quite difficult specially when the
> > <html:link<> tag was embedded in a <logic:iterate> tag and when the
> > request parameters were dynamic.
>
> > <hm:link href="request.do">
> >     <hm:paramlink name="action" value="read" />
> >     <hm:paramlink name="docref" value="55363" />
> >     This is the link for the request.
> > </hm:
>
>

Re: Multiple request parameter for the html:link tag

Posted by Ted Husted <hu...@apache.org>.
An alternative to maps for multiple dynamic parameters would be helpful. 

Could you provide some representative examples of using the tag with
iterate, and the HTML rendered?

I imagine the one provide would generate 

<a href="request.do?action=read&docref=55363">This is the link for the
rquest.</a>

-- Ted Husted, Husted dot Com, Fairport NY USA.
-- Custom Software ~ Technical Services.
-- Tel 716 737-3463.
-- http://www.husted.com/about/struts/

> Eric Fesler wrote:
> In a recent project, we had to face quite often the fact that we
> wanted to use a <html:link> tag with multiple request parameters. I
> know that this tag allows the use of a Map with all the parameters.
> However, we found its usage quite difficult specially when the
> <html:link<> tag was embedded in a <logic:iterate> tag and when the
> request parameters were dynamic.

> <hm:link href="request.do">
>     <hm:paramlink name="action" value="read" />
>     <hm:paramlink name="docref" value="55363" />
>     This is the link for the request.
> </hm: