aspose file tools*
The moose likes Struts and the fly likes How to update session values from JSP in Struts 2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How to update session values from JSP in Struts 2" Watch "How to update session values from JSP in Struts 2" New topic
Author

How to update session values from JSP in Struts 2

Abhaysinh Bhelke
Greenhorn

Joined: Jan 20, 2013
Posts: 2
Hi,

I am using Struts 2.0. I have a Java Bean Person having perName, perAge, perMail & many more. I want to display a Map of Java Bean {[1, person1], [2, person2]) on JSP and allow user to update it from the same JSP. I am using text fields to display them. There are number of variables in the bean and some of them are editable while some of them are not. For example, perName is not editable while perAge is editable. I don't want to display non editable fields. If I use only ediatable fileds, after updating I get non editable fields as null (perName is null after update). Also there are number of fileds. So I can't specify name attribute as it is changing at run time. So I am putting them in HTTP Session and displaying them. I am specifying name attribute of text field using #session.person[iterator index].perAge. Till this point everything works fine. But if I change the value in any text field & try to update, I get the old session attribute instead of changed one. I want the old session attribute with the new changed values and values of non editable fields should persist within user request. I don't want to use JavaScript. OGNL or experssions are most welcome. Your help is highly appreciated.
Gopakumar Naryanan
Ranch Hand

Joined: Jan 15, 2011
Posts: 72

Try using hidden form fields for non-editable fields .. and keep the rest as they are.. hope this works fine for your requirements .


Thanks & Regards
Gopakumar
Abhaysinh Bhelke
Greenhorn

Joined: Jan 20, 2013
Posts: 2
Thanks for the reply. I came to know that object in the session can't be edited directly by using a text field attribute as that may create a security threat. Using hidden variables works fine. But as I have number of fields as hidden variables that didn't became a solution. Instead I have used Struts interceptors. I reconstructed object in prepare method of preparable interceptor & session. Thanks for the help.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to update session values from JSP in Struts 2
 
Similar Threads
if variables not set to null before passivation?
pagination problem
get the ActionForm property value into a java variable from JSP
how to make one, out of two fields mandatory
MVC Model and Domain Model