aspose file tools*
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
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "variables" Watch "variables" New topic
Author

variables

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
Sheriff

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: http://aspose.com/file-tools
 
subject: variables
 
Similar Threads
regard on k&b book
Why Java ?
Home loans in India - fixed or floating ?
WA #1.....word association
Dont declare global variables in Servlet