JQuery, JSF et a4j: commandLink
-
06-07-2019 - |
Question
Je rencontre un problème d'utilisation de jQuery Dialog et Ajax dans JSF. J'ai le code suivant pour afficher les fenêtres de dialogue:
<script type="text/javascript">
jQuery(function(){
// Dialog
jQuery('#dialog').dialog({
dialogClass: 'alert',
autoOpen: false,
width: 300,
height: 150,
modal: true,
resizable: false,
overlay: {
backgroundColor: '#000',
opacity: 0.5
},
buttons: {
"Ok": function() {
jQuery(this).dialog("close");
return true;
},
"Cancel": function() {
jQuery(this).dialog("close");
return false;
}
}
});
// Dialog Link
jQuery('#dialog_link').click(function(){
jQuery('#dialog').dialog('open');
return false;
})
.hover(
function() { jQuery(this).addClass('ui-hover-state'); },
function() { jQuery(this).removeClass('ui-hover-state'); }
);
});
</script>
It works as it should - it displays box when link is clicked.
Now, I have something like this, for deleting something:
<a4j:commandLink
actionListener="#some.action"
reRender="something"
onclick="if(!jQuery('#dialog').dialog('open')){return false}"
ok, this commandLink is rendered as follows:
<a href="#"
id="some:long:id:j_id338"
name="formName:something:j_id338"
onclick="if(!jQuery('#dialog').dialog('open')){return
false};A4J.AJAX.Submit('something:something');
return false;"
>drop</a>
maintenant, après l’affichage de la boîte de dialogue, A4j.AJAX.Submit (..) est exécuté, y at-il quand même, que je peux par exemple, passer le tout A4J.AJAX.Submit (...) to "dialog" et exécutez-le à partir de "ok". option? Je dois simplement exécuter submit si et seulement si l'utilisateur clique sur OK. Merci pour l'aide JQ
La solution
Vous pouvez définir:
<a4j:jsFunction name="okClicked"
actionListener="#{some.action}"
reRender="something" />
Et appelez-le dans la fonction OK, par exemple:
"Ok": function() {
jQuery(this).dialog("close");
okClicked();
return true;
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow