I’m using Spring 3.1.1.RELEASE. I have this command object …
@Entity
public class Contract {
@Id
@Column(name = "ID")
@GeneratedValue(strategy=GenerationType.AUTO)
private Integer id;
@OneToOne(fetch = FetchType.EAGER, targetEntity = Product.class)
@JoinColumn(name = "PRODUCT_ID")
@NotNull
private Product product;
@Column(name = "ORDER_ID")
@NotNull
private String orderId;
…
and what I want on my JSP form is to have a drop down list of products represent the product field. Once a user selects one and submits the form, it would populate the object’s “product” member field through the command object’s setProduct method. I know how to set up the String fields,
<form:input path="orderId" />
but what do I need to put in my controller and JSP so that when my request is submitted to the controller …
@RequestMapping(value = "/add", method = RequestMethod.POST)
public ModelAndView addContract(final Contract contract,
final BindingResult result) {
…
the Product field will be populated correctly?
The answer involved a little more than just the JSP select tag. It also required binders. If I have this class
I can register the binder in my controller …
Then in my JSP, I can have
and my selection will be bound to the “product” field of my command object.