Announcement Announcement Module
Collapse
No announcement yet.
Now Infamous "Could not find Errors instance for bean & Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Now Infamous "Could not find Errors instance for bean &

    I am getting this seemingly common error when my form controller processes a request. I have poured through the forums and found one recommendation to change the (beanName).attribute to command.attribute in the spring bound form element. I have found that it is preferable to use the :

    return new ModelAndView(getFormView(), errors.getModel());

    when returning from the onSubmit method of the form controller. I have implemented both of these recommendations and still get this exception:

    org.apache.jasper.JasperException: Could not find Errors instance for bean [maintainJobLineItemMaintainFormController] in request: add the Errors model to your ModelAndView via errors.getModel()
    at org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:254)
    at org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:295)
    at org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:241)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:853)


    Here is the Formcontroller :

    package com.meyertool.controllers;

    import com.meyertool.controllers.formobjects.MaintainJobL ineItemForm;

    import com.meyertool.managers.MaintainJobLineItemManager;
    import com.meyertool.managers.MaintainJobManager;

    import com.meyertool.model.mpcs.JobLineItem;
    import com.meyertool.model.mpcs.JobLineItemPK;

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

    import org.springframework.validation.BindException;

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

    import java.util.HashMap;
    import java.util.Map;

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


    /**
    * Created by IntelliJ IDEA.
    * User: John
    * Date: Sep 2, 2004
    * Time: 8:51:13 AM
    * To change this template use File | Settings | File Templates.
    */
    public class MaintainJobLineItemMaintainFormController
    extends SimpleFormController {
    private static Log log = LogFactory.getLog(MaintainJobLineItemMaintainFormC ontroller.class);
    private MaintainJobManager mgr = null;

    public MaintainJobManager getMaintainJobManager() {
    return mgr;
    }

    public void setMaintainJobManager(MaintainJobManager mgr) {
    this.mgr = mgr;
    }

    public ModelAndView onSubmit(HttpServletRequest request,
    HttpServletResponse response, Object command, BindException errors)
    throws Exception {
    JobLineItem jobLineItem = (JobLineItem) command;
    String action = request.getParameter("action");


    if (action == null)
    {
    errors.reject(action, "Null Action Value");
    return new ModelAndView(getFormView(), errors.getModel());
    }

    if (action.equals("insert"))
    {
    mgr.insertLineItem(jobLineItem);
    }

    if (action.equals("update"))
    {
    mgr.updateLineItem(jobLineItem);
    }
    if (action.equals("delete"))
    {
    mgr.deleteLineItem(jobLineItem.getComp_id());
    }
    return new ModelAndView(getSuccessView(), errors.getModel());
    }

    protected ModelAndView returnJobItemListToView(String jobNo, BindException errors) {
    Map model = new HashMap();
    model.put("jobLineItemList", mgr.findJobLineItems(jobNo));
    model.put("errors" , errors.getModel());
    return new ModelAndView(this.getSuccessView(), model);
    }
    protected Object formBackingObject(HttpServletRequest request)
    {
    HttpSession session = request.getSession();
    JobLineItem lineItem = (JobLineItem)session.getAttribute("lineItem");
    String jobNo = request.getParameter("jobNo");
    if (lineItem != null )
    return lineItem;
    else
    {
    lineItem = new JobLineItem();
    JobLineItemPK pk = new JobLineItemPK();
    lineItem.setComp_id(pk);
    if (jobNo != null && jobNo.length() >0)
    lineItem.getComp_id().setJobNo(jobNo);
    return lineItem;
    }
    }
    }

    Here is the jsp :

    <%@ include file="/WEB-INF/jsp/include/include.jspf" %>
    <HTML>
    <title>Meyer Tool, Inc. - Add Job Item</title>
    <BODY>
    <TABLE WIDTH="620" CLASS="lightbluetable" CELLPADDING=2 CELLSPACING=0>
    <TR>
    <TD><span class="heading2">Add Job line item:</span></TD>
    </TR>
    <TR>
    <TD><span class="heading2small">Job: W175 Part#:1957M10</span></TD>
    </TR>
    <TR><TD><HR size="1"></TD></TR>
    </TABLE>
    <spring:bind path="maintainJobLineItemMaintainFormController">
    <h3><font color="red"><c:out value="${status.errorMessage}" /></font> <c:out value="${status.value}" /></h3>
    </spring:bind>
    <table class="lightbluetable" width="620" cellspacing="0" cellpadding="2">
    <tr>
    <form action="job_ss_add.jsp" method="post">
    <TD ALIGN="CENTER">
    <input type="HIDDEN" name="JOB_NO" value="W175">
    <input type="HIDDEN" name="JOB_LINE_ITEM_NO" value="1">
    <input type="HIDDEN" name="RES_NO" value="1957M10">
    <input type="HIDDEN" name="RES_TYPE" value="PART">

    <input type="BUTTON" onclick="parent.location='job_line_item_list.shtml ';MM_popupMsg('Line Item Add - Simulated')" value="Add Ship Schedule Item" tabindex="1">
    </TD>
    </form>



    <form action="job_ss_view.jsp" method="post">
    <TD ALIGN="CENTER">
    <input type="HIDDEN" name="JOB_NO" value="W175">
    <input type="HIDDEN" name="JOB_LINE_ITEM_NO" value="1">
    <input type="HIDDEN" name="RES_NO" value="1957M10">
    <input type="HIDDEN" name="RES_TYPE" value="PART">

    <input type="BUTTON" onclick="parent.location='line_item_list.shtml'" value="Back to View Line Items" tabindex="2">
    </TD>
    </form>

    <form action="<c:url value="/usr/cust-ord/ord-proc/maintain-job/addjobitem.html" />" method="POST" name="maintainJobLineItemForm">
    <TD ALIGN="CENTER">
    <input type="HIDDEN" name="JOB_NO" value="W175">
    <input type="HIDDEN" name="JOB_LINE_ITEM_NO" value="1">
    <input type="HIDDEN" name="RES_NO" value="1957M10">
    <input type="HIDDEN" name="RES_TYPE" value="PART">
    <input type="HIDDEN" name="action" value="insert">
    <input type="SUBMIT" value="Commit">
    </TD>
    </tr>
    <tr>
    <td COLSPAN="4"><HR SIZE="1"></td>
    </tr>
    </table>

    <TABLE WIDTH="620" CLASS="lightbluetable" CELLPADDING=2 CELLSPACING=0>

    <tr>
    <td>
    ITEM
    <spring:bind path="command.comp_id.jobLineItemNo"><input class="querybox" name="JOB_LINE_ITEM_NO" value="<c:out value="${status.value}" />" size="3" tabindex="5" onblur="MM_validateForm('JOB_LINE_ITEM_NO','','R') ;return document.MM_returnValue" maxlength="3"></spring:bind>
    <spring:bind path="command.comp_id.jobNo"><input class="querybox" name="JLI_LETTER" value="<c:out value="${status.value}" />" size="2" tabindex="6" maxlength="2"></spring:bind>
    P/R# <spring:bind path="command.comp_id.resourceNo"><input class="querybox" name="RESOURCE_NO" value="<c:out value="${status.value}" />" size="25" tabindex="7" onblur="MM_validateForm('RESOURCE_NO','','R');retu rn document.MM_returnValue" maxlength="25"></spring:bind>
    TYPE <spring:bind path="command.comp_id.resourceType"><input class="querybox" name="RESOURCE_TYPE" value="<c:out value="${status.value}" />" size="11" tabindex="8" onblur="MM_validateForm('RESOURCE_TYPE','','R');re turn document.MM_returnValue" maxlength="15"></spring:bind>
    MT BRAZE <spring:bind path="command.mtiBraze"><input class="querybox" name="MTI_BRAZE" value="<c:out value="${status.value}" />" size="1" tabindex="9" onblur="MM_validateForm('MTI_BRAZE','','R');return document.MM_returnValue" maxlength="1"></spring:bind>
    MT COAT <spring:bind path="command.mtiCoat"><input class="querybox" name="MTI_COAT" value="" size="1" tabindex="10" onblur="MM_validateForm('MTI_COAT','','R');return document.MM_returnValue" maxlength="1"></spring:bind>
    <br><br>
    QTY <spring:bind path="command.orderQuantity"><input class="querybox" name="ORDER_QUANTITY" value="<c:out value="${status.value}" />" size="6" tabindex="11" onblur="MM_validateForm('ORDER_QUANTITY','','R');r eturn document.MM_returnValue" maxlength="6"></spring:bind>
    UNIT$ <spring:bind path="command.unitPrice"><input class="querybox" name="UNIT_PRICE" value="<c:out value="${status.value}" />" size="13" tabindex="12" onblur="MM_validateForm('UNIT_PRICE','','R');retur n document.MM_returnValue" maxlength="13"></spring:bind>
    NO CHARGE <spring:bind path="command.nocharge"><input class="querybox" name="NOCHARGE" value="<c:out value="${status.value}" />" size="1" tabindex="13" maxlength="1"></spring:bind>
    EXTENSION$ <input class="displaybox" name="JLI_TOTAL_PRICE" value="$275,000" size="15" tabindex="14" maxlength="15">
    PAA <spring:bind path="command.paaNo"><input class="querybox" name="PAA_NO" value="" size="3" tabindex="15" maxlength="3"></spring:bind>
    <p>OVERSH <spring:bind path="command.allowableOvership"><input class="querybox" name="ALLOWABLE_OVERSHIP" value="<c:out value="${status.value}" />" size="6" tabindex="16" onblur="MM_validateForm('ALLOWABLE_OVERSHIP','','R ');return document.MM_returnValue" maxlength="6"></spring:bind>
    ITEM DESCR <spring:bind path="command.itenDescr"><input class="querybox" name="ITEM_DESCR" value="<c:out value="${status.value}" />" size="25" tabindex="17" onblur="MM_validateForm('ITEM_DESCR','','R');retur n document.MM_returnValue" maxlength="25"></spring:bind>
    JOB$ <spring:bind path="command.total"><input class="displaybox" name="TOTAL_JOB_PRICE" value="<c:out value="${status.value}" />" size="13" tabindex="18" maxlength="13"></spring:bind>
    VSE PENDING <spring:bind path="command.vsePending"><input class="querybox" name="VSE_PENDING" value="<c:out value="${status.value}" />" size="1" tabindex="19" maxlength="1"></spring:bind>
    <br>
    <br>
    IT COMM <spring:bind path="command.lineItemComment"><input class="querybox" name="LINE_ITEM_COMMENT" value="<c:out value="${status.value}" />" size="48" tabindex="20" maxlength="240"></spring:bind>
    REV <spring:bind path="command.jliRev"><input class="querybox" name="JLI_REV" value="<c:out value="${status.value}" />" size="3" tabindex="21" onblur="MM_validateForm('JLI_REV','','R');return document.MM_returnValue" maxlength="3"></spring:bind>
    QUOTE <spring:bind path="command.quoteNo"><input class="querybox" name="QUOTE_NO" value="<c:out value="${status.value}" />" size="6" tabindex="22" maxlength="6"></spring:bind>
    ITEM <spring:bind path="command.quoteLineItemNo"><input class="querybox" name="QUOTE_LINE_ITEM_NO" value="<c:out value="${status.value}" />" size="3" tabindex="23" maxlength="3"></spring:bind>
    <br>
    <br>
    P/R# <spring:bind path="command.qliResourceNo"><input class="querybox" name="QLI_RESOURCE_NO" value="<c:out value="${status.value}" />" size="25" tabindex="24" maxlength="25"></spring:bind>
    <spring:bind path="command.qliItemDescr"><input class="displaybox" name="QLI_ITEM_DESCR" value="<c:out value="${status.value}" />" size="25" tabindex="25" maxlength="25"></spring:bind>
    ERS? <spring:bind path="command.invoiceFlag"><input class="querybox" name="INVOICE_FLAG" value="<c:out value="${status.value}" />" size="1" tabindex="26" maxlength="1"></spring:bind></p>
    <p>S/I IT/P#/DS<spring:bind path="command.siResourceNo"><input class="querybox" name="SI_RESOURCE_NO" value="<c:out value="${status.value}" />" size="25" tabindex="27" maxlength="25"></spring:bind>
    <spring:bind path="command.siItemDescr"><input class="querybox" name="SI_ITEM_DESCR" value="<c:out value="${status.value}" />" size="25" tabindex="28" maxlength="25"></spring:bind>
    DUPL SNO? <spring:bind path="command.duplSno"><input class="querybox" name="DUPL_SNO" value="<c:out value="${status.value}" />" size="1" tabindex="29" onblur="MM_validateForm('DUPL_SNO','','R');return document.MM_returnValue" maxlength="1"></spring:bind>
    <br>
    <br>
    MTB/C cost: <spring:bind path="command.costItemNo"><input class="querybox" name="COST_ITEM_NO" value="<c:out value="${status.value}" />" size="3" tabindex="30" maxlength="3"></spring:bind>
    P/R <spring:bind path="command.costResourceNo"><input class="querybox" name="COST_RESOURCE_NO" value="<c:out value="${status.value}" />" size="25" tabindex="31" maxlength="25"></spring:bind>
    <spring:bind path="command.costResourceType"><input class="querybox" name="COST_RESOURCE_TYPE" value="<c:out value="${status.value}" />"size="5" tabindex="32" maxlength="15"></spring:bind>
    PRDC <spring:bind path="command.productCode"><input class="displaybox" name="PRODUCT_CODE" value="<c:out value="${status.value}" />" size="9" tabindex="33" maxlength="15"></spring:bind>
    <br>
    <br>
    TIME &amp; MATL - NO QUOTE <spring:bind path="command.noQuote"><input class="querybox" name="NO_QUOTE" value="<c:out value="${status.value}" />" size="1" tabindex="34" maxlength="1"></spring:bind>
    PRATTC CTO? <spring:bind path="command.ctoFlag"><input class="querybox" name="CTO_FLAG" value="<c:out value="${status.value}" />" disabled size="1" tabindex="35" maxlength="1"></spring:bind>
    <br>
    <br>
    </p>
    </td>
    </tr>
    <tr>
    <td colspan="4"></td>
    </tr>
    </form>
    </TABLE>
    </BODY>
    </HTML>

    Finally Here is the mapping :

    <bean id="maintainJobLineItemMaintainFormController" class="com.meyertool.controllers.MaintainJobLineIt emMaintainFormController" >
    <property name="commandName"><value>jobLineItem</value></property>
    <property name="commandClass"><value>com.meyertool.model.mpc s.JobLineItem</value></property>
    <!-- <property name="validator"><ref local="maintainJobMaintainValidator" /></property> -->
    <property name="formView"><value>usr/cust-ord/ord-proc/maintain-job/addjobitem</value></property>
    <property name="successView"><value>usr/cust-ord/ord-proc/maintain-job/addjobitem</value></property>
    <property name="maintainJobManager"><ref bean="maintainJobManager" /></property>
    <property name="sessionForm"><value>true</value></property>
    </bean>

    <bean id="urlMapping" class="org.springframework.web.servlet.handler.Sim pleUrlHandlerMapping">
    <property name="mappings">
    <props>
    <!-- default page -->
    <prop key="/mtwa.html">mtwaController</prop>
    <!-- maintain job mappings -->
    <prop key="/usr/cust-ord/ord-proc/maintain-job/search.html">maintainJobSearchFormController</prop>
    <prop key="/usr/cust-ord/ord-proc/maintain-job/maintain.html">maintainJobMaintainFormController</prop>
    <prop key="/usr/cust-ord/ord-proc/maintain-job/lineitemlist.html">maintainJobMultiActionControlle r</prop>
    <prop key="/usr/cust-ord/ord-proc/maintain-job/addjobitem.html">maintainJobLineItemMaintainFormCo ntroller</prop>
    </props>
    </property>
    </bean>

    I appreciate your help.

    Also, if you have a sample test case for a form controller in which the command object has a composite, self generated, primary key, I would appreciate getting my hands on it.

    Thank You;


    John Olmstead
    [email protected]

  • #2
    Hi John,
    I have similar action and
    Code:
    return new ModelAndView&#40;this.getFormView&#40;&#41;, errors.getModel&#40;&#41;&#41;;
    works fine for me. The difference is that my formview points to a tiles definition.

    Give this a try:
    Code:
    return new ModelAndView&#40;new RedirectView&#40;this.getFormView&#40;&#41;&#41;, errors.getModel&#40;&#41;&#41;;
    regards,
    markus

    Comment

    Working...
    X