This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Struts and the fly likes variables Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "variables" Watch "variables" New topic


Nicola Guy
Ranch Hand

Joined: Jun 23, 2004
Posts: 91
Does anyone know how to get a value from a bean and store it in a variable in a scriptlet in a jsp??
Marc Peabody
pie sneak

Joined: Feb 05, 2003
Posts: 4727

You can either do this:
<% String fooboo = ((MyBeanClass)request.getAttribute("myBean")).getMyValue(); %>
or this:
<bean efine id="fooboo" name="myBean" property="myValue"/>

Either version will call the getMyValue() method of the myBean bean and set the value to fooboo, which can be used in any scriptlet.

A good workman is known by his tools.
Nicola Guy
Ranch Hand

Joined: Jun 23, 2004
Posts: 91
thats good but its not what i want to do.

i'm iterating through a vector of beans and want to take one value from the bean to format it in a certain way but I can't find a way of retrieving the value unless i'm printing it to screen
Chengwei Lee
Ranch Hand

Joined: Apr 02, 2004
Posts: 884
I uses JSTL and Struts tag to achieve what you want.

Since you're having a vector of JavaBeans, you'll need the <logic:iterate> tag, then during each iteration, you'll need the <bean:write> tag to obtain the value of the property in the bean that you're interested in. From your posts, I think you've reach this far.

You'll need to insert a step in between. Using JSTL <c:set> tag, you embed the <bean:write> tag in it. This way, your value doesn't get printed out. It gets set into a variable, that you can specify its scope.

Lastly, you can use JSTL <fmt> to format your output.

Hope I'd interpreted your question correctly.

SCJP 1.4 * SCWCD 1.4 * SCBCD 1.3 * SCJA 1.0 * TOGAF 8
Nicola Guy
Ranch Hand

Joined: Jun 23, 2004
Posts: 91
this answer is exactly what I was looking for however you cannot embed bean:write in side the c:set tag and have the variable set

any other ideas
I agree. Here's the link:
subject: variables
Similar Threads
WA #1.....word association
Why Java ?
regard on k&b book
Home loans in India - fixed or floating ?
Dont declare global variables in Servlet