Einreichung von JavaScript -Formular zur Aktivierung des Spring -Web -Flow -Übergangs mit JSF -Integration

StackOverflow https://stackoverflow.com/questions/381434

Frage

Ich entwickle eine Anwendung mit Spring Webflow 2, Facelets und JSF. Einer meiner Ströme hat eine Seite, die bei bestimmten Veranstaltungen ein Formular auslösen muss. Für jede unterschiedliche Aktion muss eine andere Ansicht vorgestellt werden. Ich versuche also, den folgenden JavaScript -Code zu aktivieren, um die Einreichung durchzuführen:

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

Unglücklich, das löst den angeforderten Übergang in meinem Fluss nicht aus. Die Seite ändert sich nicht. Weiß jemand, wie man damit umgeht?

Danke, Alexandre

War es hilfreich?

Lösung 3

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.

Andere Tipps

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

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

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top