Back Forum Reply New

spring:bind path problem

Hi,
I am a newbie, and I have tried to solve this issue tot he best of my ability, but was not able to solve it.

Basically I am getting
quot;javax.servlet.jsp.JspTagException: Neither Errors instance nor plain target object for bean name 'login' available as request attributequot; exception.

My code:hello.jsp
---------
lt;%@ include file=quot;/WEB-INF/jsp/include.jspquot; %gt;
lt;%@ taglib prefix=quot;springquot; uri=quot;/springquot; %gt;
lt;htmlgt; lt;headgt;   lt;meta from-equiv=quot;Content-Typequot; content=quot;text/html; charset=windows-1252quot;gt;   lt;titlegt;Testlt;/titlegt; lt;/headgt; lt;bodygt;
lt;form method=quot;postquot; action=quot;upload.htmquot;gt; ltgt;User Name:  lt;spring:bind path=quot;loginquot;gt; lt;input type=quot;textquot; name=quot;userquot; value=quot;quot;/gt; lt;/spring:bindgt;  lt;/Pgt; ltgtassword:  lt;input type=quot;passwordquot; name=quot;passwordquot; /gt; lt;/Pgt;  lt;spring:hasBindErrors name=quot;loginquot;gt;
lt;font color=quot;redquot;gt;lt;cut value=quot;${status.errorMessage}quot;/gt;lt;/fontgt;
lt;/spring:hasBindErrorsgt;     ltgt;   lt;input type=quot;submitquot; alignment=quot;centerquot; value=quot;Executequot;/gt; lt;/Pgt;  
lt;/formgt; lt;/bodygt;
lt;/htmlgt;
-------------------

LoginController.java
****************
package mypackage.web;
//ALL imports come here

public class LoginController extends SimpleFormController
{ public LoginController() { }   /** Logger for this class and subclasses */   protected final Log logger = LogFactory.getLog(getClass());
   //public ModelAndView onSubmit(Object command)throws Exception {   protected ModelAndView onSubmit(fromServletRequest request, fromServletResponse response,     Object command, BindException errors) throws Exception {         System.out.println(quot;IN LoginController.onSubmit()quot;);                  String username = ((LoginClass) command).getUser();         String password = ((LoginClass) command).getPassword();                  System.out.println(quot;username IN LoginController.onSubmit(): quot;+username);         System.out.println(quot;password IN LoginController.onSubmit(): quot;+password);
              logger.info(quot;returning from LoginController view to quot; + getSuccessView());
       //return new ModelAndView(new RedirectView(getSuccessView()));       return new ModelAndView(this.getSuccessView(), errors.getModel());   }
   protected Object formBackingObject(fromServletRequest request) throws ServletException {
       Object a = new Object();       return a;
   }

}
-----------------------------------

LoginClass.java
************

package mypackage.web;

public class LoginClass
{ public LoginClass() { }  String user; String password;
public void setPassword(String password) {   this.password = password; }

public String getPassword() {   return password; }

public void setUser(String user) {   this.user = user; }

public String getUser() {   return user; }
}
------------------------------

springapp-servlet.xml
******************

lt;?xml version=quot;1.0quot; encoding=quot;UTF-8quot;?gt;
lt;!DOCTYPE beans PUBLIC quot;-//SPRING//DTD BEAN//ENquot; quot;dtd/spring-beans.dtdquot;gt;

lt;!-- - Application context definition for quot;springappquot; DispatcherServlet. --gt;

lt;beansgt;   lt;bean id=quot;springappControllerquot; class=quot;mypackage.web.SpringappControllerquot;gt;   lt;/beangt;      lt;bean id=quot;testControllerquot; class=quot;mypackage.web.TestControllerquot;gt;   lt;/beangt;      lt;bean id=quot;loginControllerquot; class=quot;mypackage.web.LoginControllerquot;gt;         lt;property name=quot;commandNamequot;gt;lt;valuegt;loginlt;/valuegt;lt;/propertygt;       lt;property name=quot;commandClassquot;gt;lt;valuegt;mypackage.web.LoginClas  slt;/valuegt;lt;/propertygt;       lt;property name=quot;successViewquot;gt;lt;valuegt;hello1.htmlt;/valuegt;lt;/propertygt;                     lt;/beangt;      lt;bean id=quot;uclMappingquot; class=quot;org..web.servlet.handler.Sim  pleuclHandlerMappingquot;gt;       lt;property name=quot;mappingsquot;gt;lt;propsgt;    lt;prop key=quot;/hello.htmquot;gt;springappControllerlt;/propgt;    lt;prop key=quot;/hello1.htmquot;gt;testControllerlt;/propgt;     lt;prop key=quot;/upload.htmquot;gt;loginControllerlt;/propgt;   lt;/propsgt;       lt;/propertygt;   lt;/beangt;      lt;bean id=quot;viewResolverquot; class=quot;org..web.servlet.view.Intern  alResourceViewResolverquot;gt;       lt;property name=quot;viewClassquot;gt;lt;valuegt;org..web.se  rvlet.view.JstlViewlt;/valuegt;lt;/propertygt;       lt;property name=quot;prefixquot;gt;lt;valuegt;/WEB-INF/jsp/lt;/valuegt;lt;/propertygt;       lt;property name=quot;suffixquot;gt;lt;valuegt;.jsplt;/valuegt;lt;/propertygt;   lt;/beangt;
lt;/beansgt;

