• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Bean values won't change on form submit

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

When a user is logged in, a user object is placed in session. This way I can access all attributes. I want to have a form where the user can the attributes.

The form:


The servlet that is called:

The current values display in the form. After changing any of the fields and pressing submit, I expect to see the new values from the servlet, but it just prints out the old values. I have no idea why. I obviously have setters in the User class. I do the same thing in user registration, which works perfectly. The only difference is that in the registration form, I instantiate the object with a <jsp:useBean>, but it should be working when accessing an existing object from the session too, right??

Maybe I'm wrong, or missing something obvious, it should be easy to get this working, but I've been stuck here for too long....

Any suggestions?
Thanks
 
Marshal
Posts: 67451
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Andre Solberg wrote:After changing any of the fields and pressing submit, I expect to see the new values from the servlet


And just why would you expect that? If you haven't done anything to update the properties of the bean, why would you expect them to be updated?

Grab the info from the request and update the bean properties.
 
Bear Bibeault
Marshal
Posts: 67451
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
P.S. Scriptlets in the JSP? In 2010?
 
Ranch Hand
Posts: 182
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
setAttribute method of HttpSession is never used in the code, means User object in the session scope not changed/updated.

Andre Solberg wrote:The only difference is that in the registration form, I instantiate the object with a <jsp:useBean>

User object in the session scope must have changed/updated, may be by using jsp:setproperty tag(i guess the scope attribute in jsp useBean tag must have the value as session).

Difference between these two is, first one takes a copy of User object from session and updates copied User object 's attribute and updates it into session; Second one directly uses the User object from session.

I am little late
 
Andre Solberg
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh ok, I see I've misunderstood........................

I handle the registration in a separate jsp instead of servlet. I forgot about the <jsp:setProperty name="user" property="*"/> within the <jsp:useBean>.
I guess I just thought there was some magic that automatically filled the bean with the values from the fields as long as the setters where right ...

But when doing this in a servlet, does that mean I have to manually fill in each and every property from the request and put in in the bean? I can't put the <jsp:setProperty> in before I submit or in the servlet? If so, then damn...

Thanks for helping!
 
Bear Bibeault
Marshal
Posts: 67451
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out Jakarta Commons BeanUtils.populate().
 
It's exactly the same and completely different as this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic