Announcement Announcement Module
Collapse
No announcement yet.
Submitting a Form rendered from a XSLT view Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Submitting a Form rendered from a XSLT view

    Since the 'action' attribute is not needed in the <Form tag, how does the form know where to 'post' to?

    Here is my scenario:
    I am displaying the form using an XSLT view (bascially a list of hierarchical items with check boxes next to them)

    I would like to then select items and call a form to add the items to a cart, but how do I specify the form to call? Can I just post to a form extending SimpleFormController and specify the URL mapping to it in the urlMapping bean?

  • #2
    Originally posted by The author of [url=http://www.eps.surrey.ac.uk/FAQ/forms/formtag.html
    this page[/url]]... if [the "action" attribute] is absent, then the current document URL will be used.
    Originally posted by 2devnull
    I would like to then select items and call a form to add the items to a cart, but how do I specify the form to call?
    Simply specify the URL of your cart controller in the action of the form. For example:

    Code:
    <form action="add_to_cart.htm" method="post">
    Originally posted by 2devnull
    Can I just post to a form extending SimpleFormController and specify the URL mapping to it in the urlMapping bean?
    Yes.

    Comment


    • #3
      Hey,
      thanks, didn't want to assume too much. Better to ask.

      Comment


      • #4
        This is not working, the following is always empty:

        Code:
        protected ModelAndView onSubmit&#40;HttpServletRequest request, HttpServletResponse response, Object command, BindException errors&#41; throws Exception &#123;
        		
        
        		Map hm = WebUtils.getParametersStartingWith&#40;request, "ck"&#41;;

        hm is empty.

        Here is the HTML:

        Code:
        <input id="Common_rowSelect3" type="checkbox" name="ck_29AB1FFDD7E38311852568F20027AB66" value="29AB1FFDD7E38311852568F20027AB66">
        Any ideas how to get the value of the checked check boxes? I am using Velocity templates BTW.

        Comment


        • #5
          Why would the request object from the servlet API not contain any of the form input fields? I tried doing a

          Code:
          protected ModelAndView onSubmit&#40;HttpServletRequest request, HttpServletResponse response, Object command, BindException errors&#41; throws Exception &#123;
                
          
                Map hm = request.getParameterMap&#40;&#41;;

          and hm here is also empty. Where in the framework would the parameters be lost?

          Comment


          • #6
            Hmm. More info might help. Can you post the relevant parts of your *-servlet.xml (url/controller mappings, etc) and also the source of the controller(s) that this request is passing through?

            Comment


            • #7
              The code below is abbreviated is some cases to show only the relevant information.


              method-servlet.xml
              --------------------------
              Code:
              <!ENTITY path.secure.rootpath "/secure"> 
              <!ENTITY path.secure.index "&path.secure.rootpath;/index.htm">
              <!ENTITY path.cart.addtocart "&path.secure.rootpath;/cart/addtocart.htm">

              Code:
              <bean id="shopcartController" class="com.method.web.ShopCartFormController">
              		<property name="sessionForm">
              			<value>false</value>
              		</property>
              		<property name="commandName">
              			<value>shopcart</value>
              		</property>
              		<property name="commandClass">
              			<value>com.method.bo.ShopCart</value>
              		</property>
              		<property name="methodDBFacade">
              			<ref bean="method" />
              		</property>
              	</bean>

              Code:
              <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
              		<property name="interceptors">
              			<list>
              				<ref bean="localeChangeInterceptor" />
              			</list>
              		</property>
              		<property name="mappings">
              			<props>
              				<prop key="&path.index;">homeController</prop>
              				<prop key="&path.browse.search;">searchController</prop>
              				<prop key="&path.cart.addtocart;">shopcartController</prop>
              </props>
              </property>
              </bean>

              controller:
              ---------------------------
              Code:
              public class ShopCartFormController extends AbstractFormController  &#123;
              	/** Logger for this class and subclasses */
              	protected final Log logger = LogFactory.getLog&#40;getClass&#40;&#41;&#41;;
              
              	private MethodDBFacade methodDBFacade;
              
              
              	public void setMethodDBFacade&#40;MethodDBFacade facade&#41; &#123;
              		methodDBFacade = facade;
              	&#125;
              
              
              	protected boolean isFormSubmission&#40;HttpServletRequest arg0&#41; &#123;
              		return true;
              	&#125;
              
              
              	protected ModelAndView processFormSubmission&#40;HttpServletRequest request, HttpServletResponse arg1, Object arg2, BindException arg3&#41; throws Exception &#123;
              		Map hm = WebUtils.getParametersStartingWith&#40;request, "ck"&#41;;
              		logger.debug&#40;"hm in shopcart onSubmit is&#58; "+hm&#41;;
              		if &#40;hm!=null&#41; 
              			logger.debug&#40;"hm size&#58; "+hm.size&#40;&#41;&#41;;
              
              		return new ModelAndView&#40;"search"&#41;;
              	&#125;

              form
              ------------------------
              Code:
              <form action="$rc.getContextPath&#40;&#41;/secure/cart/addtocart.htm" method="post"  name="shopcart">
              
               <td width="1%" align="center"><input id="Common_rowSelect1" type="checkbox" name="ck_5A1930FC8A86706685256BF40049B60E" value="5A1930FC8A86706685256BF40049B60E"></td>
              
              <INPUT NAME="addtocart" TYPE="image" SRC="/images/buttons/addtobasket.gif" align="absmiddle" width="115" height="30">
              
              </form>

              Comment


              • #8
                I changed the controller to extend this and it's the same problem. Does anyone know where the issue might be?

                Code:
                public class ShopCartFormController extends AbstractController &#123;

                Comment


                • #9
                  I found the problem. Since users are allowed to browse the catalog without login in, they can select items and click 'Add to Cart', they are then prompted to authenticate using Acegi, which redirects the request from http to https and therefore the request parameters are gone.

                  Does anyone know how to avoid this with Acegi? since I need the users to browse the catalog as guest but authenticate before being able to add items to the cart.

                  Comment


                  • #10
                    I'm glad you found the problem.

                    First a question: is it required that users be authenticated before they add an item to the cart? I have not used many online catalogs that have such a requirement. Wouldn't it be more logical to allow them to add things to the cart as an anonymous user and them authenticate them before payment?

                    If that's totally of base, read on...

                    If it doesn't matter to have the items in the request string, submit the form as a GET request instead of a post. When Acegi has authenticated the user, I believe it will redirect to the URL that was originally requested.

                    You could also add some conditional logic to look for an add-cart request in a filter that executes before the Acegi filter. When an add-cart request is detected, store the items in session where they can be retrieved once the user has been authenticated. This solution seems like a last resort to me. If authentication fails or the user simply does not login, those cart items will be left in the session until it expires. That's not very elegant.

                    Comment


                    • #11
                      Actually, the shopping cart is persisted therefore they can retrieve it from any machine once they authenticate. Right now, I do have have it as anonymous using a cookie, but obviously if they use another machine it would not be there.

                      I will try the GET method approach and see if that would work for the Acegi problem. Thanks.

                      Comment

                      Working...
                      X