• 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

Struts 2 updating record problem

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

I have the person class object in my action class

i made the getter and setter for person object in my action class

and in jsp page i update some fields

then when i submit the form new object is created instead of some of fields change....
if i set all other fields in hidden tag den its ok... is there any solution that we do not have to save other properties of person object in hidden tags

Thanks in Advance
Ramandeep S.
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let me get this straight. You present data to the user, the user changes the data, and you are surprised that when the data is submitted to the server, it is changed? Sounds to me like it is working as designed.
If you don't want the data changed, perhaps you should save a copy off somewhere.
 
RamandeepS Singh
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

First of all thanks for replying

No thats not the issue i can explain with you an example

say user has properties
1.first name
2. last Name
3. Email
4. Password

i displayed first name, last Name, password in page

and when i submit the form
email is set to null,
but if i set email as hidden then it works fine because new object is created and email is given new value

i want to know is there any way to retain the previous object and just change the changed values

condition
i do not want to save the copy of object


 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I see what you are saying. With Struts, you write an object's state to a JSP page, throw it over to the browser, then Struts reconstitutes the object and hands it to your action. If you don't put all the fields on the JSP, Struts can't retrieve that information. You have a couple of options:
1. use hidden fields, as you know.
2. put the object in the session and copy the updated values into that object.
3. only consider fields that you have on the JSP page, ignoring fields you know will be null
4. make your class structure reflect that of your JSP page. This is probably the "best" option, since we want our classes to model the real world, and they are less error prone than the previous suggestions. I usually make a class hierarchy with a simple (user name) object for list purposes, a more complex subclass for user purposes (address, phone), then a even more complex subclass for administration purposes (department assignment, mail code). This way, each JSP and action only deal with the fields then are presenting and editing.
 
reply
    Bookmark Topic Watch Topic
  • New Topic