• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How get variable from list?

 
Honzak Troubak
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9256
9
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Honzak Troubak
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9256
9
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic