Hi!
I'm trying to display a list of elements in a form: options in one of my JSP, but if the validation finds any problem and the form must be refilled with the errors, I'm finding a problem to set the selected element in the form: options.
The entity for filling the form: options is this:
In my case, the label for the options is attribute "signature", and doing this it works perfect:Code:public class Researcher implements Serializable { private Integer researcherID; ... private String signature; }
The problem appears when I submit the form, and a error appears after validation (this error is in other field, not related to this options). The selected value in the select is converted to entity through a PropertyEditor. The code for it:Code:<form:options items="${researcherList}" itemLabel="signature" itemValue="researcherID"/>
After this... a error appears refilling the form, because Spring is trying to select the appropiate field in the form: options and uses the value to perfom equals operation in Researcher (watched in debug mode).Code:public class ResearcherPropertyEditor extends PropertyEditorSupport { private ResearcherService researcherService; public ResearcherPropertyEditor(ResearcherService researcherService) { this.researcherService = researcherService; } @Override public void setAsText(String text) { Researcher rese; try { rese = researcherService.getResearcher(new Integer(text)); setValue(rese); } catch (NumberFormatException e) { setValue(null); } catch (InstanceNotFoundException e) { setValue(null); } } @Override public String getAsText() { Researcher rese = (Researcher)getValue(); if (rese == null) return ""; return rese.getResearcherID().toString(); }
The solution is, perhaps, leaving as value the object represented in options, but I don't know the way to do that. Any idea to achieve this?
Thanks in advance


Reply With Quote