0
votes

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

6
How is this event attached to your form ? What activates it ?krosenvold
Regular form elements events? onchange, onclick, and so!Alexandre
Please provide the HTML of the form you trying to submit, it makes it a lot easier to answer your question.I.devries

6 Answers

1
votes

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;
}
1
votes

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

1
votes

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.org/showthread.php?p=219358#post219358.

0
votes

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.

0
votes

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.
0
votes

Is there any reason you can't use the Spring Faces components which come 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.