Announcement Announcement Module
Collapse
No announcement yet.
Again Neither BindingResult nor plain target object for bean name Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Again Neither BindingResult nor plain target object for bean name

    Hi. My first post!

    This issue is so popular i see. After 10 hours looking for an answer i really doesn't know what's happening here It's a common issue but the solution isn't unique i guess.

    index page
    Just a simple redirect page to login view ----> status: working

    login view
    I use <form:form> tag -----> status: working
    Code:
    <form:form commandName="login" name="login" method="POST">
                  <form:hidden path="" id="simulatorName" name="simulatorName" value="${sessionScope.simulatorName}"/>
                  <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td width="80" height="30" align="left" valign="middle">Usuario:</td>
                      <td align="left" valign="middle">
    	                  <form:input id="username" name="username" path="username" /><br/>
    	                  <font color="red"><form:errors path="username"/></font>
    	              </td>
    	            </tr>
    	            <tr>
                      <td width="80" height="30" align="left" valign="middle">Contraseņa:</td>
                      <td align="left" valign="middle">
                      	<form:input id="password" name="password" path="password"/><br/>
                      	<font color="red"><form:errors path="password"/></font>
                      </td>
                    </tr>
                    <tr>
                      <td width="80" height="30" align="left" valign="middle">&nbsp;</td>
                      <td align="right" valign="middle">
                      	<input type="submit" class="submit" value="Ingresar" />
                      </td>
                    </tr>
                  </table>
                </form:form>
    LoginController
    A simple form controller with selective view name. Validations are working, and database transactions too. According to the Eclipse debugger the ModelAndView object is returned ok.

    Code:
    @Override
    	protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws ServletException	{
    		ModelAndView modelAndView = null;
    		User user = (User) command;
    		User logged = this.getLoggedUser(user);
    		DisbursementSimulation simulation = new DisbursementSimulation();
    		Simulator simulator = new Simulator();
    		
    		log.info("user: " + user.getUsername());
    		log.info("password: " + user.getPassword());
    		log.info("type: " + user.getType());
    		log.info("sim: " + request.getParameter(SIMULATOR_NAME_PARAM_NAME));
    		
    		//fill simulators map
    		this.fillSimulatorsMap();
    		
    		if (logged != null)	{
    			
    			simulation.setUser(logged);
    			simulator.setUuid(this.simulatorMap.get(request.getParameter(SIMULATOR_NAME_PARAM_NAME)));
    			simulation.setSimulator(simulator);
    			
    			//operation is a String from a hidden text in login form
    			if(request.getParameter(SIMULATOR_NAME_PARAM_NAME).equalsIgnoreCase(ADDITIONAL_DAYS_RATE_SIMULATOR)) {
    				modelAndView = this.additionalDaysRate(request, response, simulation, errors);
    				
    			}	else if(request.getParameter(SIMULATOR_NAME_PARAM_NAME).equalsIgnoreCase(DISBURSEMENT_PROVIDER_RATE_SIMULATOR)) {
    				modelAndView = this.disbursementToProvider(request, response, simulation, errors);
    				
    			}	else if(request.getParameter(SIMULATOR_NAME_PARAM_NAME).equalsIgnoreCase(CDT_SIMULATOR)) {
    				modelAndView = this.cdt(request, response, simulation, errors);
    				
    			}	else if(request.getParameter(SIMULATOR_NAME_PARAM_NAME).equalsIgnoreCase(ADMIN_VIEW) && logged.getType() == 1) {
    				modelAndView = this.admin(request, response, simulation, errors);
    				
    			}	else	{
    				//TODO: generate error view. AJAX?
    				//modelAndView = new ModelAndView();
    				log.info("error here");
    			}
    			
    			//modelAndView.addObject(USER_UUID_PARAM_NAME, logged.getUuid());
    			//modelAndView.addObject(SIMULATOR_UUID_PARAM_NAME, this.simulatorMap.get(request.getParameter(SIMULATOR_NAME_PARAM_NAME)));
    		}
    		
    		log.debug(modelAndView.getViewName());
    		
    		return modelAndView;
    	}
    
    public ModelAndView disbursementToProvider(HttpServletRequest request, HttpServletResponse response,  DisbursementSimulation simulation, BindException errors)	{
    		return new ModelAndView(DISBURSEMENT_PROVIDER_RATE_SIMULATOR, DISBURSEMENT_PROVIDER_RATE_SIMULATOR + MODEL_SUFFIX, simulation);
    	}
    Test Case: DISBURSEMENT_PROVIDER_RATE_SIMULATOR view
    JSP: <form:form> tag again

    Code:
    <form:form commandName="simulationForm" id="simulation" name="simulationForm" method="POST">
    		      <fieldset class="field_1">
    		      <legend>Campos de entrada</legend>
    		      
    		      <table width="501" border="0" cellspacing="0" cellpadding="0">
    		        <tr>
    		          <td width="87" height="40" align="left" valign="middle">Spread</td>
    		          <td width="310" height="40" align="left" valign="middle">
    <!--		          	<form:input id="spread" name="spread" path="spread" /><br/>-->
    <!--		          	<font color="red"><form:errors path="spread"/></font>-->
    		          </td>
    		        </tr><tr>
    		          <td width="87" height="40" align="left" valign="middle">&nbsp;</td>
    		          <td width="310" height="40" align="right" valign="middle"><input type="submit" onclick="" class="button" name="cdt_simular" id="cdt_simular" value="Simular" /></td>
    		      </tr>
    	      </form:form>

  • #2
    sorry... continued

    And its Controller (SimpleFormController again)
    Code:
    @Override
    	protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws ServletException	{
    		ModelAndView modelAndView = null;
    		SimulationResult result;
    		Serializable pk = null;
    		List<String> simulationParams = new ArrayList<String>();
    		SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT);
    		
    		//get from data
    		DisbursementSimulation simulation = (DisbursementSimulation) command;
    		simulation.setSimulationDate(Calendar.getInstance().getTime());
    		//get simulator
    		Simulator simulator = null;//this.simulatorDao.getSimulator(Integer.valueOf(request.getParameter(SIMULATOR_UUID_PARAM_NAME)));
    		//get user
    		User user = new User();
    		user.setUuid(Integer.valueOf(request.getParameter(USER_UUID_PARAM_NAME)));
    		
    		//calculate simulation
    		result = this.calculate(simulation);
    		
    		//set simulations used parameters
    		simulationParams.add(dateFormat.format(simulation.getSimulationDate()));		//simulation date format DD/MM/YYYY
    		simulationParams.add(String.valueOf(simulation.getSpread()));					//spread
    		simulationParams.add(dateFormat.format(simulation.getDiscountDate()));			//discount date format DD/MM/YYYY
    		simulationParams.add(dateFormat.format(simulation.getExpirationDate()));		//expiration date format DD/MM/YYYY
    		simulationParams.add(String.valueOf(simulation.getInvoiceUS()));				//invoice US
    		simulationParams.add(String.valueOf(simulation.getExpirationDays()));			//spread
    
    		//set persistent values
    		if (simulator != null)	{
    			simulation.setSimulator(simulator);
    		}
    		simulation.setUser(user);
    		simulation.setSimulationParams(Utils.serializeParams(simulationParams));
    		
    		//add model
    		modelAndView = new ModelAndView("ajax_result");
    		modelAndView.addObject(SIMULATION_RESULT_PARAM_NAME, result);
    		return modelAndView;
    	}
    But here is the problem. I get an exception trying to render this view. Attach the stack trace of this exception:

    Code:
    java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'simulationForm' available as request attribute
    	at org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:141)
    	at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getBindStatus(AbstractDataBoundFormElementTag.java:174)
    	at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getPropertyPath(AbstractDataBoundFormElementTag.java:194)
    	at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getName(AbstractDataBoundFormElementTag.java:160)
    	at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.writeDefaultAttributes(AbstractDataBoundFormElementTag.java:123)
    	at org.springframework.web.servlet.tags.form.AbstractHtmlElementTag.writeDefaultAttributes(AbstractHtmlElementTag.java:408)
    	at org.springframework.web.servlet.tags.form.InputTag.writeTagContent(InputTag.java:140)
    	at org.springframework.web.servlet.tags.form.AbstractFormTag.doStartTagInternal(AbstractFormTag.java:102)
    	at org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:79)
    	at org.apache.jsp.WEB_002dINF.views.disbursementToProviderRateSimulator_jsp._jspx_meth_form_input_0(disbursementToProviderRateSimulator_jsp.java from :393)
    	at org.apache.jsp.WEB_002dINF.views.disbursementToProviderRateSimulator_jsp._jspService(disbursementToProviderRateSimulator_jsp.java from :129)
    	at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:109)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
    	at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:406)
    	at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:483)
    	at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:373)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
    	at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1523)
    	at org.apache.catalina.core.ApplicationDispatcher.doInvoke(ApplicationDispatcher.java:822)
    	at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:684)
    	at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:517)
    	at org.apache.catalina.core.ApplicationDispatcher.doDispatch(ApplicationDispatcher.java:488)
    	at org.apache.catalina.core.ApplicationDispatcher.dispatch(ApplicationDispatcher.java:379)
    	at org.apache.catalina.core.ApplicationDispatcher.dispatch(ApplicationDispatcher.java:336)
    	at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:314)
    	at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:238)
    	at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:250)
    	at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1031)
    	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:815)
    	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:717)
    	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
    	at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:560)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:754)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
    	at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1523)
    	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279)
    	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:188)
    	at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:641)
    	at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:97)
    	at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:85)
    	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:185)
    	at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:325)
    	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:226)
    	at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:165)
    	at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:791)
    	at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:693)
    	at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:954)
    	at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:170)
    	at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:135)
    	at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:102)
    	at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:88)
    	at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:76)
    	at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:53)
    	at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:57)
    	at com.sun.grizzly.ContextTask.run(ContextTask.java:69)
    	at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:330)
    	at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:309)
    	at java.lang.Thread.run(Thread.java:662)

    Comment


    • #3
      and continue again

      Web.xml
      Code:
      <!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
      	<context-param>
      		<param-name>contextConfigLocation</param-name>
      		<param-value>
      			/WEB-INF/spring/root-context.xml
      			/WEB-INF/app-persistence.xml
      		</param-value>
      	</context-param>
      	
      	<!-- Creates the Spring Container shared by all Servlets and Filters -->
      	<listener>
      		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
      	</listener>
      
      	<!-- Processes application requests -->
      	<servlet>
      		<servlet-name>appServlet</servlet-name>
      		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
      		<init-param>
      			<param-name>contextConfigLocation</param-name>
      			<param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
      		</init-param>
      		<load-on-startup>1</load-on-startup>
      	</servlet>
      		
      	<servlet-mapping>
      		<servlet-name>appServlet</servlet-name>
      		<url-pattern>*.html</url-pattern>
      	</servlet-mapping>
      	
      	<welcome-file-list>
      		<welcome-file>index.jsp</welcome-file>
      	</welcome-file-list>
      Servlet context
      Code:
      <!-- Enables the Spring MVC @Controller programming model -->
      	<annotation-driven />
      
      	<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
      	<resources mapping="/resources/**" location="/resources/" />
      	
      	<!-- Resolves views selected for rendering by AJAX requests -->
      	<beans:bean id="ajaxViewResolver" class="com.todo1.simulators.ajax.AjaxViewResolver">
              <beans:property name="ajaxView">
                  <beans:bean class="com.todo1.simulators.ajax.AjaxView" />
              </beans:property>
              <beans:property name="ajaxPrefix" value="ajax_"></beans:property>
          </beans:bean>
      
      	<!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
      	<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
      		<beans:property name="viewClass" value="org.springframework.web.servlet.view.JstlView"></beans:property>
      		<beans:property name="prefix" value="/WEB-INF/views/" />
      		<beans:property name="suffix" value=".jsp" />
      	</beans:bean>
      	
      	<beans:bean id="simpleUrlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
      		<beans:property name="mappings">
      			<beans:props>
      				<beans:prop key="/login.html">loginController</beans:prop>
      				<beans:prop key="/disbursementToProviderRateSimulator.html">disbursementToProviderRateController</beans:prop>
      			</beans:props>
      		</beans:property>
      	</beans:bean>
      Controllers.xml
      Code:
      <context:component-scan base-package="com.todo1.simulators" />
      	
      	<bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter" />
      	
      	<bean id="loginValidator" class="com.todo1.simulators.mvc.login.LoginValidator"/>
      	<bean id="loginController" class="com.todo1.simulators.mvc.login.LoginController">
      		<property name="validator"><ref bean="loginValidator"/></property>
      		<property name="commandName" value="login"/>
      		<property name="commandClass" value="com.todo1.simulators.mvc.login.User"/>
      		<property name="sessionForm"><value>true</value></property>
      		<property name="formView"><value>login</value></property>
      	</bean>
      
      <bean id="disbursementToProviderRateValidator" class="com.todo1.simulators.mvc.disbursementtoproviderrate.SimulationValidator"/>
      	<bean name="disbursementToProviderRateController" class="com.todo1.simulators.mvc.disbursementtoproviderrate.SimulationController">
      		<property name="validator"><ref bean="disbursementToProviderRateValidator"/></property>
      		<property name="commandName" value="simulationForm"/>
      		<property name="commandClass" value="com.todo1.simulators.mvc.disbursementtoproviderrate.DisbursementSimulation"/>
      		<property name="sessionForm"><value>true</value></property>
      		<property name="formView"><value>disbursementToProviderRateSimulator</value></property>
      	</bean>
      Thanks for read
      Any help would be appreciated

      Comment


      • #4
        Any idea guys?

        I think i have an error mapping controllers cause i ha the same issue with the login view before but i solved redirecting the view from index and avoiding load the view directly.

        Please help me

        Comment


        • #5
          trying...

          I tried this from a topic here:

          Code:
          @Override
          	protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception	{
          ModelAndView modelAndView = null;
          		User user = (User) command;
          		User logged = this.getLoggedUser(user);
          		DisbursementSimulation simulation = new DisbursementSimulation();
          		Simulator simulator = new Simulator();
          		//String selectedViewName = "";
          		
          		log.info("user: " + user.getUsername());
          		log.info("password: " + user.getPassword());
          		log.info("type: " + user.getType());
          		log.info("sim: " + request.getParameter(SIMULATOR_NAME_PARAM_NAME));
          		
          		//fill simulators map
          		this.fillSimulatorsMap();
          		
          		if (logged != null)	{
          			
          			simulation.setUser(logged);
          			simulator.setUuid(this.simulatorMap.get(request.getParameter(SIMULATOR_NAME_PARAM_NAME)));
          			simulation.setSimulator(simulator);
          }
          		
          		super.setSuccessView(request.getParameter(SIMULATOR_NAME_PARAM_NAME));
          		Map<String, Object> model = errors.getModel();
          		model.put(request.getParameter(SIMULATOR_NAME_PARAM_NAME) + MODEL_SUFFIX, simulation);
          		modelAndView = super.onSubmit(request, response, command, errors);
          		
          		log.debug("view name: " + modelAndView.getViewName());
          		
          		return modelAndView;
          But didn't work

          Comment


          • #6
            May be a senior member can help with this.

            May be i'm not mapping my controllers well or may be i'm missing something using the commandName param

            Comment


            • #7
              some comments to clarify

              May be some debug info can be handy

              Before loading login view (success render)
              modelAndView (mv)
              ModelAndView: reference to view with name 'login'; model is {login=com.todo1.simulators.mvc.login.User@4db3fe, org.springframework.validation.BindingResult.login =org.springframework.validation.BeanPropertyBindin gResult: 0 errors}
              After login and trying to render next view
              modelAndView (mv)
              ModelAndView: reference to view with name 'disbursementToProviderRateSimulator'; model is {login=com.todo1.simulators.mvc.login.User@4db3fe, org.springframework.validation.BindingResult.login =org.springframework.validation.BeanPropertyBindin gResult: 0 errors}
              model is User?? weird

              Also, i could see the request at the moment

              Request mappingData
              mappingData
              host: StandardEngine[com.sun.appserv].StandardHost[server]
              context: StandardEngine[com.sun.appserv].StandardHost[server].StandardContext[/t1-psf-simulators]
              wrapper: StandardEngine[com.sun.appserv].StandardHost[server].StandardContext[/t1-psf-simulators].StandardWrapper[appServlet]
              servletName: appServlet
              contextPath: /t1-psf-simulators
              requestPath: /login.html
              wrapperPath: /login.html
              pathInfo: null
              redirectPath: null
              pathInfo = null?? What the ... i really donīt get it

              Comment


              • #8
                some changes

                Ok guys. I changed my onSubmit method in my LoginController (SimpleFormController) following some recommendations of other topics:

                Code:
                protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception	{
                		ModelAndView modelAndView = null;
                		User user = (User) command;
                		User logged = this.getLoggedUser(user);
                		DisbursementSimulation simulation = new DisbursementSimulation();
                		Simulator simulator = new Simulator();	//TODO: get simulator
                		
                		//fill simulators map
                		this.fillSimulatorsMap();
                		
                		if (logged != null)	{
                			simulation.setUser(logged);
                			simulator.setUuid(this.simulatorMap.get(request.getParameter(SIMULATOR_NAME_PARAM_NAME)));
                			simulation.setSimulator(simulator);
                		}
                		
                		super.setSuccessView(request.getParameter(SIMULATOR_NAME_PARAM_NAME));
                		Map<String, Object> model = errors.getModel();
                		model.put(request.getParameter(SIMULATOR_NAME_PARAM_NAME) + MODEL_SUFFIX, simulation);
                		modelAndView = super.onSubmit(request, response, command, errors);
                		
                		log.info("view name: " + modelAndView.getViewName());
                		
                		return modelAndView;
                	}
                But still the same error

                Mappings of the SimpleUrlHandlerMapping (look good i guess):

                Code:
                INFO: INFO : org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - Mapped URL path [/disbursementToProviderRate.html] onto handler of type [class com.todo1.simulators.mvc.disbursementtoproviderrate.SimulationController]
                INFO: INFO : org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - Mapped URL path [/login.html] onto handler of type [class com.todo1.simulators.mvc.login.LoginController]
                I tried to track the error and it's here where the exception shows:

                org.springframework.web.servlet.view.AbstractView. java (line 250)
                renderMergedOutputModel(mergedModel, request, response);

                Comments??

                Thanks

                Comment


                • #9
                  Binding date objects with date form fields

                  I tested adding initBinder method for objects type Date

                  Code:
                  @Override
                      protected void initBinder(HttpServletRequest request,ServletRequestDataBinder binder) throws Exception	{
                  		DateFormat df = new SimpleDateFormat(DATE_FORMAT);
                  		CustomDateEditor editor = new CustomDateEditor(df, false);
                  		binder.registerCustomEditor(Date.class, editor);
                      }
                  And isn't working yet

                  Please guys help me. I don't have idea what's going on here.

                  I know it's a very common exception but i'm trying and i need help.

                  Comment


                  • #10
                    anyone????

                    Comment

                    Working...
                    X