Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How do you load the initial command object populated for the initial index.jsp?

 
Mike London
Ranch Hand
Posts: 1290
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a simple Spring 3 MVC application, but when I changed the index.jsp to use the spring form tags (instead of regular HTML form controls), I then needed to have the form backing object loaded already or get the dreaded: "Neither BindingResult nor plain target object for bean name 'formObject' available as request attribute"

So, how do you get the initial form backing object initially populated so that, even if no values have been entered into the form variables (and they wouldn't have been since index.jsp is loading for the first time), you don't get any errors?

thanks.

mike
 
Tekchand Prasad
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1.Use annotation at class level for formObject:

@Configurable
public class FormObject {
//setter, getter
}
2.Use annotation at class level in Controller

@Controller
@SessionAttributes(value = { "formController" })
public class MyController(){

@ModelAttribute("formObject")
........

}

 
Mike London
Ranch Hand
Posts: 1290
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. I appreciate your reply, but it was too abbreviated for me to construct a working example.

However, I decided to just go to another page first and then when going to what used to be the index.jsp page, I then build the form backing object in the controller before that page loads.

thanks

mike
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!