gpt4 book ai didi

javascript - 关闭对话框时刷新数据表,无需单击按钮 jsf2 primefaces

转载 作者:行者123 更新时间:2023-11-28 09:43:38 25 4
gpt4 key购买 nike

我有这个对话框:

<p:dialog  header="Commande editée le #{acceuilUserController.selectedMajCommande.dateMaj} par l'#{acceuilUserController.selectedMajCommande.utilisateur.type} #{acceuilUserController.selectedMajCommande.utilisateur.nom} #{acceuilUserController.selectedMajCommande.utilisateur.prenom}" widgetVar="carDialog" resizable="false" id="carDlg"  
update="cars" showEffect="fade" hideEffect="explode" modal="true">

当用户单击数据表下面的按钮时显示:

<p:column style="width:40px">                         
<p:commandButton id="selectButton" action="#{acceuilUserController.refresh()}" update=":form:carDlg" oncomplete="carDialog.show()" icon="ui-icon-search" title="plus de détails">
<f:setPropertyActionListener value="#{car}" target="#{acceuilUserController.selectedMajCommande}" />
</p:commandButton>
</p:column>

我希望当用户关闭对话框时,将执行以下方法:

public String refresh(){
this.selectedMajCommande.setLu(true);
System.out.println("je suis la alors : "+this.selectedMajCommande.isLu());
hch.updateCommandeMaj(selectedMajCommande);
return "acceuil";
}

它允许将数据刷新到数据表中,我成功地使用对话框中的按钮做到了这一点,如下所示:

 <p:commandButton id="confirm" value="fermer" update="cars" oncomplete="carDialog.hide()"
action="#{acceuilUserController.refresh()}" />

但我只想在关闭对话框时执行此操作,而不需要在框中使用此按钮

这是我要刷新的数据表:

<p:dataTable id="cars" var="car" value="#{acceuilUserController.lc_maj}"  tableStyle="width:auto" rowStyleClass="#{(car.lu == false) ? 'red' : null}" >  

<p:column headerText="Commande N° : " style="width:100px">
<h:outputText value="#{car.commande.id}" />
</p:column>

<p:column headerText="Date de mise à jour : " style="width:100px">
<h:outputText value="#{car.dateMaj}" />
</p:column>

<p:column headerText="Decision : " style="width:100px">
<h:outputText value="#{car.decison}" />
</p:column>

<p:column headerText="Etat : " style="width:100px">
<h:outputText value="#{car.etat}" />
</p:column>

<p:column style="width:40px">
<p:commandButton id="selectButton" action="#{acceuilUserController.refresh()}" update=":form:carDlg" oncomplete="carDialog.show()" icon="ui-icon-search" title="plus de détails">
<f:setPropertyActionListener value="#{car}" target="#{acceuilUserController.selectedMajCommande}" />
</p:commandButton>
</p:column>

</p:dataTable>

如何实现这一点,提前谢谢

最佳答案

可以使用 jQuery 绑定(bind)单击事件,从而调用 PrimeFaces commandButton 组件的单击事件,该组件已配置为部分处理和更新您选择的组件。我通过将此脚本放入放置在所有对话框之外的复合组件中来完成类似的操作,但是当然有很多方法可以做到这一点。

jQuery(document).ready(function() {
// Searching for naming container that contains my dialog...
var dashboardPanel = jQuery('*[id*=#{cc.attrs.id}]');
// Find the dialog closer button by its unique class
var closerButton = dashboardPanel.children().find('.ui-dialog-titlebar-close');
closerButtons.bind('click', function(event) {
// Use set timeout to delay the event if you want to see close animation effect
setTimeout(function() { //Some logic to find the button client id
var menuItemId = 'view#{cc.attrs.id}'.replace('Panel', '');
jQuery('#' + menuItemId).click();
}, 400);
});
});

当然,如果您没有带有动态 id 的 commandButton 或者它不在重复容器中,那么在 Javascript 中通过其 widgetVar 直接引用它会简单得多。 .

commandButtonWidget.jq.click();

关于javascript - 关闭对话框时刷新数据表,无需单击按钮 jsf2 primefaces,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12089053/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com