Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

variables

 
Nicola Guy
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Nicola Guy
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 884
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Nicola Guy
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic