This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Spring and the fly likes populate a form Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "populate a form" Watch "populate a form" New topic
Author

populate a form

Al Coson
Greenhorn

Joined: Nov 18, 2009
Posts: 4
Note: Im using Spring for the view and buisiness layer, and Hibernate. But hibernate isn't important here. Im also really new to Spring.

I have created a form for adding items to my database, and it works. For that Im using a controller class that extends SimpleFormController.

I now want to reuse this controller and .jsp page for editing the verry same object as an editing page. In my mind the form would look almost exactly the same. So I changed the handleRequest method. And got the form successfully populated. But now I cant handle the submit part. My guess is that because I override the handleRequest method, the onsubmit method stops working i.e. aint being called. I havn't learned how to handle Log4j properly yet, so I dont know if onSubmit is being called or not, besides from the fact, knowing that nothing is being entered/changed into the DB.

This is what my Controller class looks like:





When this part gets called from my "index.jsp" view, it successfully populates the form with the information. But then I cannot submit it. Instead the same page is loaded as if the handleRequest is being called instead of onSubmit.
I know the onSubmit method works as Ive tested it before, when handleRequest wassnt implemented.


Can I please get suggestions on how to solve this? So that I can use this controller and .jsp page for both adding and editing an object.
Suggestions on how to solve this problem with another approach is also welcome.
Should I add any other information?
Al Coson
Greenhorn

Joined: Nov 18, 2009
Posts: 4
It seems I was looking for the formbackingObject method.. I didnt know it did what it did, but it does what I need to do, that is, populate my form.
 
 
subject: populate a form