| Author |
Getting Exception in SimpleFormController
|
Dipika Saxena
Greenhorn
Joined: Mar 27, 2006
Posts: 3
|
|
Hi all, I have written a controller extending from SimpleFormController. I want to check a session variable 'userid' and if that variable is not set, then redirect it to index page, otherwise render the form.. I'm using showForm() method for this.. protected ModelAndView showForm(HttpServletRequest request, HttpServletResponse response, BindException errors) throws Exception { HttpSession session = ((HttpServletRequest) request).getSession(false); String userid = (String)session.getAttribute("sessionUser"); if(userid == null) return new ModelAndView("redirect:index.htm"); else return new ModelAndView("changePwd"); } But it gives me following exception when session variable is set and it tries to render "changePwd.jsp"..Here 'updateProfileInfo' is command object. javax.servlet.ServletException: Neither Errors instance nor plain target object for bean name 'updateProfileInfo' available as request attribute org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:825) org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:758) org.apache.jsp.pages.changePwd_jsp._jspService(changePwd_jsp.java:295)
|
 |
Huy Tuan Nguyen
Greenhorn
Joined: Dec 10, 2004
Posts: 1
|
|
SimpleFormController offers showForm to handle the case when user is redirect to a new form (usually a GET). For submitting form, onSubmit is used (usually a POST). I read the following in Spring API: protected abstract ModelAndView showForm(HttpServletRequest request, HttpServletResponse response, BindException errors) throws Exception Prepare the form model and view, including reference and error data. Can show a configured form page, or generate a form view programmatically. A typical implementation will call showForm(request, errors, "myView") to prepare the form view for a specific view name, returning the ModelAndView provided there. For building a custom ModelAndView, call errors.getModel() to populate the ModelAndView model with the command and the Errors instance, under the specified command name, as expected by the "spring:bind" tag. You also need to include the model returned by referenceData. Note: If you decide to have a "formView" property specifying the view name, consider using SimpleFormController. Parameters: request - current HTTP request response - current HTTP response errors - validation errors holder Returns: the prepared form view, or null if handled directly So, if we use the default implementation of showForm of SimpleFormController i guess it will call the view (set in formView property) and populate the request attributes with command and error objects (though they are empty at this time). In your case, you want to use a customized model, so you should follow the API documentation above.
|
 |
sushma sree
Greenhorn
Joined: Mar 27, 2006
Posts: 12
|
|
Do you have a command class and command name mentioned in the config file? Try using onSubmit() instead and have <bean name="yourController" class="com........you controller class"> <property name="commandClass" value="your updateprofileclass" /> <property name="commandName" value="updateProfileInfo" /> </bean>
|
 |
 |
|
|
subject: Getting Exception in SimpleFormController
|
|
|