This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund 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
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Frameworks » Spring
Reply 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.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: populate a form
 
Similar Threads
problem in form submit in spring
Spring - passing values by parametrs to Controller
Hibernate loads only first element of the collection
request is not going into onSubmit
F5 or page refresh calls onSubmit of spring controller - database again updated