Back Forum Reply New

Spring 3.0 quot;formquot; annotated controller help

Hi, I am having issues getting an annotated quot;formquot; controller to work properly within Spring 3.0. I will be using velocity templates and spring macros. Below is the snippet of my controller code, form object, form backing object, and velocity template. Problem one, I can't get the #springFormSingleSelect() macro to populate my drop down list. Am I missing something within the code? Also, I was able to get around this by doing lt;selectgt; html tags (but I'd rather not). But, problem two...I can't seem to bind the selected value to be stored within my form object. Please point me to the right direction. Thanks.

This is the controller code. The service class works.

Code:
@Controller
public class SomeController
{  private final SomeService service;    @Autowired  public SomeController (SomeService service)  {     this.service = service;  }   @RequestMapping(method=RequestMethod.GET)  public void referenceData(Model model)  {     model.addAttribute(quot;someFormquot;, new someForm());     model.addAttribute(quot;namesquot;, service.getNames());       //lt;--- this is the drop down list  }
  @RequestMapping(method=RequestMethod.POST)  public void onSubmit(@ModelAttribute(quot;someFormquot;) SomeForm someForm) {    ....    //if I do a call like below, I get a null... even though I selected something in the view...    System.out.println(quot;name: quot; + someForm.getName()); }  
}
This is the form(domain) class

Code:
@Component
public class SomeForm
{  private String name;
  ... standard getters/setters ...
}
This is the custom Name bean for the drop-down list

Code:
public class Name
{  private String name;
  ...getters/setters...
}
This is my velocity template. The #springFormSingleSelect doesn't populate my list. But the raw html code below does...

Code:
lt;form method=quotOSTquot;gt; #springFormSingleSelect(quot;someForm.namequot; $names)
  #springBind(quot;someForm.namequot;) lt;selectgt;    #foreach( $name in $names )        lt;option value=quot;$name.namequot;gt;$name.namelt;/optiongt;    #end lt;/selectgt;
lt;/formgt;
Please give some insights. Am I missing a @InitBinder? If so, what would such code look like?

Thanks.
¥
Back Forum Reply New