radone
Jan 23rd, 2005, 08:12 AM
Can anyone help me? I am desperate about this problem :-(
I have 2 classes Town -*------1-> Country :
public class Town extends BaseObject implements Serializable {
protected String postalCode;
protected String name_i18n;
protected Country country;
// getters and setters
}
public class Country extends BaseObject implements Serializable {
protected String code;
protected String name_i18n;
// getters and setters
}
All DAO and Services works correctly, even whole Countr, even displaying Town in SpringMVC. Problem came when I try to save class Town - which compose class Country:
## Error message ##
Failed to convert property value of type [java.lang.String] to required
type [org.appfuse.model.Country] for property 'country'
## Error Logs ##
[appfuse] DEBUG [http-8080-Processor24]
TownFormController.formBackingObject(78) | entering 'formBackingObject'
method...
[appfuse] DEBUG [http-8080-Processor24]
SimpleFormController.processFormSubmission(218) | Data binding errors: 1
## TownFormController ##
public class TownFormController extends BaseFormController {
private TownManager townManager = null;
public void setTownManager(TownManager townManager) {
this.townManager = townManager;
}
public ModelAndView onSubmit(HttpServletRequest request,
HttpServletResponse response, Object command, BindException errors)
throws Exception {
if (log.isDebugEnabled()) {
log.debug("entering 'onSubmit' method...");
}
Town town = (Town) command;
Locale locale = request.getLocale();
if (request.getParameter("delete") != null) {
townManager.removeTown(town.getPostalCode().toStri ng());
saveMessage(request, getText("town.deleted", locale));
} else if (request.getParameter("update") != null) {
townManager.updateTown(town);
saveMessage(request, getText("country.updated", locale));
return new ModelAndView("redirect:editTown.html", "id", town
.getPostalCode());
} else {
try {
townManager.saveTown(town);
} catch (DataAccessException e) {
// error message
saveError(request, getText("town.exists", locale));
request.setAttribute("town", town);
return new ModelAndView(getFormView());
}
saveMessage(request, getText("country.added", locale));
}
return new ModelAndView(getSuccessView());
}
protected Object formBackingObject(HttpServletRequest request)
throws Exception {
if (log.isDebugEnabled()) {
log.debug("entering 'formBackingObject' method...");
}
Country cc = new Country();
cc.setCode("CZ");
String id = request.getParameter("id");
Town town = null;
if (!StringUtils.isEmpty(id)) {
town = townManager.getTown(id);
return town;
} else {
town = new Town();
}
return town;
}
}
Any help will be very appreciated.
I have 2 classes Town -*------1-> Country :
public class Town extends BaseObject implements Serializable {
protected String postalCode;
protected String name_i18n;
protected Country country;
// getters and setters
}
public class Country extends BaseObject implements Serializable {
protected String code;
protected String name_i18n;
// getters and setters
}
All DAO and Services works correctly, even whole Countr, even displaying Town in SpringMVC. Problem came when I try to save class Town - which compose class Country:
## Error message ##
Failed to convert property value of type [java.lang.String] to required
type [org.appfuse.model.Country] for property 'country'
## Error Logs ##
[appfuse] DEBUG [http-8080-Processor24]
TownFormController.formBackingObject(78) | entering 'formBackingObject'
method...
[appfuse] DEBUG [http-8080-Processor24]
SimpleFormController.processFormSubmission(218) | Data binding errors: 1
## TownFormController ##
public class TownFormController extends BaseFormController {
private TownManager townManager = null;
public void setTownManager(TownManager townManager) {
this.townManager = townManager;
}
public ModelAndView onSubmit(HttpServletRequest request,
HttpServletResponse response, Object command, BindException errors)
throws Exception {
if (log.isDebugEnabled()) {
log.debug("entering 'onSubmit' method...");
}
Town town = (Town) command;
Locale locale = request.getLocale();
if (request.getParameter("delete") != null) {
townManager.removeTown(town.getPostalCode().toStri ng());
saveMessage(request, getText("town.deleted", locale));
} else if (request.getParameter("update") != null) {
townManager.updateTown(town);
saveMessage(request, getText("country.updated", locale));
return new ModelAndView("redirect:editTown.html", "id", town
.getPostalCode());
} else {
try {
townManager.saveTown(town);
} catch (DataAccessException e) {
// error message
saveError(request, getText("town.exists", locale));
request.setAttribute("town", town);
return new ModelAndView(getFormView());
}
saveMessage(request, getText("country.added", locale));
}
return new ModelAndView(getSuccessView());
}
protected Object formBackingObject(HttpServletRequest request)
throws Exception {
if (log.isDebugEnabled()) {
log.debug("entering 'formBackingObject' method...");
}
Country cc = new Country();
cc.setCode("CZ");
String id = request.getParameter("id");
Town town = null;
if (!StringUtils.isEmpty(id)) {
town = townManager.getTown(id);
return town;
} else {
town = new Town();
}
return town;
}
}
Any help will be very appreciated.