aspose file tools*
The moose likes Struts and the fly likes Use Rultime Expressions in Struts 2 tags Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Use Rultime Expressions in Struts 2 tags" Watch "Use Rultime Expressions in Struts 2 tags" New topic
Author

Use Rultime Expressions in Struts 2 tags

Vish Shukla
Ranch Hand

Joined: Oct 12, 2008
Posts: 111
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?


Thanks & Regards,
Vishal S Shukla (SCJP 93%, SCWCD 94%, SCBCD 100%)
Nishan Patel
Ranch Hand

Joined: Sep 07, 2008
Posts: 689


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.





Thanks, Nishan Patel
SCJP 1.5, SCWCD 1.5, OCPJWSD Java Developer,My Blog
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Oct 12, 2008
Posts: 111
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
Rancher

Joined: Sep 29, 2008
Posts: 12617

That's a pretty different issue--you should really start a different thread for a new topic.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Use Rultime Expressions in Struts 2 tags