PDA

View Full Version : AbstractCommandController



yogita.shetye
Sep 26th, 2005, 06:52 AM
I am a newbie to Spring and trying to implement AbstractCommandController. code for this is as follows:

public class MenuController extends AbstractCommandController
{
private ManualHandlerBPO manualHandlerBPO = null;

public ManualHandlerBPO getManualHandlerBPO() {
return manualHandlerBPO;
}

public void setManualHandlerBPO(ManualHandlerBPO manualHandlerBPO) {
this.manualHandlerBPO = manualHandlerBPO;
}

public MenuController()
{
setCommandClass(ManualCommand.class);
}

protected ModelAndView handle(HttpServletRequest arg0, HttpServletResponse arg1, Object command, BindException arg3)
throws Exception {

ManualCommand manCommand = (ManualCommand)command;
ManTO manTO = null;
manTO.setId(manCommand.getId());
long id = manTO.getId();
manTO = (ManTO) manualHandlerBPO.process(manTO);

return new ModelAndView("menu", "view", manTO);
}
}

I have also added command refernc in .xml file as

<bean id="MenuController" class="com.biomedcentral.export.mvc.MenuController">
<property name="manualHandlerBPO"><ref bean="ManualHandlerBPO"/></property>
<property name="commandClass"><value>com.biomedcentral.export.mvc.ManualCommand</value></property>
</bean>

but command object is not getting initialized. am i mising anything?

thanks in advance
---
yogita

Colin Yates
Sep 26th, 2005, 07:20 AM
Can you expand a bit please :)

Did you read the javadoc for the handle method which states
* <p>Call <code>errors.getModel()</code> to populate the ModelAndView model
* with the command and the Errors instance, under the specified command name,
* as expected by the "spring:bind" tag.

i.e. you need to do:


ModelAndView mav = new ModelAndView&#40;"menu", "view", manTO&#41;;
mav.addAllObjects&#40;errors.getModel&#40;&#41;&#41;;
return mav;