You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by andy wix <st...@hotmail.com> on 2004/08/30 22:03:37 UTC
Identifying the 'clicked' line when iterating over collection
Hi,
In my jsp page I have an ArrayList of contact objects and I use this to
build an html table; one contact per row. At the end of each table row I
have edit and delete links such that the form looks roughly like:
Name Number
Fred 1234 edit delete
Barney 2345 edit delete
What's the best way to identify which link was clicked?
I know I can make each link name unique by using the index used to iterate
through the collection and assign this to the link ID. Then (if I knew how)
I could get JavaScript to identify which link was selected and add this to
the request/session. Does Struts have a 'posher' way of doing this and, if
not, does anyone have the JavaScript required?
Cheers,
Andy
_________________________________________________________________
Want to block unwanted pop-ups? Download the free MSN Toolbar now!
http://toolbar.msn.co.uk/
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Identifying the 'clicked' line when iterating over collection
Posted by Rick Reumann <st...@reumann.net>.
benanderson@benanderson.us wrote:
> It sounds like you want to attach parameters to your link? How bout something
> like this:
> <jsp:useBean id="paramMap" class="java.util.HashMap"/>
> ...
> <c:forEach ... >
> <c:set target="${paramMap}" property="reasonCode" value="${row.reasonCode}"/>
> ...
> <html-el:link action="some/action" name="paramMap"/>
The above is nice, or I just use the JSTL url tag so for a row you might
have (if using one dispatch Action called contactAction ) ...
<c:url var="url" scope="page" value="/conatctAction.do">
<c:param name="ID" value="${yourForm.rowObject.id}"/>
</c:url>
<a href="<c:out value='${url}'/>&userAction=edit">EDIT</a>
<a href="<c:out value='${url}'/>&userAction=delete">DELETE</a>
or if JSP 2.0
<a href="${url}&userAction=edit">EDIT</a>
(Note: struts 1.2 MappingDispatch action could work as well slightly
modified. I haven't used it yet, but it looks great)
--
Rick
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Identifying the 'clicked' line when iterating over collection
Posted by be...@benanderson.us.
It sounds like you want to attach parameters to your link? How bout something
like this:
<jsp:useBean id="paramMap" class="java.util.HashMap"/>
...
<c:forEach ... >
<c:set target="${paramMap}" property="reasonCode" value="${row.reasonCode}"/>
...
<html-el:link action="some/action" name="paramMap"/>
Quoting andy wix <st...@hotmail.com>:
> Hi,
> In my jsp page I have an ArrayList of contact objects and I use this to
> build an html table; one contact per row. At the end of each table row I
> have edit and delete links such that the form looks roughly like:
>
> Name Number
> Fred 1234 edit delete
> Barney 2345 edit delete
>
> What's the best way to identify which link was clicked?
> I know I can make each link name unique by using the index used to iterate
> through the collection and assign this to the link ID. Then (if I knew how)
> I could get JavaScript to identify which link was selected and add this to
> the request/session. Does Struts have a 'posher' way of doing this and, if
> not, does anyone have the JavaScript required?
>
> Cheers,
> Andy
>
> _________________________________________________________________
> Want to block unwanted pop-ups? Download the free MSN Toolbar now!
> http://toolbar.msn.co.uk/
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org