• 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

Passing Object from MVC controller to jsp page

 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a very simple controller and two views, a form and a thank you view. The form() method in the controller (mapped to the URL /form.do binds a new Member domain object (containing first and last name strings) to a form bean and returns it to the form.jsp page. The form.jsp page then is used to fill in the first and last names and submits to the controller's proecessFormData() method. This then puts the Member object passed to it into the Model and returns to the Thanks.jsp page. When I fill in the data on the form.jsp page and submit, I can see from the log statement in the processFormData() method of the controller that the first and last name are coming through correctly, my form data is getting to the controller properly. Also the processFormData() correctly returns to the thanks.jsp view (thanksViewName is set to "thanks"). However, on the thanks.jsp page, the ${member} EL evaluates to null null. It is getting a member object, but apparently the first and last names are null. I would think the model.addAttribute(member) should put the member object onto the Model under the attribute name "member". I'm not sure why the Member object is coming through null. Can someone advise?

Thanks in advance.
Mike

Controller


Views:

1) Form view:


2) Thanks view:

 
Mike Tabak
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I discovered the problem: my bean mapping for the NomineeController was
<bean name="/roster/*" class="com.springinpractice.ch03.web.NomineeController"
p:thanksViewName="redirect:/main/nominee/thanks"/>, so I was doing a redirect which causes the browser to request the page with a new uninitialized Member object and thus the first and last name properties were null.
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for posting the answer, Mike! Even you're the one who asked the question, it might help somebody else in future.
 
If you send is by car it's a shipment, but if by ship it's cargo. This tiny ad told me:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic