开发者

How to call server side action method just before submitting form to 3rd party url?

开发者 https://www.devze.com 2023-02-04 22:20 出处:网络
Ok, I\'m using Spring Webflow and I currently have a flow that involves two jsp pages (views), the second of which submits a form to a 3rd party system (payments).

Ok, I'm using Spring Webflow and I currently have a flow that involves two jsp pages (views), the second of which submits a form to a 3rd party system (payments).

In my pay-flow.xml I have states such as these;

<!-- Initial state, the jsp(view) gathers the number of items to purchase -->
<view-state id="buy" view="credit/buy" model="credit">
    <transition on="submit" to="createTrans" />
</view-state>

<!-- State not tied to a jsp, saves the "credit" object to the database -->
<action-state id="createTrans">
   <evaluate expression="creditAction.saveTrans(credit)"/>
   <transition to="w开发者_高级运维pRedirect"/>
</action-state>

<!-- Gathers some more info & has a form that submits to the 3rd party system -->
<view-state id="wpRedirect" view="credit/redirect">
    <transition on="accepted" to="showInvoice" history="invalidate">
    <evaluate expression="creditAction.reloadTrans(credit)" result="credit" />
</transition>
</view-state>

As you can see the process is basically like this;

1) Display 1st jsp, user enters some details, submits form

2) Save the model object to the database in the background

3) Display 2nd jsp, user enters more details and submits form

4) Form submits to a 3rd party URL, user interacts with 3rd party system

5) Eventually 3rd party redirects back into the flow

6) On "accepted" response, reload that previously saved model object

What I want to do is combine both jsps into one view and basically condense those three states into one. I've got some javascript and form controls to gather all the info together.

The question is, how can I still submit the form to the 3rd party URL but just before doing that, still call that "creditAction.saveTrans(credit)" on the server side? Obviously this needs to be transparent to the user, they should be happy the pages are now combined but still only have to click "Submit" at the end and have all the background saving and loading done without them knowing.

I was thinking I can put an onclick on the submit button, making it just a normal button and then submit the form from javascript similar to the following, but how can I call my server side code to save the model essentially on the line before .submit()?

function submitform() {
    <!-- call creditAction.saveTrans(credit) somehow??? -->
    document.forms["myform"].submit();
}


You have two choices:

1) use JavaScript to change the target and action of the form and submit it to a hidden IFrame, submit, then change it back to normal and submit it again.

2) Submit it using AJAX, then submit the form normally.

0

精彩评论

暂无评论...
验证码 换一张
取 消