Javascript Form Submission for Activating Spring Web Flow Transitions with JSF Integration

I am developing an application using Spring WebFlow 2, Facelets and JSF. One of my threads has a page that should trigger form submission on certain events. For each other action, a different view must be presented. So I am trying to activate the following javascript code to execute the view:

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

      

Unfortunately this does not trigger the requested transition on my thread. The page does not change. Does anyone know how to deal with this?

Thank you, Alexander

0


source to share


6 answers


I have a solution on the Spring WebFlow forum. According to Jeremy Grelle, representing the "_eventId" parameter does not trigger transitions when integrating Spring WebFlow into JSF. The solution he gave was to create a JSF PhaseListener that creates a JSF action when the "_eventId" parameter is sent.



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

+1


source


Don't know anything about SringFaceletsSF, but I think the event handler should return true

. Otherwise, your browser won't submit the form.

So:



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

      

+1


source


Upon closer inspection, there are a number of issues with this code.

document.myForm.action is a non-standard way to get elements. Better, cross-browser way:

document.getElementById('myFormId');

      

Blindly adding an ampersand to the form action url assumes there is another url parameter and there is already a question mark after the url. If it is not, the next line breaks:

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

      

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

+1


source


Are you looking for this parameter in GET parameters or POST parameters? It will not appear in POST.

Update:

ok so for illustration 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 browser (not IE) * and see if it works. If so, the problem is GET vs. POST is a problem.

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

      

0


source


Modifying form.action is a very bad way to add information to a form submission. I suggest putting a hidden input into the form that you can fill out with your event ID.

0


source


Is there a reason you can't use the Spring Faces components that come with SWF? There is an ajaxEvent tag that you can use to wrap elements. It fires on given javascript events (onclick, onchange) and invokes an action of your choice.

0


source







All Articles