Announcement Announcement Module
Collapse
No announcement yet.
Problem with form submission Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem with form submission

    Code:
    <bean id="configCtrl"
    		class="ro.project.spread.ConfigureController">
    		<property name="formView" value="pages/config" />
    		<property name="successView" value="pages/view-file"></property>
    	</bean>
    .. and the ConfigureController.java
    Code:
    public class ConfigureController extends GenericAction{
    
    	protected ModelAndView onSubmit(HttpServletRequest request) throws Exception {
    		// some calculations
    		return super.onSubmit(request);
    	}
    }
    GenericAction extends SimpleFormController.
    The problem is that after I submit the form, it simply goes to "view-file.htm", but does not excute the onSubmit(...)
    No errors.
    Can someone help me with this?
    Thank you.

  • #2
    onSubmit(HttpServletRequest request) is not a valid variant of onSubmit and is not called by SimpleFormController.

    You can override
    • onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors)
    • onSubmit(Object command)
    • onSubmit(Object command, BindException errors)
    see SimpleFormController

    Martin

    Comment


    • #3
      I've tried:
      Code:
       public class ConfigureController extends GenericAction{  
         
          protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception {  
               // some calculations  
               return super.onSubmit(request, response, command, errors);  
          }  
       }
      Same result.

      Comment


      • #4
        There are a few things(practices) which I would like to explain before posting the actual solution for this task:
        1. If you are submitting a form, you need to bind the form fields using a command class.I don't see a command class property injected in your controller bean.The command class is nothing but A POJO class.
        2. Now The code in your overridden method needs to be changed.You need to pass the model and view object in the return statement.
        3. I don't know how you are doing it, but the right way would have been your config controller extends SimpleFormController.THat would really help you in future maintanence.
        And If you don't want to use a form in a page and still want a controller, Then you can use AbstarctController from spring and override the handleRequestInternal Method.

        Now for the solution to your problem,
        define the command bean in your configCtrl bean using your pojo class.it should be something like this:
        Code:
        <property name="commandClass">
        			<value>com.projectname.pojo.pojoClassName
        			</value></property>
        <property name="commandName">
        			<value>pojoClassObjectName</value>
        		</property>
        The other thing you should do is add the following code in your onSubmit method.
        1. First map your command object with the pojo class
        2. Create a ModelAndView object.
        3. return the object with successView.
        Here it goes :
        Code:
                   PojoClassName pojoObjectName = (PojoClassName) command;
                   /* do any manipulation with pojo fields if you want now or if you want any processing to be done there*/
                   return new ModelAndView(getSuccessView());
        Remember to add
        Code:
        "redirect:pages/view-file"
        in your configCtrl bean definition for the successView property.

        I hope this helps you out & gets you moving in a positive direction.
        Cheers,
        Sushant

        Comment


        • #5
          configCtrl:
          Code:
          <bean id="configCtrl"
          		class="ro.wpcs.igdss.spreadsheet.controllers.ConfigureController">
          		<property name="formView" value="pages/config" />
          		<property name="successView" value="redirect:pages/view-file"></property>
          		<property name="commandClass" value="ro.wpcs.igdss.spreadsheet.base.SpreadsheetConfig"></property>
          		<property name="commandName" value="SpreadsheetConfig"></property>
          	</bean>
          ConfigureController.java :
          Code:
          protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception {
          SpreadsheetConfig spreadConfig = (SpreadsheetConfig) command;
          //some calculations
          return new ModelAndView(getSuccessView());
          }
          I get the same result, but I suspect its the way I submit the form, I'm not using a submit button. I do the submission using javascript and I don't know if that counts.
          Here is the form:
          Code:
          <form method="post" action="view-file.htm" name="configform"><textarea
          	rows="1" cols="1" style="visibility: hidden;" name="output" id="output">
          	</textarea>
          	
          </form>
          ... and the submission part in a .js file:
          Code:
          <a href='#' onclick='if (!confirm(\""+trans("You will lose your current work. Are you sure ?")+"\")) return false;' onchange='document.configform.submit(); ' accesskey='l'>"+trans("<input type='file' name='chooseFile' value='Load' />")</a>
          Thanks for the advices so far!

          Comment


          • #6
            Fixed it, the problem was the action field in the form, wrong path
            Thanks for the help!
            Tomita

            Comment


            • #7
              It's great to hear it worked !! I would also suggest you to use spring tag libraries and bind the text area field since you are submitting a form. Anyways, dat's all from my side.
              Cheers Tomita,
              Sushant

              Comment


              • #8
                Will do, thanks Sushant!

                Comment

                Working...
                X