如何在PrimeFaces选项卡视图中单击特定选项卡时显示对话框
我是jsf新手,我正在使用PrimeFaces4.0编写一个选项卡视图。 我想在单击特定选项卡时在我的支持Bean中执行一些操作,因此我尝试了以下方法: 第页: 到目前为止,一切都正常,但由于某些原因,支持Bean运行缓慢,我想在支持Bean运行时显示一个包含进度条的对话框: 这样的对话框:如何在PrimeFaces选项卡视图中单击特定选项卡时显示对话框,primefaces,tabview,jsf-2.2,Primefaces,Tabview,Jsf 2.2,我是jsf新手,我正在使用PrimeFaces4.0编写一个选项卡视图。 我想在单击特定选项卡时在我的支持Bean中执行一些操作,因此我尝试了以下方法: 第页: 到目前为止,一切都正常,但由于某些原因,支持Bean运行缓慢,我想在支持Bean运行时显示一个包含进度条的对话框: 这样的对话框: <p:dialog id="pBarDialog" header="Progressing..." widgetVar="dlg" modal="true" height="70" resizable
<p:dialog id="pBarDialog" header="Progressing..." widgetVar="dlg" modal="true" height="70" resizable="false" closable="false">
<h:outputText value="Please wait, we're generating your info..." />
<p:progressBar widgetVar="pbAjax" ajax="true" value="100" styleClass="animated"> </p:progressBar>
</p:dialog>
那么,当我单击“统计”选项卡时,如何显示对话框 解决方案可以是使用对话框上的visible属性:
<p:dialog id="pBarDialog" header="Progressing..." visible="#{myConsoleBean.showDialog}"
modal="true" height="70" resizable="false" closable="false">
然后
if(activeTabIndex==1)//Stat tab clicked
{
myConsoleBean.displayDialog();
}
还要确保ajax组件更新对话框,您可以执行以下操作:
public void onTabChange(TabChangeEvent event) {
TabView tv = (TabView) event.getComponent();
int activeTabIndex = tv.getActiveIndex();
System.out.println(activeTabIndex);
if(activeTabIndex==1)//Stat tab clicked
{
//do something here...
}
if(activeTabIndex==2){
RequestContext.getCurrentInstance().execute("PF('dlg').show()"); //For Primeface 4.0
RequestContext.getCurrentInstance().execute("dlg.show()"); //Before Primeface 4.0
}
}
我想我解决了这个问题。 我看到后使用了
p:remoteCommand
这是我最后的密码:
第页:
不管怎样,谢谢你们两位,拉姆克和埃米尔·卡明斯基。
如果没有您的帮助,我将永远找不到该线程,因为我会从您的答案中键入关键字。我不知道它为什么不起作用。但我的问题已经通过Emil Kaminski的解决方案解决了。不过,非常感谢!我相信这是一个很好的解决办法。如果可以的话,我会使用这个解决方案。不知道我是否做错了什么。你的primefaces版本是什么?我使用primefaces版本4.0Ok,所以只使用
RequestContext.getCurrentInstance().execute(“PF('dlg').show()”)代码>选择stat选项卡时,activeTabIndex是什么?你有javascript错误吗?对不起,我发现对话框显示,即使我点击了其他选项卡,我是否应该做些什么来修复它?对不起,我没有完全阅读你的问题,我错过了对话框应该只出现在特定选项卡上的部分。看到我更新的答案了吗<代码>public void onTabChange(TabChangeEvent事件){TabView tv=(TabView)event.getComponent();int-activeTabIndex=tv.getActiveIndex();if(activeTabIndex==1){displayDialog();goToUrl(“myStat.xhtml”);}私有布尔显示对话框;public void displayDialog(){showDialog=true;}public boolean getShowDialog(){return showDialog;}
但是,在“gotour(“myStat.xhtml”);”完成之前,它不显示任何内容。因为当我单击Stat选项卡时,它只是刷新“showDialog”,并且该方法在我的“gotour”(“myStat.xhtml”);”函数完成后返回。因此,对话框将在事情完成后显示,而我希望对话框在“gotour”(“myStat.xhtml”);”运行时显示。
private boolean showDialog;
public void displayDialog() {
showDialog = true;
}
public boolean getShowDialog() {
return showDialog;
}
if(activeTabIndex==1)//Stat tab clicked
{
myConsoleBean.displayDialog();
}
public void onTabChange(TabChangeEvent event) {
TabView tv = (TabView) event.getComponent();
int activeTabIndex = tv.getActiveIndex();
System.out.println(activeTabIndex);
if(activeTabIndex==1)//Stat tab clicked
{
//do something here...
}
if(activeTabIndex==2){
RequestContext.getCurrentInstance().execute("PF('dlg').show()"); //For Primeface 4.0
RequestContext.getCurrentInstance().execute("dlg.show()"); //Before Primeface 4.0
}
}
<p:tabView effect="fade" effectDuration="normal">
<p:ajax event="tabChange" listener="#{myConsoleBean.onTabChange}" oncomplete="dlg.hide()" update=":rightForm"/>
<p:tab title="My">
</p:tab>
<p:tab id="statTab" title="Stat">
<p:remoteCommand actionListener="#{myConsoleBean.goToUrl('myStat.xhtml')}" update=":rightForm" name="showStat" global="true" onstart="dlg.show()" oncomplete="dlg.hide()"></p:remoteCommand>
</p:tab>
</p:tabView>
<p:dialog id="pBarDialog" header="Progressing..." widgetVar="dlg" modal="true" height="70" resizable="false" closable="false">
<h:outputText value="Please wait, we are generating your info..." />
<p:progressBar widgetVar="pbAjax" ajax="true" value="100" styleClass="animated">
</p:progressBar>
</p:dialog>
public void onTabChange(TabChangeEvent event) {
TabView tv = (TabView) event.getComponent();
int activeTabIndex = tv.getActiveIndex();
if(activeTabIndex==1)
{
RequestContext.getCurrentInstance().execute("showStat()");
}
}