This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes Struts and the fly likes How get variable from list? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Frameworks » Struts
Reply Bookmark "How get variable from list?" Watch "How get variable from list?" New topic
Author

How get variable from list?

Honzak Troubak
Greenhorn

Joined: Jan 11, 2013
Posts: 24
Hello people,

i have stupid problem - how can I get variable from list?

In list ( conferenceList ) is variable idConference and I need work with it. But I can't do it. I tried to use <%= %>, %{}, etc.

Here is my code:


Thanks
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8291

You can't use OGNL notation ( i.e. "%{}") inside a scriptlet. You would need to access the request and get the value stack. The first value on the stack would be the current value of the iterator.
Best Practices for JSP's tell us to avoid using scriptlets. If you need to "work with" a value, do it in your action or a business logic bean. Leave JSP's for display logic.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Honzak Troubak
Greenhorn

Joined: Jan 11, 2013
Posts: 24
Thanks for reply!

You were right, I had to use HttpServletRequest.



Only one small question - I have problem on line 7: <s:property value="conferenceList[<%=cislo%>].title"/>

When I use number, for example <s:property value="conferenceList[0].title"/> , everything is all right.

But when I use <%=cislo%> it doesn't work. I think it's similar problem like in my first question but unfortunately I can't resolve it.
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8291

Again, you should not be using scriptlets (java code inside a JSP). If all you need is an ID inside a URL, Struts provides a url tag that lets you construct a URL with parameters.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: How get variable from list?
 
Similar Threads
Sticky nested lists problem in Struts 2
Querying DB and Iterating over the resultset
List of dinamic checkboxes, how to get values, reflection of properties
nested iterator using List and Map in struts2
Struts iterator tag value attribute