------------------------

Any help in this would be appreciated.

The spring bind tag binds form fields (parameters) to object (command) properties.  Right now, it looks like you're trying to bind it to the object itself.

So for starters, try something like:
lt;spring:bind path=quot;login.userquot;gt;
lt;input type=quot;textquot; name=quot;userquot; value=quot;quot;/gt;
lt;/spring:bindgt;

Note difference in path attribute.

Thanks for the reply.

I already tried that option, but still I got the same errors. I tried again now, but same errors.

Any help is really appreciated.

Thanks

I have a doubt. Why are you overriding
protected Object formBackingObject(fromServletRequest request)?

this returns an instance of the class of the command object in AbstractFormController. In your case it is returning a simple object?

Why are you doing that?

I think you should try this

protected Object formBackingObject(fromServletRequest request) throws ServletException {

LoginClass login = new LoginClass();
return login;

}

instead of this
protected Object formBackingObject(fromServletRequest request) throws ServletException {

Object a = new Object();
return a;

}

I'm with mazhar on this one.  In your configuration you've set the command class to be of type quot;mypackage.web.LoginClassquot;; however, formBackingObject is returning an object of type quot;Objectquot;.

Thanks for all the replies.

I am using now

protected Object formBackingObject(fromServletRequest request) throws ServletException {

LoginClass login = new LoginClass();
return login;

}But still I am having the same problem. Also I am using this method from a different example.

Thanks for your time and any more help would be much appreciated.

Where have you set the form view?  I do not see it in your configuration.  Both showForm methods of SimpleFormController use getFormView() in order to know which view to return.  So you should be getting a ServletException prior to even being able to get that JSPTagException.

Along those lines, what are you doing to get that exception?  Like accessing an ucl in a browser?  If so, what ucl are you using?  If you're calling hello.jsp quot;directlyquot;, the request won't have any attributes those spring tags want, which would explain the exception.  You'd want to use the ucl as defined in your ucl Mapping in your configuration so that the controller is run and returns the view (which will bring you back to the exception you should be getting as indicated in the first paragraph above).  If you don't use the path as defined in the mapping, you're not running LoginController at all.  You don't just want to quot;submit toquot; your extension of simpleformcontroller, you want to run it.  SimpleFormController (actually AbstractFormController) has logic (isFormSubmission) to determine whether or not you're just calling it to show a form or actually submitting a form.

So try entering this into your test browser: protocol--SERVER/CONTEXT/upload.htm

For example, foo/upload.htm

Thanks for the reply.

Actually in the examples I saw, there was no getFormView() used, so I was proceeding in the same way. If I need to use getFormView(), where should I use it?

Also I am accessing using .htm only. My index page redirects to hello.htm, which in turn will goto hello.jso after passing through the controller, but the ucl will display *.htm only.

Any examples on w here should I use getFormView() would be appreciated.

Thanks a lot.

You can just set it in your configuration like any other property:Code:
lt;bean id=quot;loginControllerquot; class=quot;mypackage.web.LoginControllerquot;gt;
...
lt;property name=quot;formViewquot;gt;lt;valuegt;hellolt;/valuegt;lt;/propertygt;
...
lt;/beangt;

The problem is that if you haven't set the form view, you shouldn't be able to even get to a view (JSP).  You should get a ServletException with a pretty verbose message explaining why.  So I don't know how you're even getting to a JSP that would throw a JSPTagException.

So I'd set the form view and then we can continue to see what's going on.
¥
Back Forum Reply New