Hey there, noob here trying to figure out Spring MVC. Been doing a lot of searching here and closely examining the step by step Spring MVC tutorial and can't find the answer to my problem.
I'm working on a site where the user logs in and then is directed to the home page. I've got the log in part working fine, but the re-direction to the home page is where I'm having problems.
The home page is a form, so I'm using a SimpleFormController bean:
here's my servlet xml:Code:public class CalendarController extends SimpleFormController { private CalendarManager calendarManager; private WorkoutManager workoutManager; public CalendarController() { super(); setSupportedMethods(new String[] {METHOD_GET, METHOD_POST}); setCommandClass(Month.class); } private ModelAndView handleWorkout(Month m) { return new ModelAndView("weightsWorkout"); } private ModelAndView handleCardio(Month m) { return new ModelAndView("cardioCalendar", "month", m); } private ModelAndView handleDiet(Month m) { return new ModelAndView("dietCalendar", "month", m); } public ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception { Month m = (Month)command; if(m.getActionType().equals("cardio")) { return handleCardio(m); } else if(m.getActionType().equals("diet")) { return handleDiet(m); } else { request.getSession().setAttribute("month", m); return handleWorkout(m); } } protected Object formBackingObject(HttpServletRequest request) throws ServletException { Month m = this.getCalendarManager().initializeCalendar(); System.out.println("formBackingObject"); return m; } public CalendarManager getCalendarManager() { return calendarManager; } public void setCalendarManager(CalendarManager calendarManager) { this.calendarManager = calendarManager; } public WorkoutManager getWorkoutManager() { return workoutManager; } public void setWorkoutManager(WorkoutManager workoutManager) { this.workoutManager = workoutManager; } }
and finally my jsp:Code:<bean id="calendarController" class="com.thegymjournal.controller.CalendarController"> <property name="sessionForm"><value>true</value></property> <property name="commandName"><value>month</value></property> <property name="commandClass"><value>com.thegymjournal.model.Month</value></property> <property name="calendarManager"><ref bean="calendarManager"/></property> <property name="workoutManager"><ref bean="workoutManager"/></property> </bean>
I keep getting this error :Code:<form:form method="post" action="home.htm" commandName="month"> <form:hidden path="selectedDate" /> <form:hidden path="actionType" /> <form:hidden path="action" /> <div id="calendarContainer" align="center"> <div class="week" align="center"> <input type="image" name="previousMonth" src="./images/resultset_previous.png" onclick="javascript:document.forms[0].submit();"/> <c:out value="${month.month}"/><c:out value=" ${month.intYear}"/> <input type="image" name="nextMonth" src="./images/resultset_next.png" onclick="javascript:document.forms[0].submit();"/> </div> <div class="week"> <div class="dayTitleHeader">Sun</div> <div class="dayTitleHeader">Mon</div> <div class="dayTitleHeader">Tues</div> <div class="dayTitleHeader">Wed</div> <div class="dayTitleHeader">Thur</div> <div class="dayTitleHeader">Fri</div> <div class="dayTitleHeader">Sat</div> </div> <c:forEach var="day" items="${month.days}" varStatus="status"> <div> <div class="day"> <div class="dayHeader"> <c:out value="${day.date}"/> </div> <div align="left"> <c:if test="${day.date >= 1}"> <c:choose> <c:when test="${(day.cardio == true) || (day.diet == true) || (day.weight == true)}"> <c:if test="${day.cardio == true}"> <input type="image" src="img/sneakers_32x32.gif" name="viewCardio" onclick="doSubmit('<c:out value="${day.calendarDate}"/>', 'view', 'cardio')"/> </c:if> <c:if test="${day.diet == true}"> <input type="image" src="img/grapes_32x32.gif" name="viewDiet" onclick="doSubmit('<c:out value="${day.calendarDate}"/>', 'view', 'diet')"/> </c:if> <c:if test="${day.weight == true}"> <input type="image" src="img/dumbbell_32x32.gif" name="viewWeights" onclick="doSubmit('<c:out value="${day.calendarDate}"/>', 'view', 'weights')"/> </c:if> </c:when> <c:otherwise> <input type="image" src="img/btn/icon_add_16x16.gif" name="addCardio" onclick="doSubmit('<c:out value="${day.calendarDate}"/>', 'add', 'cardio')"><c:out value="Cardio"/> </br> <input type="image" src="img/btn/icon_add_16x16.gif" name="addDiet" onclick="doSubmit('<c:out value="${day.calendarDate}"/>', 'add', 'diet')"><c:out value="Diet"/> </br> <input type="image" src="img/btn/icon_add_16x16.gif" name="addWeights" onclick="doSubmit('<c:out value="${day.calendarDate}"/>', 'add', 'weights')"><c:out value="Weights"/> </c:otherwise> </c:choose> </c:if> </div> </div> </div> </c:forEach> </div> </form:form>
org.apache.jasper.JasperException: java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'month' available as request attribute
but I know why - my month object isn't getting bound to the form. I have over-ridden the formBackingObject method, but for some reason this method is never called - thus resulting in the error above.
Any one see any reason why my formBackingObject method isn't being called? I know it's gotta be something simple and stupid on my part.
TIA
Matt


Reply With Quote

