Results 1 to 5 of 5

Thread: Unable to get request attributes in formView of SimpleForm

  1. #1
    Join Date
    Dec 2004
    Posts
    4

    Default Unable to get request attributes in formView of SimpleForm

    Code:
    BrandReviewController extends AbstractCommandController
    BrandEditController  extends SimpleFormController
    BrandAddController extends SimpleFormController
    
    <bean id="brandReviewController"
    	class="com.web.mvc.BrandReviewController">
    	<property name="commandName"><value>brandCommand</value></property>
    	<property name="commandClass"><value>com.web.mvc.BrandCommand</value></property>
    </bean>
    	
    <bean id="brandEditController"
     		class="com.web.mvc.BrandEditController">
     		<property name="commandName"><value>brandCommand</value></property>
       		<property name="commandClass"><value>com.web.mvc.BrandCommand</value></property>
     		<property name="validator"><ref bean="brandAddValidator"/></property>
     		<property name="formView"><value>brandEditDef</value></property>
     		<property name="successView"><value>brandReviewDef</value></property>
    </bean>
    Flow:

    1) Click Brand Link in main page --> 2) BrandReviewController (Load Brand Data) --> 3) brand_review.jsp (display brand data loaded in step2)
    --> 4) Click on Edit button in brand_review.jsp --> 5) navigate to brand_edit.jsp (using formView property of brandEditController)


    Data bound (using spring:bind) in step4 ie. in brand_review.jsp is not able obtain in step 5 ie.brand_edit.jsp.

    I'm not submitting the form in step4. just clicking the button link <a href>

    Am I missing something here?? Do I need to submit the FORM in step 4??

    Thanks,
    Moorthi

  2. #2
    Join Date
    Aug 2004
    Location
    Montréal, Canada
    Posts
    845

    Default

    Moorthi,

    can you expand more on what data you send using your link, how your do to populate the data in brandEditController and what you put in your model before forwarding to the jsp?
    Omar Irbouh

    Spring Modules Team
    http://irbouh.blogspot.com/

  3. #3
    Join Date
    Dec 2004
    Posts
    4

    Default

    Hi Omar,

    In brand_review.jsp, I am binding brandCommand.brand.brandNo value. This binding is done based on the radio button (next to each brandNo) selection by the user. After choosing the radio button, when user clicks on button link (not submiting form) request is handled by (brandReview.do - brandEditController).

    Code:
    protected Object formBackingObject&#40;HttpServletRequest request&#41; throws Exception &#123;
    
    	log.debug&#40;"formBackingObject &#58; enter"&#41;;
    
    	if&#40;!isFormSubmission&#40;request&#41;&#41;&#123;
    		String param = request.getParameter&#40;"selectedBrandNo"&#41;;
    		BrandCommand brandCommand = &#40;BrandCommand&#41;getCommand&#40;request&#41;;
    
    		if&#40;brandCommand != null&#41;&#123;
    			String brandNo = brandCommand.getBrand&#40;&#41;.getBrandNo&#40;&#41;;
    			log.debug&#40;"formBackingObject = "+brandNo&#41;;
    		&#125;else&#123;
    			brandCommand = new BrandCommand&#40;&#41;;				//line - 27
    			if&#40;param != null&#41;&#123;
    				brand.setBrandNo&#40;param&#41;;
    				brandCommand.setBrand&#40;brand&#41;;
    			&#125;
    		&#125;
    		return brandCommand;
    	&#125;else &#123;
    		return new BrandCommand&#40;&#41;;
    	&#125;
    	
    &#125;
    Inside brandEditController, i'm overriding formBackingObject(HttpServletRequest request) in which i'm checking for isFormSubmission(request) and trying to get the brandCommand object (using getCommand()) that I bound in brand_review.jsp. For some reason I'm not able to get the command object here. (I guess calling getCommand is not appropriate..)

    Default implementation of formBackingObject always return new command object. But I want the existing command object with brandNo value in it.

    If I pass brandNo as a param-value, i'm able to get it using request.getParameter("param") [see line 27] and instantiate new brandCommand object. In formView (brand_edit.jsp) I'm able to get the brandCommand.brand.brandNo value. But I would prefer to use my existing brandCommand object instead of re-populating the value. Is this possible??

    Moorthi

  4. #4
    Join Date
    Aug 2004
    Location
    Montréal, Canada
    Posts
    845

    Default

    Moorthi,

    add the following to your controller configuration:
    Code:
      <property name="bindOnNewForm">
        <value>true</value>
      </property>
    HTH
    Omar Irbouh

    Spring Modules Team
    http://irbouh.blogspot.com/

  5. #5
    Join Date
    Dec 2004
    Posts
    4

    Default

    Hi Omar,

    I added "bindOnNewForm" property for my controller.

    Code:
    <bean id="brandEditController"
     		class="com.web.mvc.BrandEditController">
     		<property name="commandName"><value>brandCommand</value></property>
       		<property name="commandClass"><value>com.web.mvc.BrandCommand</value></property>
     		<property name="sessionForm"><value>true</value></property>
     		<property name="validator"><ref bean="brandAddValidator"/></property>
     		<property name="formView"><value>brandEditDef</value></property>
     		<property name="successView"><value>brandReviewDef</value></property>
     		<property name="bindOnNewForm"><value>true</value></property>
    </bean>
    calling getCommand(request) in formBackingObject(HttpServletRequest request) of my controller throws "Form object not found in session" exception msg.

    Code:
    javax.servlet.ServletException&#58; Form object not found in session
    	at org.springframework.web.servlet.mvc.AbstractFormController.getCommand&#40;AbstractFormController.java&#58;333&#41;
    	at com.web.mvc.BrandEditController.formBackingObject&#40;BrandEditController.java&#58;49&#41;
    	at org.springframework.web.servlet.mvc.AbstractFormController.getErrorsForNewForm&#40;AbstractFormController.java&#58;295&#41;
    	at org.springframework.web.servlet.mvc.AbstractFormController.showNewForm&#40;AbstractFormController.java&#58;277&#41;
    	at org.springframework.web.servlet.mvc.AbstractFormController.handleRequestInternal&#40;AbstractFormController.java&#58;233&#41;
    	at org.springframework.web.servlet.mvc.AbstractController.handleRequest&#40;AbstractController.java&#58;128&#41;
    	at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle&#40;SimpleControllerHandlerAdapter.java&#58;44&#41;
    	at org.springframework.web.servlet.DispatcherServlet.doService&#40;DispatcherServlet.java&#58;584&#41;
    	at org.springframework.web.servlet.FrameworkServlet.serviceWrapper&#40;FrameworkServlet.java&#58;366&#41;
    	at org.springframework.web.servlet.FrameworkServlet.doGet&#40;FrameworkServlet.java&#58;317&#41;
    	at javax.servlet.http.HttpServlet.service&#40;HttpServlet.java&#58;740&#41;
    	at javax.servlet.http.HttpServlet.service&#40;HttpServlet.java&#58;853&#41;
    	at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run&#40;ServletStubImpl.java&#58;996&#41;
    	at weblogic.servlet.internal.ServletStubImpl.invokeServlet&#40;ServletStubImpl.java&#58;419&#41;
    	at weblogic.servlet.internal.ServletStubImpl.invokeServlet&#40;ServletStubImpl.java&#58;315&#41;
    	at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run&#40;WebAppServletContext.java&#58;6452&#41;
    	at weblogic.security.acl.internal.AuthenticatedSubject.doAs&#40;AuthenticatedSubject.java&#58;321&#41;
    	at weblogic.security.service.SecurityManager.runAs&#40;SecurityManager.java&#58;118&#41;
    	at weblogic.servlet.internal.WebAppServletContext.invokeServlet&#40;WebAppServletContext.java&#58;3661&#41;
    	at weblogic.servlet.internal.ServletRequestImpl.execute&#40;ServletRequestImpl.java&#58;2630&#41;
    	at weblogic.kernel.ExecuteThread.execute&#40;ExecuteThread.java&#58;219&#41;
    	at weblogic.kernel.ExecuteThread.run&#40;ExecuteThread.java&#58;178&#41;

    Then I tried to override getFormSessionAttributeName() method to get proper command name.
    Code:
    protected String getFormSessionAttributeName&#40;&#41; &#123;
    			return isSessionForm&#40;&#41; ? getCommandName&#40;&#41; &#58; null;
    	&#125;
    Now I'm able to get the brandCommand object from session, but without the brandNo value that I bound in jsp (using spring:bind). Am I missing something??

    Moorthi

Similar Threads

  1. Hibernate Long Session Per Flow?
    By akw in forum Web Flow
    Replies: 21
    Last Post: Dec 12th, 2005, 08:06 PM
  2. Replies: 9
    Last Post: Nov 1st, 2005, 10:36 PM
  3. Beandoc crashing (on its samples!)
    By aaime in forum Container
    Replies: 17
    Last Post: Oct 7th, 2005, 07:21 AM
  4. Replies: 2
    Last Post: Sep 10th, 2005, 01:24 PM
  5. Replies: 8
    Last Post: Dec 7th, 2004, 06:13 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •