binding 1 « MVC « Spring Q&A

1. Automatic dynamic binding in spring

I am using spring MVC and would like to expose default validator for javascript to use. I have a bunch of controllers extending a common abstract class and bunch of validators implementing ...

2. Spring: escaping input when binding to command

How do you handle the case where you want user input from a form to be htmlEscape'd when you are binding to a command object? I want this to sanitize input data ...

3. How can i register a global custom editor in Spring-MVC?

I use the following custom editor in MANY Spring-MVC controllers according to: A controller

binder.registerCustomEditor(BigDecimal.class, new CustomNumberEditor(BigDecimal.class, NumberFormat.getNumberInstance(new Locale("pt", "BR"), true));
Other controller
binder.registerCustomEditor(BigDecimal.class, new CustomNumberEditor(BigDecimal.class, NumberFormat.getNumberInstance(new Locale("pt", "BR"), true));
Another controller
binder.registerCustomEditor(BigDecimal.class, new CustomNumberEditor(BigDecimal.class, NumberFormat.getNumberInstance(new Locale("pt", ...

4. Spring Dynamic List Binding

I have a typical scenario - I have read many articles on this and dynamic addition seems to work fine. I could not get elegant solution for dynamic delete.

  1. A Web ...

5. Simple Spring Binding Question

I have some objects like the two below public class SavedSearch { String title; ArrayList<SearchParameters> params; } public class SearchParameter { String field; int operator; String match; } On the JSP page in the input form, I use <input type="text" name="title"> and ...

6. How to bind IP address to a Spring 3 @ModelAttribute?

Here's how my method looks like:

@RequestMapping(value = "/form", method = RequestMethod.POST)
public String create(@ModelAttribute("foo") @Valid final Foo foo,
        final BindingResult result, final Model model) {

7. changing spring jsp date input bind in a form to use freemarker

I´m trying to change a spring jsp example to use freemarker. I changed all fields in a form with something like this: <@spring.formInput "" /> Everything worked nicely. Form binded to the object ...

8. Spring @InitBinder not invoked when showing form => CustomEditors not defined

I have following (simplified to the bone) Controller:

public class TestController  {

@RequestMapping(value = "/test.htm", method = RequestMethod.GET)
public String showForm(final ModelMap map) {
    final TestFilter filter = ...

9. Setting nested object to null when selected option has empty value

I have a Class which models a User and another which models his country. Something like this:

public class User{
    private Country country;
    //other attributes and ...

10. Nested form data binding with Lists of Objects in Spring MVC

I have an object like so:

public class FormFields extends BaseObject implements Serializable {

private FieldType fieldType; //checkbox, text, radio
private List<FieldValue> value; //FieldValue contains simple string/int information, id, value, label

//other properties and getter/setters

I ...

11. spring-mvc binding arraylist in form

In my controller I added an ArrayList to my model with the attribute name "users". Now I looked around and this is the method I found (including a question here):

<form:form action="../user/edit" method="post" ...

12. Spring - disable bind exceptions (for a particular property)

In a web application I'm working on using Spring 2.5.6.SEC01, I essentially have an Integer field that takes a number to determine which page to scroll to. The requirements changed, ...

13. Spring Bind Exception

i got exception in my controller class using bindexception.using reject method how i can print the message in my jsp.

14. java.lang.NumberFormatException - Data Binding errors

I am using Spring MVC for a web application and I am working with a simple form that deals with selecting clients and showing contact information. One of the problems I ...

15. Is it possible to bind/convert the items in a list of a form to a specific type in a Spring Web MVC app?

I'm building a Spring MVC app with Spring 3.0.3. I have data binding of my form working just fine, but one of the form fields is a list of items. Hypothetically ...

16. Show binding errors next to each input

How do I show validation errors NEXT to each input/component? Validator:

public void validate( final Object obj, final Errors e )
   ValidationUtils.rejectIfEmpty( e, "firstname", "error.firstname.empty" );
<form:label  path="firstname">
   <spring:message ...

17. getting org.springframework.web.bind.MissingServletRequestParameterException

I am using spring annotations I have written one method

public ModelAndView showTestPage(@RequestParam("firstInstanceId") String id1, 
  @RequestParam("secondInstanceId") String id2, HttpSession  session) {

  ModelAndView mv = new ModelAndView("showCompareItemList");
  mv.addObject("pageTitle", ...

18. How to bind ENUM to radiobutton?

Type is enum property in object. jsp:

<form:radiobutton path="type" value="Male" />
public enum TestType
    Male, Female;
and got error Unable to convert value 'Male' from type 'java.lang.String' to type 'java.lang.Enum'; reason = 'java.lang.Enum ...

19. Data binding of an abstract class in spring-mvc

I've went thru Spring documentation and source code and still haven't found answer to my question. I have these classes in my domain model and want to use them as backing form ...

20. What does it mean to say "if (binding.hasErrors())" in Spring?

In this example, I don't understand what the BindingResult is for and what it means to say if (binding.hasErrors()) below.

@RequestMapping(value = "/test", method = RequestMethod.POST)
public final String submit(@ModelAttribute(TEST) @Valid final Test ...

21. Spring MVC bind comma separated list to multi-select

tl;dr: I have a custom object that isn't a Collection. How can I get Spring to bind it to a multiple select? I have an object Field that contains a field ...

22. Spring MVC 3.0: How do I bind to a persistent object

I'm working with Spring MVC and I'd like it to bind a a persistent object from the database, but I cannot figure out how I can set my code to make ...

23. SpringMVC form bind to command object which is interface

I'm learning SpringMVC 2 and i have a form that i need to bind to an object (the command). But what if i need this command object to be an interface ...

24. Spring MVC - Binding a Date Field

For request parameters representing string, number, and boolean values, the Spring MVC container can bind them to typed properties out of the box. How do you have the Spring MVC container bind ...

25. Spring 3 bind obscures real values of command object

I have a controller that allows users to add or edit an entity. I've removed from myForm but spring still shows it when the spring:bind tag is used. See the ...

26. Spring tries to bind all fields

Using Spring 3 I have two forms: adding Item and invalidating Item I have ItemAddEditCommand that references Item and some other data. Adding Item works great but I have problem with invalidating Item. In ...

27. data binding to drop down box in Spring MVC

I have simple spring mvc web application.I want to bind list into drop down.In this case list items are normally bind into drop down; but If I select item and click ...

28. Spring MVC - command object binding question

I'm using a domain object as a command object in the web layer. In one case, this command object is backing a form that represents a partial update of the domain ...

29. Binding Properties of Primitive Wrapper Types with Spring MVC

It appears to me that Spring MVC cannot bind properties of primitive wrapper types(e.g. Integer, Boolean, etc). When it tries to bind such properties, it throws the following exception.

javax.servlet.ServletException: javax.servlet.jsp.JspException: javax.servlet.jsp.JspException: ...

30. Binding Multiple Command Objects of Same Type in Spring MVC

I have a several command objects of the same type to bind, each of which represents a row from a form. How do I bind these in an annotation based controller? ...

31. How to bind to a select box that is populated from another select box

Simple application using Spring 2.5. Have a left hand side multi select box and I have a right hand side multi select box. I have no issues in populating the left side from ...

32. Understanding the concept of data binding in a Spring-MVC app

I'm trying to understand the concept of data binding in Spring-MVC with Velocity (I'm learning this framework and porting an app to this platform). I'm used to getting form variables using request.getParameter("username"), ...

33. Spring-MVC: Need the most simple example of form-processing, binding, and validation

I have a form:

<form action="/processform">
   <input name="firstname" value="john" />
   <input name="lastname" value="doe" />
I have a Person object:
public class Person {
   private String firstname;

34. Selectively Binding a Property in Spring MVC

I have a page that has a form on it where the user can save or delete a bean. The form backing object has a bean as its property. When the ...

35. Spring WebDataBinder for binding multiple fields into a field of type Date

Could please anybody figure out a way how to use Spring data binders for getting values of a few fields (integers) : year, month, day, hour, minute from request and bind ...

36. Spring MVC Data binding error

When submitting a form I get the message: Data binding errors: 6 {||||||| - |}
The command class inherits from an abstract base class. When using debugging I can see ...

37. Problem with Spring databinding and @RequestBody

I have a small question regarding spring's MVC databinding capabilities. I do have the following controller class:

public class FooController() {

    // … some init stuff //

@RequestMapping(value = "/{id}/edit.{format}", method ...

38. mvc:annotation-driven - do I still need to bind Validators?

I have added <mvc:annotation-driven/> to my Spring configuration, and according to the documentation it will provide:

Support for validating @Controller inputs with @Valid, if a JSR-303 Provider is present on ...

39. @ModelAttribute in a method

Imagine a code like this one:

@RequestMapping(value="/users", method=RequestMethod.GET)
public String list(Model model) {

public void initBinder(WebDataBinder binder) {
    binder.setDisallowedFields("password"); // Don't allow user to override the ...

40. ConversionService in Spring

I'm following this scheme in a Spring application.

  1. Request is sent to the server with the id of the object and some other params to be populated in this object
  2. The object ...

41. Spring 3.0 MVC binding nested object

Why is spring not binding the values on my nested object? The SecurityQuestion object on the RegistrationBean is set with question and answer as null, null, respectively, despite setting then in ...

42. Spring form data binding - how to map a form property to a form attribute (when the form-property has a different name than the form-object)

public class MyForm {
  private String username;

public class MyController {
  public String handleForm( MyForm form, Model model ){
    //do something
If ...

43. Spring MVC binding

I have the following command object:

public class User {
    private Department department;
    private String firstName;
    private String lastName;
    private ...

44. Spring binding values in a Map

Is there a way to Spring bind values in a map? For instance, I have a Map<String,String> and I want to spring bind specific values in it. The user will type ...

45. Spring 3.0 MVC binding Enums Case Sensitive

If I have a RequestMapping in a Spring controller like so...

@RequestMapping(method = RequestMethod.GET, value = "{product}")
public ModelAndView getPage(@PathVariable Product product)
And Product is an enum. eg. Product.Home When I request the page, ...

46. spring mvc bind into 2 objects that have identical fields

I submit a form, lets say this form contains

<input name="address" ..>
<input name="billingAddress" ..>
i have 2 objects to which i need to bind to:
class Address {
   String address;

47. Apply property editor to object in the model

I have a form and I have registered the CustomNumberEditor for the float numbers of my objects.

public void initBinder(WebDataBinder binder){
    NumberFormat numberFormat = NumberFormat.getInstance();
    binder.registerCustomEditor(Float.class, ...

48. Spring CustomNumberEditor parses numbers that are not numbers

I'm using Spring CustomNumberEditor editor to bind my float values and I've experimented that if in the value is not a number sometimes it can parse the value and no error ...

49. How to catch and handle org.springframework.web.portlet.bind.MissingPortletRequestParameterException

Here is one of my controller method,

  public String handlePetPurchaseAction(

50. Use error in form without a field binding?

I am wondering whether you can use a <form:errors> tag to display an error that doesn't have a binding to a field in the command object. Basically I want to do ...

51. Protect specific fields when binding in Spring

I'm working on page that allows users to edit profile info. I want them to be able to edit their public info, but not allow them to change system flags ...

52. what is data binding used in spring jsp views

I can't fully understand the purpose of data binding in jsp of spring. Does someone have a full understanding of it?

53. Spring numberformatting with registercustomereditor on list of numbers

When registering a customerEditor in spring to format a number with a given numberFormat instance, it is easy to apply this to a specific field in the jsp, e.g.:

NumberFormat numberFormat = ...

54. Spring 3 form binding object is always null

I'm trying to bind a nested object with Spring 3, and I'm having issues. JSP:

<portlet:actionURL var="formAction" />
<form:form id="add-objects-form" method="post" action="${formAction}">
   <input name = "obj.a"...>
   <input name = "obj.b"...>

55. Confused with spring MVC JSP page binding

I have not been able to solve my binding problem. I have one class Person

Class Person {

Private fname;
private lname;
public Address address;
Now one other class
class Address {

    private ...

56. What is the purpose of init binder in spring MVC

This is the code on internet for init binder

    public void initBinder(WebDataBinder binder) {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");


57. Need help with binding Set with Spring MVC form

I have been trying for last 3 days still i am not able to solve my problem I have Person Class

 @OneToMany(cascade = CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="person")
 public Set<Book> books = new ...

58. How to add date field in Spring MVC

If i want to use custom date editor i need few things to ask

1)In database do i have to set variable startDate as datetime or varchar
2)IN Person class startDate is refered ...

59. How can I bind fieldName_1, fieldName_2 to a list in spring mvc

I'm trying to convert a struts 1 application to Spring MVC 3.0. We have an form with quite a few parameters, most of which where automatically binded in struts. However there ...

60. Using @ModelAttribute for reference data - avoid binding

I'd like to use the autowiring magic of @ModelAttribute for obtaining and passing around reference data. The problem in doing this is that anything added to the model with @ModelAttribute is ...

61. How to bind form data in Spring 2.5 most efficiently?

What would be the best way how to bind a form data to model? I mean I have a simple model class:

public class LoginCommand {

    private String login;

62. spring mvc binding/validation

so lets say I have some model class:

public class MyRequestParams {
    private Long val = Long.valueOf(0); // default value

    // ... plus some other stuff
And ...

63. How bind data to view without ModelAndView object

I have Spring Controller, and a method like this:

public ModelAndView getItems() {
    ModelAndView mav = new ModelAndView("myView");
    Item entity = new ...

64. Use Spring 3 MVC Annotation Validation with Freemarker

I am using Spring 3 MVC Annotation Validation. I know how to do it in JSP(using modelAttribute property in JSP), but I don't have any clue how to apply this kind ...

65. Spring form multiple binding

Hi guys is it possible to bind selected value and label at the same time on spring form? I am trying something similar to that.

<form:select id="selectionCity" path="targetAddress.cityid"

66. Spring MVC Binding

I am not sure if this is possible, but I need to do some odd binding with Spring MVC. We have to dynamically generate a page which is a precursor ...

67. spring portlet mvc form:select bind to list

I am using spring mvc portlet for one of my applications. I have a problem in binding a dynamically filled list box with the List collection in Controller. public class Conference { ...

68. How to bind a Set in spring mvc form

I have a command object associated with a spring form controller:

public class PluginInstance {
  private Set<PluginParameter> pluginParameters = new HashSet<PluginParameter>();
  ... some other string/long properties and getter setters...
the PluginParameter ...

69. How to use a binding framework efficiently

I've been using binding frameworks for a while now and i'd like to know how you handle this cases. You have a newspaper that has some attributes like

  • (String) headline
  • (Boolean) published
  • (Date) publishmentDate
On your ...

70. Spring MVC - bind form elements to a List

Is it possible to bind a form element to a List<Long>? ie. <form:input path="formValues[0]" /> binding to an element in List<Long> formValues; in the form backing object? When I try this, it fails ...

71. How to bind a List for ModelAttribute in spring mvc3

public class User{
       private String name;
       private List<Link> links;
public class Link{
       private String ...

72. Spring MVC Data Binding Error

I'm getting the following error when I try to retreive the form results in controller method..

org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 1 errors Field error in object 'search' on field 'clients': rejected ...

73. How can I set a value after data binding, but before validation, in Spring MVC 3?

I need to set a "time submitted" field on one of my domain objects. Validation rules require that property to be there, but I can't have it set by data binding ...

74. Spring Validation - Programmatically bind to a Validator

I am trying to use Spring validation to validate my model populated by Jackson converter. So I have a java class,

class MyClass(){
    private String myString;
This class ...

75. Why are the other properties of the object in a Spring @MVC form becoming null?

I'm trying to create a form using Spring @MVC 3.0. This form is supposed to let the user update the flavor of a soup, but I'm running into some issues. ...

76. How do you show non binding related errors on SpringMVC 3?

How do you show non binding related errors on SpringMVC 3? For example, I want to show a message when a certain entity cannot be shown to a specific user on ...

77. Issue Binding AutoPopulating List to a form Spring MVC

I have an issue binding the AutoPupulating List in a form to update the data. I was able to save the data using Autopopulating list though. Here is the form backing model.

public ...

78. Spring MVC binding to wrong fields

I have a controller with 2 methods that return related objects via the @ModelAttribute annotation:

public Site getSite(){
return site;

public Document getDocument(){
return document;
These objects are related to each other with one Site having ...

79. Simple Spring MVC 3 Bind Form Question

I have a simple html form,

<form id="marketplaceForm" enctype="multipart/form-data" method="post">
<select name="category">
    <option selected ></option>
    <option value="Sales">Sales</option>
    <option value="Marketing" >Marketing</option>
<textarea type="text" id="marketplaceDesc" name="description" value="" ...

80. Spring MVC 3 - Binding an 'immutable' object to a form

I have several thoroughly unit-tested and finely crafted rich DDD model classes, with final immutable invariants and integrity checks. Object's instantiation happens through adequate constructors, static factory methods and even via ...

81. Spring MVC Binding: How to bind ArrayList<...>?

I've got a DTO (bean) with ArrayList field:

public MyDTO {
  private List<MyThing> things;
  ... getters, setters and so on
In my initBinder I have:
public void initBinder(WebDataBinder ...

82. Spring MVC binding issue

In my spring mvc application, I have levels that users can create. With these levels, there are various requirements that a level needs in order to be taken (need a car, ...

83. [solved] binding nested model of list containing custom obj

[solved] binding nested model of list containing custom obj Hi.. i have a problem about a nested model object which is a list containing a collection of a custom class.. I ...

84. MVC - binding with AutoPopulatingList doesn't work

MVC - binding with AutoPopulatingList doesn't work I have a dynamic list of input fields that I want to bind to an AutoPopulatingList. I followed various tutorials ( on this but ...

85. [Spring MVC] Binding Overwriting Object in ModelAndView

[Spring MVC] Binding Overwriting Object in ModelAndView I am using Spring MVC 2.5.5. I have a controller that saves an object from an editing form and then returns to that form ...

86. Spring MVC dataType Binding issue

Spring MVC dataType Binding issue Hi, I'm fairly new to spring mvc. We created a jsp form with input fields and we are trying to set that value to a Hibernate ...

87. Spring MVC3. Bind addtional data before validation

Spring MVC3. Bind addtional data before validation I am developing an application whith Spring MVC 3.0.5. I use the @InitBinder method to initialize the binder and @Valid to validate forms I ...

88. MVC Binding

Is it possible to bind a value to a Map (which is directly on the request, and not on a backing object)? I have implemented the code from this JIRA, and ...

89. Binding Data to in Spring MVC

I have a component in my jsp page which binds to a collection. example Code: public class Test { private Sex sex; private String[] sexes = {"male", "female"}; public String[] ...

90. Binding @RequestHeader to model object

Hi, I want to be able to bind a @RequestHeader (or @CookieValue) to a model object. This seems to not work (but it does work for @RequestParam). Am I missing something, ...

91. spring mvc spring:bind

92. Binding form data using @ModelAttribute

Hi, As of now, I'm binding more than one datasets to my form using individual forms. For example: Code: @ModelAttribute("students") public Collection getStudents() { return this.sService.getStudents(); } @ModelAttribute("courses") public Collection getCourses() ...

93. Binding many-to-many list object on Spring MVC form

Binding many-to-many list object on Spring MVC form Hi, This should be a common scenario where we need to bind a list object to a spring form. However, I'm getting errors ...

94. options for mvc binding to domain object constructors...?

i saw an older post on this topic from 2008 and there was a discussion about adding setters and no arg-constructors to domain objects to allow for use at ui layer ...

95. MVC binding to wrong fields?

MVC binding to wrong fields? I have a controller with 2 methods that return related objects via the @ModelAttribute annotation: Code: @ModelAttribute("site") public Site getSite(){ ..... return site; } @ModelAttribute("document") public ...

96. Dynamic Data Binding in Spring MVC

97. Simple Spring MVC 3 Bind Form Question

Simple Spring MVC 3 Bind Form Question I have a simple html form,