File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "populate a form" Watch "populate a form" New topic

populate a form

Al Coson

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

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.
I agree. Here's the link:
subject: populate a form
It's not a secret anymore!