|
|
Newbie problem with binding
I know this has been posted, documented etc just about everywhere, but I still can't get my simple app to work...
My controller is as follows:
Code:
public class TempController extends SimpleFormController
{ public TempController () { setCommandClass(ReportForm.class); } protected ModelAndView onSubmit(Object command) throws Exception { ReportForm reportForm= (ReportForm) command;
// This debug call represents the real business use case logger.debug(quot;got date: quot; + reportForm) ; return new ModelAndView(quot;dataquot;, quot;reportFormquot;, command.toString()); } protected Object formBackingObject(fromServletRequest request) throws Exception
{ ReportForm form = new ReportForm() ; form.setFromWeek(quot;06-Aug-2006quot;); return form;
}
}
My 'bean' class is
Code:
public class ReportForm { String fromWeek;
public String getFromWeek() { return fromWeek; }
public void setFromWeek(String fromWeek) { this.fromWeek = fromWeek;
}
in my servlet.xml...Code:
lt;?xml version=quot;1.0quot; encoding=quot;UTF-8quot;?gt;
lt;!DOCTYPE beans PUBLIC quot;-//SPRING//DTD BEAN//ENquot; quot;dtd/spring-beans.dtdquot;gt;
lt;!-- Application context definition for dnamis DispatcherServlet. rev : 06 Aug 06 --gt;
lt;beansgt;
lt;bean id=quot;headerControllerquot; class=quot;com.db.dna.rtmis.mvc.HeaderControllerquot;/gt;
lt;bean id=quot;dataControllerquot; class=quot;com.db.dna.rtmis.mvc.DataControllerquot;/gt;
lt;bean id=quot;weeklySummaryControllerquot; class=quot;com.db.dna.rtmis.mvc.WeeklySummaryControllerquot;/gt;
lt;bean id=quot;tempControllerquot; class=quot;com.db.dna.rtmis.mvc.TempControllerquot;/gt;
lt;bean id=quot;messageSourcequot; class=quot;org..context.support.ResourceBundleMessageSourcequot;gt; lt;property name=quot;basenamequot;gt;lt;valuegt;messageslt;/valuegt;lt;/propertygt; lt;/beangt;lt;!-- important !
these mapping properties allow the ucl to be resolved to the right jsp via
the appropriate handler
--gt;
lt;bean id=quot;uclMappingquot; class=quot;org..web.servlet.handler.SimpleuclHandlerMappingquot;gt;
lt;property name=quot;mappingsquot;gt;
lt;propsgt;
lt;prop key=quot;header.doquot;gt;headerControllerlt;/propgt;
lt;prop key=quot;dataold.doquot;gt;weeklySummaryControllerlt;/propgt;
lt;prop key=quot;data.doquot;gt;tempControllerlt;/propgt;
lt;/propsgt;
lt;/propertygt;
lt;/beangt;
lt;bean id=quot;viewResolverquot; class=quot;org..web.servlet.view.InternalResourceViewResolverquot;gt;
lt;property name=quot;viewClassquot;gt;lt;valuegt;org..web.servlet.view.JstlViewlt;/valuegt;lt;/propertygt;
lt;property name=quot;prefixquot;gt;lt;valuegt;/WEB-INF/jsp/lt;/valuegt;lt;/propertygt;
lt;property name=quot;suffixquot;gt;lt;valuegt;.jsplt;/valuegt;lt;/propertygt;
lt;/beangt;lt;/beansgt;
and my jspCode:
lt;spring:bind path=quot;reportForm.fromWeekquot;gt; lt;tdgt; lt;INPUT TYPE=quot;textquot; NAME=quot;fromWeekquot; value=quot;lt;c ut value=quot;${status.value}quot;/gt;quot;gt; lt;ing hrcf=quot;#quot; src=quot;images/calendar.gifquot; alt=quot;Calendarquot; title=quot;Click for pop-up Calendarquot; onClick=quot;cal.select(document.forms['calendar'].fromWeek,'anchor1','dd-NNN-yyyy'); return false;quot; NAME=quot;anchor1quot; ID=quot;anchor1quot;/gt; lt;/spring:bindgt;
What I'm trying to do is bind the fromWeek value into my ReportForm class. I'm aware that my code posted may be horribly wrong (I've tried so many examples that I'm not sure what I'm doing anymore) - I would really really appreciate any help whatsoever as I'm at my wits end!
Hi
Read through your code, I think that there are some errors
protected ModelAndView onSubmit(Object command) throws Exception { ReportForm reportForm= (ReportForm) command;
// This debug call represents the real business use case logger.debug(quot;got date: quot; + reportForm) ; return new ModelAndView(quot;dataquot;, quot;reportFormquot;, command.toString()); }
your return ModelAndView may be wrong. It should be something like ModelAndView(String viewName, String modelName, Object modelObject)... Check doc.
lt;bean id=quot;tempControllerquot; class=quot;com.db.dna.rtmis.mvc.TempControllerquot;/gt;
You mayneed formView or successView.....
In your jsp you have
Code:
lt;spring:bind path=quot;reportForm.fromWeekquot;gt; lt;tdgt; lt;INPUT TYPE=quot;textquot; NAME=quot;fromWeekquot; value=quot;lt;c ut value=quot;${status.value}quot;/gt;quot;gt; lt;ing hrcf=quot;#quot; src=quot;images/calendar.gifquot; alt=quot;Calendarquot; title=quot;Click for pop-up Calendarquot; onClick=quot;cal.select(document.forms['calendar'].fromWeek,'anchor1','dd-NNN-yyyy'); return false;quot; NAME=quot;anchor1quot; ID=quot;anchor1quot;/gt; lt;/spring:bindgt;
However that is not entirely correct. I think that when you change the name value of you input tag to {status.expression} it is going to work like a charm.Code:
lt;spring:bind path=quot;reportForm.fromWeekquot;gt; lt;tdgt; lt;INPUT TYPE=quot;textquot; NAME=quot;lt;c ut value=quot;${status.expression}quot;/gt;quot; value=quot;lt;c ut value=quot;${status.value}quot;/gt;quot;gt; lt;ing hrcf=quot;#quot; src=quot;images/calendar.gifquot; alt=quot;Calendarquot; title=quot;Click for pop-up Calendarquot; onClick=quot;cal.select(document.forms['calendar'].fromWeek,'anchor1','dd-NNN-yyyy'); return false;quot; NAME=quot;anchor1quot; ID=quot;anchor1quot;/gt; lt;/spring:bindgt;mand=org..validation.BindException: BindException: 0 errors}] neither contains a view name nor a View object in servlet with name 'rtmis'
Why would the view be returning null if I'm passing through the correct view and some data to it? |
|