Announcement Announcement Module
Collapse
No announcement yet.
Processing forms in webscript which is part of page Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • #16
    Can you let me know if you're still having trouble with this?

    I wanted to create an FV test using this example but found that it was failing so followed up with Kev and he'd tested the sample successfully through Alfresco Share web extensions (since it's a very quick way of testing Spring Surf code). When I tried the sample code in a standalone Spring Surf application it was failing (because the formdata.fields attribute is not getting set).

    We've started digging into this to discover what the differentiating factor is, but it looks like Spring MVC might also be parsing the request in standalone Spring Surf which is causing issues.

    I'll post back when we have a resolution.

    Regards,
    Dave

    Comment


    • #17
      We've got to the bottom of this...

      The original "spring-surf-application-petclinic" module included some unnecessary (and corrupting) Spring MVC configuration. In particular it included the lines:

      Code:
      <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
          <property name="maxUploadSize" value="10000000"/>
      </bean>
      ...which result in the CommonsMultipartResolver processing multipart requests and breaking the Spring Surf processing of them. Unfortunately, this configuration is also in the Spring Roo Add-on code so applications built using Roo will also get these unnecessary lines.

      Please check your "webmvc-config.xml" / "web-application-config.xml" files for this configuration and remove it to ensure that multipart form processing can be successfully handled by Spring Surf.

      Regards,
      Dave

      Comment


      • #18
        Originally posted by kroast View Post
        OK I have written a test case that shows formdata processing for a webscript is working. This is posting a form to the webscipt - not too a page, I haven't tried that yet, but it should just be a matter of mapping the page url args (which contain the formdata expect for "file" data) into the webscript component url (see my previous posts in the forums relating to this).

        testformdatamultipartprocessing2.post.desc.xml
        Code:
        <webscript>
          <shortname>Test formdata processing enabled</shortname>
          <description>Test forms with enctype of multipart/form-data</description>
          <url>/testformdatamultipartprocessing2</url>
          <authentication>none</authentication>
        </webscript>
        testformdatamultipartprocessing2.post.js
        Code:
        var result = (formdata != null);
        
        model.result = result;
        
        // should be a multi-part form
        model.isMultiPart = (formdata.getIsMultiPart());
        
        // example of getting a form field via the "args" map - but cannot get "file" field this way
        model.args_name = args.name;
        
        // Parse form attributes - including "file" field
        for each (field in formdata.fields)
        {
           switch (String(field.name).toLowerCase())
           {
              case "file":
                 if (field.isFile)
                 {
                    model.form_filename = field.filename;
                 }
                 break;
        
              case "name":
                 model.form_name = field.value;
                 break;
              
              case "title":
                 model.form_title = field.value;
                 break;
              
              case "hiddenvalue":
                 model.form_hiddenvalue = field.value;
                 break;
              
           }
        }
        testformdatamultipartprocessing2.post.html.ftl
        Code:
        <#if result>
        Success, formdata is available.<br>
        isMultiPart = ${isMultiPart?string}<br>
        arg.name = ${args_name}<br>
        name = ${form_name}<br>
        title = ${form_title}<br>
        name = ${form_hiddenvalue}<br>
        filename = ${form_filename}<br>
        <#else>
        Failed as no formdata!
        </#if>
        And the test html page that POSTs:
        testformdatamultipartprocessing2.html
        Code:
        <html>
           <head></head>
           <body>
              <form action="http://YOURSERVER:8080/YOURAPPSERVER/service/testformdatamultipartprocessing2" method="post" enctype="multipart/form-data" accept-charset="UTF-8" onsubmit="return validate();">
              <tr><td>Name:&nbsp;</td><td><input name="name" id="name" maxlength="1024"></td></tr>
              <tr><td>Title:&nbsp;</td><td><input name="title" maxlength="1024"></td></tr>
              <tr><td>File:&nbsp;</td><td><input name="file" type="file"></td></tr>
              <tr><td><input type="submit" name="submit" value="OK"></td></tr>
              <input type="hidden" name="hiddenvalue" value="BISCUITS">
              </form>
           </body>
        </html>
        Loading the page, filling in the fields (including selecting a file) and hitting OK gives me:
        Code:
        Success, formdata is available.
        isMultiPart = true
        arg.name = 1
        name = 1
        title = 2
        hiddenvalue = BISCUITS
        filename = alfresco_csrf.html
        Hope this helps!

        Kev
        Hi,

        I know this is an old topic but i need some help.

        I'm using this webscript as test, it works correctly if I post the form to the webscript, but when I post the form to a page, the webscript .js not have the formdata.

        How can I Map the formdata from the page to the webscript?

        Thanks in advance

        Comment


        • #19
          Originally posted by ddraper View Post
          We've got to the bottom of this...

          The original "spring-surf-application-petclinic" module included some unnecessary (and corrupting) Spring MVC configuration. In particular it included the lines:

          Code:
          <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
              <property name="maxUploadSize" value="10000000"/>
          </bean>
          ...which result in the CommonsMultipartResolver processing multipart requests and breaking the Spring Surf processing of them. Unfortunately, this configuration is also in the Spring Roo Add-on code so applications built using Roo will also get these unnecessary lines.

          Please check your "webmvc-config.xml" / "web-application-config.xml" files for this configuration and remove it to ensure that multipart form processing can be successfully handled by Spring Surf.

          Regards,
          Dave
          Did you make these changes?

          Comment


          • #20
            In my web-application-config.xml i haven't this lines.

            I'm using the same webscript but, without the "file" uploader, only text fields.
            Last edited by ruben.arjonilla; Mar 21st, 2011, 10:24 AM.

            Comment


            • #21
              I assume you are using RC1/2 not M3 (which was horribly broken)

              Comment


              • #22
                I was using M3...
                I upgraded to RC2 and now works fine.

                Thank you very much

                Comment

                Working...
                X