You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Eric Jain <Er...@isb-sib.ch> on 2003/06/23 12:15:06 UTC
Building a link from a form
How does one build simple html links that contain all parameters from a
form?
There is of course the brute force method:
<c:url value="/search" var="url">
<c:param name="x" value="${form.x}"/>
<c:param name="y" value="${form.y}"/>
...
</c:url>
I assume there is a better way, something along the lines of
<html:link action="/search" property="form"/>
Any ideas?
--
Eric Jain
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: Building a link from a form
Posted by Eric Jain <Er...@isb-sib.ch>.
> How does one build simple html links that
> contain all parameters from a form?
Thanks for all your helpful replies...
Here is one solution:
request.setAttribute("param_map",
new HashMap(request.getParameterMap()));
<html:link action="/search" name="param_map">...</html:link>
Still, I'd prefer a pure JSP solution...
--
Eric Jain
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: Building a link from a form
Posted by Eric Jain <Er...@isb-sib.ch>.
> <html:link action="/search" name="<%= request.getParamerMap() %>">
> It'll blow up during page compilation.
Should have mentioned that I am using the html-el tags, where you can of
course do things such as
<html:link action="/search" name="param">...</html:link>
Sorry for the confusion!
--
Eric Jain
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: Building a link from a form
Posted by Kris Schneider <kr...@dotech.com>.
Not to beat the proverbial dead horse, but the "name" attribute is always a
String and it's used as a key to do a lookup of a scoped attribute. If you only
specify "name", then the bean stored under that key is used directly as the Map.
If you also specify "property", then the bean stored under that key is assumed
to expose a property of type Map. So, if you do something like:
<html:link action="/search" name="<%= request.getParamerMap() %>">
It'll blow up during page compilation.
Quoting Eric Jain <Er...@isb-sib.ch>:
> > The <html:link> "name" attribute is a key, not a Map instance.
>
> If you specify a 'name' but no 'property', it is in fact considered to
> be the map instance itself. Confusing indeed.
>
>
> > What is it you want done in JSP/XML?
>
> >>> <%@ page import="org.apache.commons.beanutils.PropertyUtils" %>
> >>> <jsp:useBean id="paramMap" class="java.util.HashMap"/>
> >>> <c_rt:forEach var="entry" items="<%= PropertyUtils.describe(form)
> >>> %>"> <c:set target="paramMap" property="${entry.key}"
> >>> value="${entry.value}"/> </c_rt:forEach>
> >>> <html:link action="/search" name="paramMap">
> >>> ...
> >>> </html:link>
>
>
> But never mind, the original problem is solved, so let's leave this one
> as an exercise for the students :-)
>
>
> --
> Eric Jain
--
Kris Schneider <ma...@dotech.com>
D.O.Tech <http://www.dotech.com/>
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: Building a link from a form
Posted by Eric Jain <Er...@isb-sib.ch>.
> The <html:link> "name" attribute is a key, not a Map instance.
If you specify a 'name' but no 'property', it is in fact considered to
be the map instance itself. Confusing indeed.
> What is it you want done in JSP/XML?
>>> <%@ page import="org.apache.commons.beanutils.PropertyUtils" %>
>>> <jsp:useBean id="paramMap" class="java.util.HashMap"/>
>>> <c_rt:forEach var="entry" items="<%= PropertyUtils.describe(form)
>>> %>"> <c:set target="paramMap" property="${entry.key}"
>>> value="${entry.value}"/> </c_rt:forEach>
>>> <html:link action="/search" name="paramMap">
>>> ...
>>> </html:link>
But never mind, the original problem is solved, so let's leave this one
as an exercise for the students :-)
--
Eric Jain
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: Building a link from a form
Posted by Kris Schneider <kr...@dotech.com>.
The <html:link> "name" attribute is a key, not a Map instance. If you want to
try to use the request's parameter map directly, I think you'd need something like:
<bean:page id="requestBean" property="request"/>
<html:link action="/search" name="requestBean" property="parameterMap">
...
</html:link>
Or:
<c:set var="paramMap" value="${paramValues}"/>
<html:link action="/search" name="paramMap">
...
</html:link>
What is it you want done in JSP/XML?
Quoting Eric Jain <Er...@isb-sib.ch>:
> > request.setAttribute("paramMap", PropertyUtils.describe(form));
>
> One issue with PropertyUtils.describe is that it also adds a property
> 'class' to the map; this would probably have to be removed explicitely.
>
>
> > For an all-JSP solution, I guess you could do:
> >
> > <%@ page import="org.apache.commons.beanutils.PropertyUtils" %>
> > <jsp:useBean id="paramMap" class="java.util.HashMap"/>
> > <c_rt:forEach var="entry" items="<%= PropertyUtils.describe(form) %>">
> > <c:set target="paramMap" property="${entry.key}"
> > value="${entry.value}"/> </c_rt:forEach>
> > <html:link action="/search" name="paramMap">
> > ...
> > </html:link>
>
> Now, next level: all-JSP/XML :-)
>
> It just occured to me that if none of the request parameters needs to be
> modified then the parameter map could probably be used directly:
>
> <html:link action="/search" name="param">
>
> --
> Eric Jain
--
Kris Schneider <ma...@dotech.com>
D.O.Tech <http://www.dotech.com/>
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: Building a link from a form
Posted by Eric Jain <Er...@isb-sib.ch>.
> request.setAttribute("paramMap", PropertyUtils.describe(form));
One issue with PropertyUtils.describe is that it also adds a property
'class' to the map; this would probably have to be removed explicitely.
> For an all-JSP solution, I guess you could do:
>
> <%@ page import="org.apache.commons.beanutils.PropertyUtils" %>
> <jsp:useBean id="paramMap" class="java.util.HashMap"/>
> <c_rt:forEach var="entry" items="<%= PropertyUtils.describe(form) %>">
> <c:set target="paramMap" property="${entry.key}"
> value="${entry.value}"/> </c_rt:forEach>
> <html:link action="/search" name="paramMap">
> ...
> </html:link>
Now, next level: all-JSP/XML :-)
It just occured to me that if none of the request parameters needs to be
modified then the parameter map could probably be used directly:
<html:link action="/search" name="param">
--
Eric Jain
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: Building a link from a form
Posted by Kris Schneider <kr...@dotech.com>.
If you've got an action that fronts the JSP, use something like:
request.setAttribute("paramMap", PropertyUtils.describe(form));
to dump a map of all the form properties into request scope. Then, in the JSP:
<html:link action="/search" name="paramMap">
...
</html:link>
For an all-JSP solution, I guess you could do:
<%@ page import="org.apache.commons.beanutils.PropertyUtils" %>
<jsp:useBean id="paramMap" class="java.util.HashMap"/>
<c_rt:forEach var="entry" items="<%= PropertyUtils.describe(form) %>">
<c:set target="paramMap" property="${entry.key}" value="${entry.value}"/>
</c_rt:forEach>
<html:link action="/search" name="paramMap">
...
</html:link>
Quoting Eric Jain <Er...@isb-sib.ch>:
> How does one build simple html links that contain all parameters from a
> form?
>
> There is of course the brute force method:
>
> <c:url value="/search" var="url">
> <c:param name="x" value="${form.x}"/>
> <c:param name="y" value="${form.y}"/>
> ...
> </c:url>
>
> I assume there is a better way, something along the lines of
>
> <html:link action="/search" property="form"/>
>
> Any ideas?
>
>
> --
> Eric Jain
--
Kris Schneider <ma...@dotech.com>
D.O.Tech <http://www.dotech.com/>
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org