aspose 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
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: 8971
    
    9

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.


[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: 8971
    
    9

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.
 
 
subject: How get variable from list?