Announcement Announcement Module
Collapse
No announcement yet.
Problem with "Neither Errors instance nor plain ...&quo Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem with "Neither Errors instance nor plain ...&quo

    Hello all.

    I am very new to Spring. I have a problem with one form and I can't find anything that looks like my problem on the forums here... So, if this has been answered many times before, please, just point me to the correct link and be merciful...

    My situation is: I have one form (which works just great) that displays a list of events. A user can select one of the events to display, edit, delete, etc that event. Or, he can create a new one. Once I select one to, say, modify. I get this exception:
    Code:
    javax.servlet.ServletException: Neither Errors instance nor plain target object for bean name '1' available as request attribute
    ...only, the '1' is replaced with the ID of the record from the event table (via Hibernate). The number displayed IS the ID of the event that is being selected.

    Here are my particulars:

    bean definition
    Code:
    <bean id="eventDetail" class="com.dpm.controllers.EventDetailFormController">
        <property name="dao"><ref bean="eventDao"/></property>
        <property name="sessionForm"><value>false</value></property>
        <property name="commandName"><value>eventDetail</value></property>
        <property name="commandClass"><value>com.dpm.forms.EventDataForm</value></property>
        <property name="formView"><value>eventdetail</value></property>
        <property name="successView"><value>eventmaint.dpm</value></property>
    </bean>
    Form controller code
    Code:
    public class EventDetailFormController extends SimpleFormController &#123;
    	private EventDAO dao;
    	
    	public EventDetailFormController&#40;&#41; &#123;
    		setCommandName&#40;"eventdetail"&#41;;
    	&#125;
    	
    	public void setDao&#40;EventDAO dao&#41; &#123;
    		this.dao = dao;
    	&#125;
    	
    	protected Object formBackingObject&#40;HttpServletRequest request&#41; throws ServletException &#123;
    		EventDataForm eventForm = null;
    		HttpSession session = request.getSession&#40;&#41;;
    		Integer action = &#40;Integer&#41;session.getAttribute&#40;"action"&#41;;
    		String eventId = &#40;String&#41;session.getAttribute&#40;"event"&#41;;
    		if &#40;&#40;null != eventId&#41; && &#40;eventId.length&#40;&#41; > 0&#41;&#41; &#123;
    			eventForm = new EventDataForm&#40;&#40;Events&#41;dao.getEvent&#40;new Integer&#40;eventId&#41;&#41;&#41;;
    			System.out.println&#40;"fetched event&#58; " + eventForm.getEventId&#40;&#41;&#41;;
    		&#125;
    		return eventForm;
    	&#125;
    	
    	public ModelAndView onSubmit&#40;HttpServletRequest request, HttpServletResponse response, Object command, BindException errors&#41; throws ServletException &#123;
    		System.out.println&#40;"got here too!"&#41;;
    		return new ModelAndView&#40;getSuccessView&#40;&#41;, errors.getModel&#40;&#41;&#41;;
    	&#125;
    &#125;
    the .JSP code
    Code:
    <%@ include file="/WEB-INF/jsp/include.jsp" %>
    
    <html>
      <head>
        <title><fmt&#58;message key="event.detail.title"/></title>
      </head>
      <body>
      	<h1><fmt&#58;message key="event.detail.title"/><br>
      	<form method="post">
      		<table width="90%" border="0" cellpadding="3" cellspacing="3">
      			<spring&#58;bind path="$&#123;eventDetail.eventId&#125;">
    	  			<tr><td><fmt&#58;message key="event.detail.id"/></td>
    	  			<td><input type="text" name="<c&#58;out value="$&#123;status.expression&#125;"/>" value="<c&#58;out value="$&#123;status.value&#125;"/>" readonly="true"/>
    	  			<font color="red"><b><c&#58;out value="$&#123;status.errorMessage&#125;"/></b></font></td></tr>
      			</spring&#58;bind>
      			<spring&#58;bind path="$&#123;eventDetail.eventName&#125;">
    	  			<tr><td><fmt&#58;message key="event.detail.name"/></td>
    	  			<td><input type="text" name="<c&#58;out value="$&#123;status.expression&#125;"/>" value="<c&#58;out value="$&#123;status.value&#125;"/>"/></td></tr>
      			</spring&#58;bind>
      			<spring&#58;bind path="$&#123;eventDetail.eventDate&#125;">
    	  			<tr><td><fmt&#58;message key="event.detail.date"/><td>
    	  			<td><input type="text" name="<c&#58;out value="$&#123;status.expression&#125;"/>" value="<c&#58;out value="$&#123;status.value&#125;"/>"/></td></tr>
      			</spring&#58;bind>
      			<spring&#58;bind path="$&#123;eventDetail.eventDescription&#125;">
    	  			<tr><td><fmt&#58;message key="event.detail.description"/></td>
    	  			<td><input type="text" name="<c&#58;out value="$&#123;status.expression&#125;"/>" value="<c&#58;out value="$&#123;status.value&#125;"/>"/></td></tr>
      			</spring&#58;bind>
      			<spring&#58;bind path="$&#123;eventDetail.region.regionName&#125;">
    	  			<tr><td><fmt&#58;message key="event.detail.region"/></td>
    	  			<td><input type="text" name="<c&#58;out value="$&#123;status.expression&#125;"/>" value="<c&#58;out value="$&#123;status.value&#125;"/>"/></td></tr>
      			</spring&#58;bind>
      			<spring&#58;bind path="$&#123;eventDetail.sponsor.sponsorName&#125;">
    	  			<tr><td><fmt&#58;message key="event.detail.sponsor"/></td>
    	  			<td><input type="text" name="<c&#58;out value="$&#123;status.expression&#125;"/>" value="<c&#58;out value="$&#123;status.value&#125;"/>"/></td></tr>
      			</spring&#58;bind>
      		</table>
      	</form>
      </body>
    </html>
    I KNOW I must be missing something, or simply doing something WRONG. But, right now, I'm frustrated, lost, and don't know where to turn other than the forums here. I've been fighting this for 2 days now. I'm lost.

    Thanks in advance for any advice.

  • #2
    So, if this has been answered many times before, please, just point me to the correct link and be merciful...
    Don't worry, this forum is friendly.

    Neither Errors instance nor plain target object for bean name '1' available as request attribute
    This error normally occurs when you have a mismatch between JSP bean name and the command name - not sure why you'd get the ID as the missing bean name - what's in the include.jsp?

    This probably doesn't have anything to do with it, but you set the command name in the constructor (incorrectly) as well as in the bean definition (correctly - this setting should reset it after the contructor).

    Comment


    • #3
      The contents of include.jsp are simply:
      Code:
      <%@ page session="false" %>
      
      <%@ taglib prefix="c" uri="http&#58;//java.sun.com/jstl/core" %>
      <%@ taglib prefix="fmt" uri="http&#58;//java.sun.com/jstl/fmt" %>
      <%@ taglib prefix="spring" uri="/spring" %>
      I started from the tutorial and have been adding functionality as I need it.

      Yeah, I caught the error in the constructor after I posted the original question. I was experimenting to see if the commandName made a difference, then added the line in the constructor (as mentioned in another thread), but, still the same.

      I still have no clue how the bean is being named from the ID of the record coming back from Hibernate.

      Comment


      • #4
        I DO know that the 'formBackingObject' method is getting called properly. I debugged it and the correct form is being populated with the correct objects/values. It's somewhere between the .jsp page being rendered and the bind tag.

        Comment


        • #5
          Can you post a small isolated test case?

          Comment


          • #6
            I'm very sorry. I'm not sure what information you need as part of the 'isolated test case'.

            Comment


            • #7
              I'm very sorry. I'm not sure what information you need as part of the 'isolated test case'.
              Just the smallest code possible that exibits the behaviour.

              Comment


              • #8
                Gotcha... I'm working on it.

                Comment


                • #9
                  commandName is nothing but a bean id - so has to be unique.

                  See if it works.

                  Comment


                  • #10
                    Did you solve this? I am using very similiar code and get the same error message.

                    "javax.servlet.jsp.JspTagException: Neither Errors instance nor plain target object for bean name 'customer' available as request attribute"

                    Comment


                    • #11
                      it's the little 'd' in the class...

                      remove the line : setCommandName("eventdetail");

                      from your form controller ... you're using eventDetail inside the jsp, note the capital D, but in your controller you're setting it to small d ... if you just let the commandName property in the xml load it you should be fine

                      Comment


                      • #12
                        you set the command name in the constructor (incorrectly)
                        Yeah, I caught the error in the constructor after I posted the original question
                        remove the line : setCommandName("eventdetail");
                        This doesn't seem to be the problem.

                        Comment


                        • #13
                          Make sure that JSP refers to the commandName ( bind tags) as specified in the bean configuration. Invalid bean names/ids in JSPs cause this error.

                          Also, I see a bean name conflict i.e., both the bean id and the commandName are same. Make them distinct and you are all set.


                          So here are few things for you to do:

                          remove from the constructor: setCommandName("eventdetail");
                          - This is already set using the properties in the configuration xml.

                          Either change the bean id 'eventDetail' to 'eventDetailController' and modify the corresponding handler mapping configuration in the xml if any.

                          or

                          set the commandName to 'eventDetailForm' and change your jsp to refer to this form name on your c:out(s) i.e., eventDetailForm.description .

                          Comment

                          Working...
                          X