• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Use Rultime Expressions in Struts 2 tags

 
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I am facing issue while using runtime expression with Struts tags. Is there any work around to use runtime expressions in tags like <s:select>???

say I have Users List in the session and I want it to be displayed in the <s:select>. I can't use it like list ="${usersList}".
How can I achieve this?

 
Ranch Hand
Posts: 689
Scala Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

hi,

Ok, first see the syntax of your and Struts 2 <s:select> box. You have written list="{$list}" but that is wrong.

First get the list in your action List user and set it to getting value form session . Like make one user object and getter and setter for user.

Then use to initialize user object.

user = (User) ActionContext.getContext().getApplication().get("YOUR USER SESSION NAME");

then direct you can use

<s:select theme="simple" cssClass="textfield"
headerValue="Select User" headerKey="0"
name="userName"
value="%{userName}" id="region"
list="user" listKey="id" listValue="userName" />


so remove you ${} form list="" attribute.




 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OGNL can be used to access session attributes; if the user list is already in session:You can also use Nishan's suggestion of retrieving the user list object in the action and exposing it as an action property, but it's probably easier and more testable to implement SessionAware and load the action property from the session attribute map.

Implementing SessionAware doesn't involve any static utilities and makes actions easier to test in isolation.
 
Vish Shukla
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi David and Nishan,

thanks for your replies.. I am not yet able to try this out. What I want more in this is that I want to use say UserID as Key of list and UserName as display value. And the other thing is, when I change value of this select, say I changed name to "Vishal", at that time the other <s:select> should show list of say "hobbies" of the user "Vishal". So how do I do that? Should I do ajax request to server on value change event? if yes, then how do I do that? if no, then what is alternative of doing it..

Thanks in advance.

Eagerly waiting for reply.
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's a pretty different issue--you should really start a different thread for a new topic.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic