Announcement Announcement Module
Collapse
No announcement yet.
Problem after validating form data - Set option value Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem after validating form data - Set option value

    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:

    Code:
    public class Researcher implements Serializable
    {
    
         private Integer researcherID;
         ...
         private String signature;
    }
    In my case, the label for the options is attribute "signature", and doing this it works perfect:

    Code:
    <form:options items="${researcherList}" itemLabel="signature" itemValue="researcherID"/>
    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:
    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();
    	}
    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).

    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
Working...
X