Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 2nd, 2012  |  syntax: None  |  size: 2.25 KB  |  hits: 127  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Neither BindingResult nor plain target object for bean name 'userProfile' available as request attribute
  2. java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'userProfile' available as request attribute
  3.     at org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:141)
  4.     at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getBindStatus(AbstractDataBoundFormElementTag.java:174)
  5.     at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getPropertyPath(AbstractDataBoundFormElementTag.java:194)
  6.     at org.springframework.web.servlet.tags.form.LabelTag.autogenerateFor(LabelTag.java:129)
  7.     ...
  8.        
  9. @Controller
  10. public class UserController {
  11.  
  12.     @Autowired
  13.     private UserProfileService userProfileService;
  14.  
  15.     public UserController(){
  16.  
  17.     }
  18.  
  19.     @RequestMapping(value="/add", method=RequestMethod.POST)
  20.     public String registerUser(@ModelAttribute("userProfile") UserProfile userProfile, BindingResult result, Map model){
  21.  
  22.         userProfileService.addUserProfile(userProfile);
  23.  
  24.         return "redirect:/login";
  25.     }
  26.     ...
  27. }
  28.        
  29. @Entity
  30. @Table(name="USER_PROFILE")
  31. public class UserProfile {
  32.     @Id
  33.     @GeneratedValue
  34.     @Column(name = "ID")
  35.     private Long id;
  36.  
  37.     @Column(name = "USERNAME")
  38.     private String userName;
  39.  
  40.     @Column(name = "PASSWORD")
  41.     private String password;
  42.  
  43.     //sets and gets
  44. }
  45.        
  46. <form:form method="post" action="add" commandName="userProfile">
  47.     <table>
  48.         <tr>
  49.             <td><form:label path="userName"><spring:message code="label.username" /></form:label></td>
  50.             <td><form:input path="userName" /></td>
  51.         </tr>
  52.         <tr>
  53.             <td><form:label path="password"><spring:message code="label.password" /></form:label></td>
  54.             <td><form:password path="password" /></td>
  55.         </tr>
  56.         <tr>
  57.             <td><input type="submit" value="<spring:message code="label.adduser" />"></td>
  58.         </tr>
  59.     </table>
  60. </form:form>
  61.        
  62. @RequestMapping("/")
  63. public String home() {
  64.     return "redirect:/index";
  65. }
  66.  
  67. @RequestMapping(value = "/index", method = RequestMethod.GET)
  68. public String createRegisterForm(Map<String, Object> model){
  69.     model.put("userprofile", new UserProfile());
  70.     return "index";
  71. }