Page 1 of 3 123 LastLast
Results 1 to 10 of 22

Thread: Processing forms in webscript which is part of page

  1. #1
    Join Date
    Sep 2010
    Posts
    8

    Default Processing forms in webscript which is part of page

    Hi all,

    I created a RESTful service (webscript) with a form on it. It processes GET (responds with a form) and POST (shows the result) at the moment. It works fine till I add that webscript to a page that contains other webscript components like header and footer. Once I submit the form I get exceptions that neither header nor footer supports the method POST.

    Please could someone advise what is the proper way to process forms? I don't want to include the whole page into the webscript respond because it goes against the main idea of surf (as I understand it) – arranging multiple components on one page.

    Thanks!

  2. #2

    Default

    You have two options, in the trunk we have added a feature so that all components fall back to the .get implementation if no .post implementation is found -this is ideal for POSTing to pages where you only want to add specific .post logic for some components - so update to trunk codeline will fix it for you. The other option is to add .post implementations for all the components on the page you are POSTing too - this is obviously annoying as it is a copy/paste exercise - but if you don't want to update to trunk that is your option currently.

    Cheers,

    Kev

  3. #3
    Join Date
    Jun 2010
    Location
    Reading
    Posts
    8

    Default

    If you do take the duplicate post file route then you can import the get js and freemarker files into the post files to avoid duplicating the file contents.

  4. #4
    Join Date
    Sep 2010
    Posts
    8

    Default

    Thanks a lot for the quick response.

    The behavior to fall back to the .get implementation for all the components that doesn't have .post is exactly what I would expect. Thanks for adding that feature!

  5. #5
    Join Date
    Sep 2010
    Posts
    8

    Default

    Tested. Everything works fine except... post parameters aren't reachable as
    args["paramName"]

  6. #6

    Default

    I assume you are talking about the .post implementation webscript? As you wouldn't expect POST params from a FORM to be available to .get webscript impls. Also if you are submitting a FORM then the data should be available in the "formdata" model object.

    Cheers,

    Kev

  7. #7
    Join Date
    Sep 2010
    Posts
    8

    Default

    Hi Kev,

    Yes, you're right, I'm talking about .post implementation of the mentioned above component. Unfortunately I wasn't able to see the parameters in the formdata as well, at least not in a debugger console. I will do more tests soon to double check it.

    As a side question, please could you clarify is there a proper way (I found some but not sure they are correct) of protecting /service/console on public server? Currently the scripts refreshing could lead to the whole site become unreachable.

    Thanks again for your quick response.

  8. #8

    Default

    >As a side question, please could you clarify is there a proper way (I found some but not sure they are correct) of protecting /service/console on public server? Currently the scripts refreshing could lead to the whole site become unreachable.

    To protect the scripts, override the following bean as follows:

    Code:
       <!-- Override WebScript View Resolver - authenticated for admin webscripts via alfresco-feed connector -->
       <bean id="webscriptViewResolver" class="org.springframework.extensions.webscripts.servlet.mvc.WebScriptViewResolver">
          <property name="container" ref="webscripts.container" />
          <property name="authenticatorFactory" ref="webscripts.authenticator.basic" />
       </bean>
    This ensure all console webscripts go through the 'webscripts.authenticator.basic' authenticator. We do this in Alfresco Share where we have the 'alfresco-feed' endpoint (used by that authenticator) authenticating using basic http auth against the Alfresco server.

    The other option is to remove those scripts from a runtime instance.

    Cheers,

    Kev

  9. #9
    Join Date
    Sep 2010
    Posts
    8

    Default

    Just rebuild the latest 1.0.0.CI-SNAPSHOT and "formdata" is not defined in .post script. Neither I can see the content of the formdata object in the debugger (but I see that formdata root object does exists).

    Thanks!

  10. #10

    Default

    OK. Can you give me a bit more detail - what are you posting (FORM data i assume since it's a page post) and what encoding? application/x-www-form-urlencoded or multipart/form-data?

Posting Permissions

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