Thanks for your reply commer.
Thinking in the possibilities about using PropertyEditors, I want to know if this situation could be resolved using them:
Suposse that we have an Entity with some attributes, like this:
Code:
public class Researcher implements Serializable
{
private Integer researcherID;
...
private String signature;
...
}
(Attribute researcherID is the primary key (identifier) in database)
So, in the same situation explained in my first post (two list of elements to move elements from the left one to the right one and viceversa), suppose that I want to display in the form: options the researchers using:
Label --> signature
Value --> researcherID
¿Could be possible to define a CustomPropertyEditor to solve this situation? I try to do it, but the same error that I explained before appears.
Also, if is possible to do this, ¿ could be possible to send the information on the target list, and through the PropertyEditor convert automatically the value of the option to the corresponding Researcher to access them on the controller?
I try this:
Form to contain the two list of Researchers
Code:
public class ResearcherAddRemoveForm
{
private List<Researcher> availableElements;
private List<Researcher> currentElements;
...
}
CustomPropertyEditor
Code:
public class ResearcherPropertyEditor extends PropertyEditorSupport
{
@Autowired
private ResearcherService researcherService;
public ResearcherPropertyEditor(){}
@Override
public String getAsText()
{
Researcher r = (Researcher)getValue();
return r.getSignature();
}
@Override
public void setAsText(String text)
{
Researcher rese;
try
{
rese = researcherService.getResearcher(Integer.parseInt(text));
setValue(rese);
}
catch (NumberFormatException e)
{
setValue("");
}
catch (InstanceNotFoundException e)
{
setValue("");
}
}
}
Binding Initializer
Code:
public class LBDPortalBindingInitializer implements WebBindingInitializer
{
@InitBinder
public void initBinder(WebDataBinder binder, WebRequest request)
{
binder.registerCustomEditor(Researcher.class, new ResearcherPropertyEditor() );
}
}
XML servlet configuration
Code:
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="webBindingInitializer">
<bean class="es.udc.lbd.portal.http.controller.propertyeditors.LBDPortalBindingInitializer"/>
</property>
</bean>
¿Any ideas? Perhaps I am not understanding correctly the meaning of getAsText and setAsText...
The real thing I want to do is, when the form is submitted, send a list of researchers to the controller in the command object attribute "currentWriters". In a simple way, perhaps sending all values of the form: options to the controller things would be easy, but I don't know how to do it!