Search code examples
formsatghtml-formhandler

ATG Formhandler:Need to set some values before calling the handle method


My requirement is I have a hidden form from where i am calling a handle method. Along with the handle method I am setting success and error url's as hidden values.

    <dsp:form action="blank.jsp" method="post" formid="UNIQUE_FORM_ID">
    <dsp:input bean="FormHandler.commitOrder" type="hidden" value="submit" />
    <dsp:input bean="FormHandler.commitOrderSuccessURL" type="hidden" value="SOME_VALUE" />  
    <dsp:input bean="FormHandler.commitOrderNotReadyURL" type="hidden" value="SOME_VALUE" />  
    </dsp:form>  

I need to set the successurl and errorUrl before calling the handle method.

I tried giving priority, but still its not working.

Thanks, Neenu


Solution

  • Here is a snippet of code that I tested and works.

    <dsp:importbean bean="/atg/commerce/order/purchase/CommitOrderFormHandler"/>
    
    <dsp:form action="blank.jsp" method="post" formid="commitForm">
        <dsp:input bean="CommitOrderFormHandler.commitOrderSuccessURL" type="hidden" value="success.jsp" />  
        <dsp:input bean="CommitOrderFormHandler.commitOrderErrorURL" type="hidden" value="failure.jsp" />  
        <dsp:input id="submitFormInput" bean="CommitOrderFormHandler.commitOrder" type="submit" style="position: absolute; left: -9999px; width: 1px; height: 1px;"/> 
    </dsp:form>
    
    <%-- 
        If your form (including the submit button) is hidden,
        then I assume that elsewhere on the page, you have some
        other way to trigger the submission of your hidden form.  
     --%>
    <button type="button" onclick="document.getElementById('submitFormInput').click()">Click Me!</button>
    

    A few key points here:

    1. Make sure to import the form handler you are using.
    2. Make sure the form handler you are using has an instance variable and a public getter/setter for each success/error url you are trying to set.
    3. You should have a <dsp:input> of type="submit" and bean="<form handler method you are trying to call>". If this must be hidden, you can hide it using CSS.
    4. In my code example I have included an HTML <button> tag to submit the form, but you can replace this with your submission method.