I've got two DTO beans: Route and Worker. The relation is one to one, but i have to provide possibility of 'null' selection (No worker assigned to work on route).
Init binder looks like this:
This select control is basically working (I can change foreign key value in the db), but it does not render a 'selected' attribute. Also, I'd like to provide 'null' choice in this control.Code:@InitBinder public void initBinder(WebDataBinder binder) { final WorkerDao workerDao0 = workerDao; binder.registerCustomEditor(Worker.class, new PropertyEditorSupport() { @Override public void setAsText(String text) { Object value = null; try { Long id = Long.valueOf(text); value = workerDao0.findById(id); } catch (Exception e) { /*swallow*/ } setValue(value); } @Override public String getAsText() { Object value = getValue(); String retVal = null; if (value != null) { retVal = "" + ((Worker)value).getId(); } else { retVal = ""; } return retVal; } }); }
Code:<form:select path="worker" itemValue="id" itemLabel="description" items="${workerList}"/>


Reply With Quote