Link to home
Start Free TrialLog in
Avatar of simi
simi

asked on

set property for a bean with a value from the request

Hi,

Here is an example of what I want to achieve.

<jsp:setProperty name="someBean" property="someProperty" value="<%=session.getValue("someOtherProperty")%>"/>

Basically I want to assign to a bean property another property comming from the session object.

With the syntax from above, I keep getting an error message "Attribute someOtherProperty has no value".
However, if I replace the code from abobe with
<%=session.getValue("someOtherProperty")%>, I am getting printed the value of the someOtherPropery, which is OK.

Thanks.
ASKER CERTIFIED SOLUTION
Avatar of pellep
pellep
Flag of Sweden image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of knightEknight
or:

<%! String prop = session.getValue("someOtherProperty"); %>

<jsp:setProperty name="someBean" property="someProperty" value="<%= prop %>"/>
the only change to knightEknight's code I would make is
make the prop a local var.. whenever I use JSP declaration scriptlet I always run into scoping issues.

<% String prop = session.getValue("someOtherProperty"); %>

<jsp:setProperty name="someBean" property="someProperty" value="<%=prop%>"/>

CJ
good catch CJ, that was a cut-n-paste error on my part.
isn't that exactly what you had??
<curiously>
no, the original had <%= and pellep suggested <%
Ah I see.

Surprised that worked.. learn somethin new everyday..

CJ
Avatar of jayametts
jayametts


weird. you got to have = sign.
that's what I see for struts 1.1 .. i get a message asking for = sign inside the assignment tag.