Hello,
I saw some threads already on this but because I'm a newb, I'm having trouble applying it to my program:
I'm writing a simple web app, that starts with a list of employees in a form that you select with a radio button. This employee that is selected plus the action is passed through the session to the next form for editing.
I wanted to bind the an Employee command object for Validating the form here is the dispatcher-servlet.xml
relevant methods in my EmployeeFormController( extends SimpleFormController) class are:Code:<bean id="employeeFormValidator" class="bus.EmployeeFormValidator"/> <bean id="employeeFormController" class="web.EmployeeFormController"> <property name="sessionForm"><value>true</value></property> <property name="commandName"><value>employee</value></property> <property name="commandClass"><value>bus.Employee</value></property> <property name="validator"><ref bean="employeeFormValidator"/></property> <property name="formView"><value>index</value></property> <property name="successView"><value>salaryincrease.htm</value></property> <property name="employeeManager"> <ref bean="emplMan"/> </property> </bean>
Code:@Override protected ModelAndView showForm(HttpServletRequest request, HttpServletResponse response, BindException errors, Map controlModel){ String now = (new java.util.Date()).toString(); logger.debug("returning index view with " + now); Map myModel = new HashMap(); myModel.put("now", now); myModel.put("employees", getEmployeeManager().getEmployees()); return new ModelAndView(getFormView(), "model", myModel); } @Override protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors){ String action = request.getParameter("action"); String id = request.getParameter("id"); logger.debug("action: " + action + " id: " + id); HttpSession sess = request.getSession(true); sess.setAttribute("action", action); sess.setAttribute("id", id); return new ModelAndView(new RedirectView(getSuccessView())); }
Relevant jsp code is:
Code:<spring:bind path="employee.id"> <c:forEach items="${model.employees}" var="empl"> <tr> <td><input type="radio" name="id" value="${empl.id}"/></td><td><c:out value="${empl.name}"/></td><td>$ <c:out value="${empl.salary}"/></td> </tr> </c:forEach> </spring:bind>
and finally the error im seeing:
and help to resolve the error as well as criticisms of best practices would be appreciated. thanks in advance.Code:2008-01-03 09:41:58,281 ERROR [org.springframework.web.servlet.tags.BindTag] - Neither BindingResult nor plain target object for bean name 'employee' available as request attribute javax.servlet.jsp.JspTagException: Neither BindingResult nor plain target object for bean name 'employee' available as request attribute at org.springframework.web.servlet.tags.BindTag.doStartTagInternal(BindTag.java:120) at org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:77) at org.apache.jsp.WEB_002dINF.jsp.index_jsp._jspService(index_jsp.java from :114) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:93)
-Matt


Reply With Quote
