最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Javascript form submission to activate Spring Web Flow transitions with JSF integration - Stack Overflow

programmeradmin2浏览0评论

I`m developing an application using Spring WebFlow 2, Facelets and JSF. One of my flows does have a page that must trigger a form submit at certain events. For each different action, a different view must be presented. So, I'm trying to activate the following javascript code to perform the submission:

function myFormSubmit( eventId ) {
   var formAction = document.myForm.action;
   document.myForm.action = formAction + '&_eventId=' + eventId;
   document.myForm.submit();
}

Unfortunatelly, this doesn't triggers the requested transition in my flow. The page doesn't change. Does anyone knows how to deal with this?

Thanks, Alexandre

I`m developing an application using Spring WebFlow 2, Facelets and JSF. One of my flows does have a page that must trigger a form submit at certain events. For each different action, a different view must be presented. So, I'm trying to activate the following javascript code to perform the submission:

function myFormSubmit( eventId ) {
   var formAction = document.myForm.action;
   document.myForm.action = formAction + '&_eventId=' + eventId;
   document.myForm.submit();
}

Unfortunatelly, this doesn't triggers the requested transition in my flow. The page doesn't change. Does anyone knows how to deal with this?

Thanks, Alexandre

Share Improve this question edited Nov 10, 2011 at 21:03 BalusC 1.1m376 gold badges3.7k silver badges3.6k bronze badges asked Dec 19, 2008 at 16:20 AlexandreAlexandre 1,0263 gold badges13 silver badges23 bronze badges 3
  • How is this event attached to your form ? What activates it ? – krosenvold Commented Dec 19, 2008 at 16:23
  • Regular form elements events? onchange, onclick, and so! – Alexandre Commented Dec 19, 2008 at 16:31
  • Please provide the HTML of the form you trying to submit, it makes it a lot easier to answer your question. – I.devries Commented Dec 19, 2008 at 18:08
Add a ment  | 

6 Answers 6

Reset to default 1

Don't know anything about SringFaceletsSF, but I think that event handler should probably return true. Otherwise your browser will not submit the form.

so:

function myFormSubmit( eventId ) {
   var formAction = document.myForm.action;
   document.myForm.action = formAction + '&_eventId=' + eventId;
   document.myForm.submit();
   return true;
}

On closer inspection, there are a bunch of problems with this code.

document.myForm.action is a non-standard way of getting elements. The better, cross-browser way is:

document.getElementById('myFormId');

Blindly appending an ampersand to the form action URL assumes that there is already another url parameter, and so there is already a question mark after the URL. If this is not the case the following line breaks:

document.myForm.action = formAction + '&_eventId=' + eventId;

Lastly, if you are calling this function as an onsubmit handler, I believe you should just return true, and not call the myForm.submit() method

I've got the solution in the Spring WebFlow forum. According to Jeremy Grelle, the submission of "_eventId" parameter does not trigger transitions when integrating Spring WebFlow to JSF. The solution he gave was to create a JSF PhaseListener that creates a JSF action when an "_eventId" parameter is sent.

The phaseListener code can be seen at http://forum.springsource/showthread.php?p=219358#post219358.

Modifying form.action is a very poor way of adding information to a form submission. I suggest putting a hidden input in your form that you can populate with your eventID.

Are you looking for this parameter in your GET params or your POST params? It won't appear in the POST.

Update:

ok,so to illustrate, try this...

change your function to do this:

function myFormSubmit( eventId ) {
   var formAction = document.myForm.action;
   //document.myForm.action = formAction + '&_eventId=' + eventId;
     var myAction = document.createElement('input');
     myAction.setAttribute('name', '_eventId');
     myAction.setAttribute('type', 'hidden');
     myAction.setAttribute('value', eventId);
     document.myForm.appendChild(myAction);
   document.myForm.submit();
}

Test in any (non-IE)* browser and see if it works. If so, the GET vs. POST param is the issue.

* non-IE: trying to set the name or type in IE will FAIL, thus don't test there.

Is there any reason you can't use the Spring Faces ponents which e with SWF? There's an ajaxEvent tag you can use to wrap elements. It activates on given javascript events (onclick, onchange) and invokes an action of your choice.

发布评论

评论列表(0)

  1. 暂无评论