You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Zimmerman, Steven R." <sr...@DOC1.WA.GOV> on 2003/09/18 22:45:16 UTC
html:link question (for a relative newbie)
I cannot seem to get this to work
<html:link
page="/collaborator.do?mode=edit&code=<%=code%>">Edit</html:link>
or better yet this instead
<html:link
action="collaborator.do?mode=edit&code=<%=code%>">Edit</html:link>
but the <%=code%> is not picking up the value of "code", instead it is
putting "<%=code%>" in its place. That all makes sense why, but is there a
way I can get at a expression using Struts tags like I can using the code
below with a hard coded HREF ('cuse it works fine there but is not what I
want).
<A href="logon.jsp?task=delete&code=<%=code%>">Delete</A>
All else works fine, I realize that I could be chaining actions or some
other "do not do" but I am under a bit of a time crunch (as always... :).
TIA, Steve
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: html:link question (for a relative newbie)
Posted by de...@betterway.net.
A quick hack you can do is:
<%java.util.HashMap ha = new java.util.HashMap(); ha.put("mode","edit");
ha.put("code", code); pageContext.setAttribute("linkParams",ha);%>
<html:link href="collaborator.do" name="linkParams">Edit</html:link>
I usually build my link hashmap in the setup action for the jsp, but you can
do this.
----- Original Message -----
From: "Zimmerman, Steven R." <sr...@DOC1.WA.GOV>
To: <st...@jakarta.apache.org>
Sent: Thursday, September 18, 2003 4:45 PM
Subject: html:link question (for a relative newbie)
> I cannot seem to get this to work
> <html:link
> page="/collaborator.do?mode=edit&code=<%=code%>">Edit</html:link>
>
> or better yet this instead
> <html:link
> action="collaborator.do?mode=edit&code=<%=code%>">Edit</html:link>
>
> but the <%=code%> is not picking up the value of "code", instead it is
> putting "<%=code%>" in its place. That all makes sense why, but is there
a
> way I can get at a expression using Struts tags like I can using the code
> below with a hard coded HREF ('cuse it works fine there but is not what I
> want).
> <A href="logon.jsp?task=delete&code=<%=code%>">Delete</A>
>
> All else works fine, I realize that I could be chaining actions or some
> other "do not do" but I am under a bit of a time crunch (as always... :).
> TIA, Steve
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: html:link question (for a relative newbie)
Posted by Joe Germuska <Jo...@Germuska.com>.
At 13:45 -0700 9/18/03, Zimmerman, Steven R. wrote:
>I cannot seem to get this to work
> <html:link
>page="/collaborator.do?mode=edit&code=<%=code%>">Edit</html:link>
You can only use a runtime expression as the complete content of a
JSP tag attribute, if at all. So, you could do something like this:
<bean:define name="temp"
type="java.lang.String">/collaborator.do?mode=edit&code=<%=code%></bean:define
<html:link page="<%=temp%>">Edit</html:link>
>or better yet this instead
> <html:link
>action="collaborator.do?mode=edit&code=<%=code%>">Edit</html:link>
To pass parameters to URLs built from the "action" attribute, you can
use paramId, paramName, paramProperty, and paramScope to pass a
single parameter, or name (and optionally property) to identify a Map
whose keys are parameter names and whose values are corresponding
parameter values. See
http://jakarta.apache.org/struts/userGuide/struts-html.html#link for
details.
Actually, you can use these to pass parameters to any url, but if you
use the "action" attribute, this is the only way to do it.
For what you define above, you may prefer to establish the
"mode=edit" state by using a different ActionMapping. Something like:
<action path="/CollaboratorEdit" parameter="edit"
type="com.example.CollaboratorAction" ... />
<action path="/CollaboratorView" parameter="view"
type="com.example.CollaboratorAction" ... />
Your action class can use "mapping.getParameter()" to find out
whether it's in edit or view mode just as easily as it could consult
the "mode" property of an ActionForm (or the "mode" request
parameter).
In my opinion, this is more elegant, and it saves the hassle of
appending multiple parameters in html:link using a Map.
The <c:url> tag in the JSTL supports a <c:param> subtag for adding an
arbitrary number of parameters to a URL. Of course, it doesn't know
how to dereference an action path. There's been some talk about
adding a similar tag in Struts, but no one has been motivated to
write it yet.
Joe
--
--
Joe Germuska
Joe@Germuska.com
http://blog.germuska.com
"If nature worked that way, the universe would crash all the time."
--Jaron Lanier
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
RE: html:link question (for a relative newbie)
Posted by Ray Madigan <ra...@madigans.org>.
If you are not opposed to using the JSTL standard library
I personally have a difficult time keeping track of the parameters
and values using the other syntax.
<c:url value='/collaborator.do' var='collaboratorURL'>
<c:param name='mode' value='edit'/>
<c:param name='code' value='${code}'/>
</c:url>
<html-el:link href='${collaboratorURL}'>
Edit
</html-el:link>
-----Original Message-----
From: Zimmerman, Steven R. [mailto:srzimmerman@DOC1.WA.GOV]
Sent: Thursday, September 18, 2003 1:45 PM
To: 'struts-user@jakarta.apache.org'
Subject: html:link question (for a relative newbie)
I cannot seem to get this to work
<html:link
page="/collaborator.do?mode=edit&code=<%=code%>">Edit</html:link>
or better yet this instead
<html:link
action="collaborator.do?mode=edit&code=<%=code%>">Edit</html:link>
but the <%=code%> is not picking up the value of "code", instead it is
putting "<%=code%>" in its place. That all makes sense why, but is there a
way I can get at a expression using Struts tags like I can using the code
below with a hard coded HREF ('cuse it works fine there but is not what I
want).
<A href="logon.jsp?task=delete&code=<%=code%>">Delete</A>
All else works fine, I realize that I could be chaining actions or some
other "do not do" but I am under a bit of a time crunch (as always... :).
TIA, Steve
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org