Tks for the advice katentim. I have made some tests but I'm still having problems:
I have created a custom property editor for Channel, here is it:
Code:
public class CustomChannelEditor extends PropertyEditorSupport {
private ChannelDao channelDao;
public CustomChannelEditor(ChannelDao channelDao) {
this.channelDao = channelDao;
}
public void setAsString(String text) {
System.err.println(": " + text);
if (StringUtils.hasText(text)) {
Channel channel = channelDao.load((Long) NumberUtils.parseNumber(text, Long.class));
if(channel == null) {
throw new IllegalArgumentException("Invalid Channel identification");
}
setValue(channel);
} else {
setValue(null);
}
}
public String getAsText() {
Channel value = (Channel) getValue();
return (value != null ? value.toString() : "");
}
}
I have passed a DAO via constructor to this class to load the Channel indexed by the id filled in form, that I guess is in text parameter.
So in my controller I have overide the initBinder, here is it:
Code:
protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws ServletException {
binder.registerCustomEditor(Channel.class, "channel.superChannel", new CustomChannelEditor(channelDao));
}
and again, here is my jsp:
Code:
<spring:bind path="channel.superChannel">
<td><fmt:message key="cms.channel.form.superchannel.text"/></td>
<td>
<select name="<core:out value="${status.expression}"/>" size="5" style="width: 300px;">
<core:forEach var="channel" items="${channels}">
<option value="<core:out value="${channel.id}"/>"<core:if test="${status.value == channel.id}"> selected</core:if>><core:out value="${channel.path}"/></option>
</core:forEach>
</select>
<br />
<font color="red"><core:out value="${status.errorMessage}"/></font>
</td>
</spring:bind>
The problem remains, I still getting this message error:
Code:
Failed to convert property value of type [java.lang.String] to required type [br.com.atom.cms.business.Channel] for property superChannel
Is there something that I have missed or that I have done wrong?
Regards.