You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Richard Hill <RH...@classmates.com> on 2003/04/09 04:22:31 UTC

Using a model bean value in an encoded URL

I have an action that creates and populates a model bean (not a form bean)
and makes it available to the view component, in this case a success.jsp . 

In the success.jsp I would like to build an encoded link based on two
values. One value that is not dependent on the model bean value, and the
second value that is.

The "Struts - Kick Start" by Turner, and Bedell suggests doing something
like the following for building links with two or more name/value pairs to
be encoded in a URL:

<%
    java.util.HashMap myMap = new java.util.HashMap();
    myMap.put("firstValue",  new String("some value") );
    myMap.put("secondValue", new String("a value in my model bean"));
    pageContext.setAttribute("map", myMap);
%>

<html:link page="/NextAction.do" name="map">
    URL encode a parameter based on values in a Map
</html:link>

My question is how do you insert an attribute value of the model bean into
the 'new String("a value in my model bean")' ?

Can I do the following:
myMap.put("secondValue", new String(<bean:write name="path.to.model.bean"
property="name" />);

Thanks,
Richard

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


Re: Using a model bean value in an encoded URL

Posted by Ian Hunter <ih...@hunterweb.net>.
How is the model bean exposed to the page -- have you set it as a session
attribute?  In that case,

myMap.put("secondValue", new
String((beanClass)request.getSession().getAttribute("beanName").getProperty(
).toString);

Does that help?

Ugly doing things in scriptlets, isn't it?

----- Original Message -----
From: "Richard Hill" <RH...@classmates.com>
To: <st...@jakarta.apache.org>
Sent: Tuesday, April 08, 2003 10:22 PM
Subject: Using a model bean value in an encoded URL


> I have an action that creates and populates a model bean (not a form bean)
> and makes it available to the view component, in this case a success.jsp .
>
> In the success.jsp I would like to build an encoded link based on two
> values. One value that is not dependent on the model bean value, and the
> second value that is.
>
> The "Struts - Kick Start" by Turner, and Bedell suggests doing something
> like the following for building links with two or more name/value pairs to
> be encoded in a URL:
>
> <%
>     java.util.HashMap myMap = new java.util.HashMap();
>     myMap.put("firstValue",  new String("some value") );
>     myMap.put("secondValue", new String("a value in my model bean"));
>     pageContext.setAttribute("map", myMap);
> %>
>
> <html:link page="/NextAction.do" name="map">
>     URL encode a parameter based on values in a Map
> </html:link>
>
> My question is how do you insert an attribute value of the model bean into
> the 'new String("a value in my model bean")' ?
>
> Can I do the following:
> myMap.put("secondValue", new String(<bean:write name="path.to.model.bean"
> property="name" />);
>
> Thanks,
> Richard
>
> ---------------------------------------------------------------------
> 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: Using a model bean value in an encoded URL

Posted by Kris Schneider <kr...@dotech.com>.
JSTL is your friend:

<jsp:useBean id="paramMap" class="java.util.HashMap"/>
<c:set target="${paramMap}" property="firstValue" value="some value"/>
<c:set target="${paramMap}" property="secondValue" value="${modelBean.name}"/>
<html:link action="/nextAction" name="paramMap">
   URL encode a parameter based on values in a Map
</html:link>

Richard Hill wrote:
> I have an action that creates and populates a model bean (not a form bean)
> and makes it available to the view component, in this case a success.jsp . 
> 
> In the success.jsp I would like to build an encoded link based on two
> values. One value that is not dependent on the model bean value, and the
> second value that is.
> 
> The "Struts - Kick Start" by Turner, and Bedell suggests doing something
> like the following for building links with two or more name/value pairs to
> be encoded in a URL:
> 
> <%
>     java.util.HashMap myMap = new java.util.HashMap();
>     myMap.put("firstValue",  new String("some value") );
>     myMap.put("secondValue", new String("a value in my model bean"));
>     pageContext.setAttribute("map", myMap);
> %>
> 
> <html:link page="/NextAction.do" name="map">
>     URL encode a parameter based on values in a Map
> </html:link>
> 
> My question is how do you insert an attribute value of the model bean into
> the 'new String("a value in my model bean")' ?
> 
> Can I do the following:
> myMap.put("secondValue", new String(<bean:write name="path.to.model.bean"
> property="name" />);
> 
> Thanks,
> Richard
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org

-- 
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