File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes How get variable from list? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How get variable from list?" Watch "How get variable from list?" New topic
Author

How get variable from list?

Honzak Troubak
Ranch Hand

Joined: Jan 11, 2013
Posts: 31
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: 8707
    
    6

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
Ranch Hand

Joined: Jan 11, 2013
Posts: 31
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: 8707
    
    6

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://aspose.com/file-tools
 
subject: How get variable from list?
 
Similar Threads
Struts iterator tag value attribute
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
Sticky nested lists problem in Struts 2