Results 1 to 9 of 9

Thread: Could not find Errors instance

  1. #1
    Join Date
    Jan 2005
    Location
    Shanghai, PRC
    Posts
    4

    Default Could not find Errors instance

    javax.servlet.ServletException: Could not find Errors instance for bean 'report' in request: add the Errors model to your ModelAndView via errors.getModel()
    org.apache.jasper.runtime.PageContextImpl.doHandle PageException(PageContextImpl.java:825)
    org.apache.jasper.runtime.PageContextImpl.handlePa geException(PageContextImpl.java:758)
    org.apache.jsp.WEB_002dINF.views.report_jsp._jspSe rvice(report_jsp.java:373)...

    How can I fix this? I'm trying to create a basic MVC app with the SimpleFormController following the MVC-step-by-step documents. I've searched all over the Net and on these boards and I've found nothing that works.

    ------------------------------------------------
    /*
    * ReportFormController.java
    *
    * Created on January 30, 2005, 7:10 PM
    */

    package com.spacepirates.ispreport;

    import org.springframework.web.servlet.mvc.SimpleFormCont roller;
    import org.springframework.web.servlet.ModelAndView;
    import org.springframework.web.servlet.view.RedirectView;

    import org.springframework.validation.BindException;

    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;

    import java.io.IOException;
    import java.util.Map;
    import java.util.HashMap;

    import org.apache.commons.logging.Log;
    import org.apache.commons.logging.LogFactory;

    import java.text.SimpleDateFormat;
    /**
    *
    * @author scott
    */
    public class ReportFormController extends SimpleFormController {

    /** Logger for this class and subclasses */
    protected final Log logger = LogFactory.getLog(getClass());

    private ReportManager reportManager;
    private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd @ HH:mm:ss z");

    public ModelAndView onSubmit(Object command, BindException errors)
    throws Exception {

    String now = (new java.util.Date()).toString();

    Map myModel = new HashMap();

    myModel.put("now", now);
    myModel.put("reports", getReportManager().getReports());

    return new ModelAndView(new RedirectView(getSuccessView()),errors.getModel());
    }

    protected Object formBackingObject(HttpServletRequest request) throws ServletException {

    Report theReport = new Report();
    // set properties to some defaults... could be done in the Report class I suppose.
    theReport.setAddress("66.220.3.178");
    theReport.setIsp("China Telecom");
    theReport.setLocation("Shanghai");
    //theReport.setReporter("worker");
    theReport.setStatus("unreachable");

    java.util.Date now = new java.util.Date();

    theReport.setDateReported(sdf.format(now));

    return theReport;

    }

    public ReportManager getReportManager() {
    return reportManager;
    }

    public void setReportManager(ReportManager reportManager) {
    this.reportManager = reportManager;
    }


    }

  2. #2
    Join Date
    Aug 2004
    Location
    Amsterdam, Netherlands
    Posts
    450

    Default

    This won't work using a RedirectView.

    The RedirectView appends the model as query parameters to the newly generated request URL it redirects to, an Errors object will be toString'ed and appended to the URL, it's not an object anymore when arriving in the JSP redirected to...

    regards,
    Alef
    Alef Arendsen
    SpringSource
    http://www.springsource.com

  3. #3
    Join Date
    Jan 2005
    Location
    Shanghai, PRC
    Posts
    4

    Default thanks for the tip, what to do now?

    Is there any documentation for the MVC feature other than the 2003 MVC-step-by-step (which is obsolete)?

    Where can I see an example of the use of SimpleFormController?

    Using:
    return new ModelAndView(getSuccessView());
    or
    return new ModelAndView(getSuccessView(),errors.getModel());

    Doesn't work either.

    javax.servlet.ServletException: Neither Errors instance nor plain target object for bean name report available as request attribute
    org.apache.jasper.runtime.PageContextImpl.doHandle PageException(PageContextImpl.java:825)
    org.apache.jasper.runtime.PageContextImpl.handlePa geException(PageContextImpl.java:758)
    ...


    One working example is what I need.

  4. #4
    Join Date
    Aug 2004
    Location
    London, UK
    Posts
    339

    Default Re: thanks for the tip, what to do now?

    Quote Originally Posted by ShanghaiScott
    Is there any documentation for the MVC feature other than the 2003 MVC-step-by-step (which is obsolete)?
    The ref docs are online at http://www.springframework.org/docs/...nce/index.html, other than that there's the JavaDoc for the relevant classes and the sample applications included in the distributions.

    Regards,
    Darren Davison.
    Public Key: 0xE855B3EA

  5. #5
    Join Date
    Aug 2004
    Location
    Amsterdam, Netherlands
    Posts
    450

    Default

    Could you post your context configuring the form controller?
    Alef Arendsen
    SpringSource
    http://www.springsource.com

  6. #6
    Join Date
    Jan 2005
    Location
    Shanghai, PRC
    Posts
    4

    Default configuration

    <!-- Validator and Form Controller for the "Report" page -->
    <bean id="reportValidator" class="com.spacepirates.ispreport.ReportValidator"/
    >
    <bean id="reportForm" class="com.spacepirates.ispreport.ReportFormContro ller">
    <property name="sessionForm"><value>true</value></property>
    <property name="commandName"><value>Report</value></property>
    <property name="commandClass"><value>com.spacepirates.isprep ort.Report</valu
    e></property>
    <property name="validator"><ref bean="reportValidator"/></property>
    <property name="formView"><value>report</value></property>
    <property name="successView"><value>reports.htm</value></property>
    <property name="reportManager">
    <ref bean="reports"/>
    </property>
    </bean>

    The idea here was: replace the PriceIncrease class in the MVC step-by-step example, with my Report class...

  7. #7
    Join Date
    Dec 2004
    Location
    Amsterdam
    Posts
    15

    Default

    Don't use:
    Map myModel = new HashMap();

    Instead use:
    Map myModel = errors.getModel();

    Then add properties to myModel, and return modelAndView:
    return new ModelAndView(getSuccessView(),myModel);


    Hope that helps,
    Erik

  8. #8
    Join Date
    Jan 2005
    Location
    Shanghai, PRC
    Posts
    4

    Default tried that already

    As part of "programming by trial and error" which this shit forces me to do, I tried Map myModel = errors.getModel() and so on. Doesn't work either.

    I also tried something based on the jpetstore AccountFormController's onSubmit, but that doesn't work either.

    I really wish the example from MVC step-by-step actually worked. I would be done with my tiny project 2 days ago.

    Clearly I am doing something wrong! But without a working example, it's pretty hard to figure this out. Is the MVC step-by-step example really wrong? Why can't I just replace the PriceIncrease class with my Report class?

    Should I be using SpringFramework 1.1.x? Do most people still use 1.0?

  9. #9
    Join Date
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,104

    Default

    Are you still getting this error?

    Should I be using SpringFramework 1.1.x? Do most people still use 1.0?
    Why not look at the samples which are included in the distribution, and so are always up-to-date with the current release.

Similar Threads

  1. Beandoc crashing (on its samples!)
    By aaime in forum Container
    Replies: 17
    Last Post: Oct 7th, 2005, 07:21 AM
  2. Replies: 4
    Last Post: Oct 5th, 2005, 11:04 AM
  3. EHCaching Hibernate
    By dencamel in forum Data
    Replies: 3
    Last Post: Sep 6th, 2005, 09:03 PM
  4. DefaultAdvisorAutoProxyCreator skipping beans
    By youngm in forum Container
    Replies: 6
    Last Post: Apr 12th, 2005, 04:29 PM
  5. Replies: 2
    Last Post: Sep 10th, 2004, 08:47 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •