• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Junilu Lacar
  • Martin Vashko
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Scott Selikoff
  • salvin francis
  • Piet Souris

Getting Exception in SimpleFormController

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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>
 
You are HERE! The other map is obviously wrong. Better confirm with this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!