Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to update session values from JSP in Struts 2

 
Abhaysinh Bhelke
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 72
Eclipse IDE Hibernate Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try using hidden form fields for non-editable fields .. and keep the rest as they are.. hope this works fine for your requirements .
 
Abhaysinh Bhelke
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic