我正在使用Primefaces 2.2。我有p:tabView,里面有三个标签。 Tab1包含一个布尔复选框。现在我想要当用户点击tab1中的复选框时,然后选项卡2变为禁用。我该怎么做?这是代码预览。
<h:body>
<p:panel header="F.C. Barcelona" footer="Visca el Barca!">
<p:tabView>
<p:tab id="tab1" title="Godfather Part I">
<h:panelGrid columns="2" cellpadding="10">
<h:outputText value="In tab1." />
</h:panelGrid>
<h:selectBooleanCheckbox id="Mark"
value="#{disableTag.disable}" >
<f:ajax render="tab2" />
</h:selectBooleanCheckbox>
</p:tab>
<p:tab id="tab2" title="Godfather Part II">
<h:panelGrid columns="2" cellpadding="10">
<h:outputText value="In tab2." />
</h:panelGrid>
</p:tab>
<p:tab id="tab3" title="Godfather Part III">
<h:panelGrid columns="2" cellpadding="10">
<h:outputText value="In tab3." />
</h:panelGrid>
</p:tab>
</p:tabView>
</p:panel>
</h:body>
由于
答案 0 :(得分:1)
<h:form id="myFormId">
<p:panel header="F.C. Barcelona" footer="Visca el Barca!">
<p:tabView>
<p:tab id="tab1" title="Godfather Part I" disabled="#{myBean.myBooleanFirstTabDisable}">
<h:panelGrid columns="2" cellpadding="10">
<h:outputText value="In tab1." />
</h:panelGrid>
<h:selectBooleanCheckbox id="Mark"
value="#{disableTag.disable}" >
<p:ajax event="check" update="myFormId" listener="#{myBean.myMethodEvaluatingDisabledTabs}" />
</h:selectBooleanCheckbox>
</p:tab>
<p:tab id="tab2" title="Godfather Part II" disabled="#{myBean.myBooleanSecondTabDisable}">
<h:panelGrid columns="2" cellpadding="10">
<h:outputText value="In tab2." />
</h:panelGrid>
</p:tab>
<p:tab id="tab3" title="Godfather Part III" disabled="#{myBean.myBooleanThirdTabDisable}">
<h:panelGrid columns="2" cellpadding="10">
<h:outputText value="In tab3." />
</h:panelGrid>
</p:tab>
</p:tabView>
</p:panel>
</h:form>
所以你必须有一个表单组件,你可以看到你可以使用primefaces ajax和update属性...方法/监听器myMethodEvaluatingDisabledTabs
用于更改disabled
使用的布尔值每个标签中的属性:因此,对于您想要的每个标签,您都会更改为disabled=true
(在这种情况下,您将有3个布尔变量),然后更新整个表单。
PS:我必须检查ajax事件......
答案 1 :(得分:1)
我是怎么做到的。
<h:head>
<title>Facelet Title</title>
</h:head>
<h:body>
<h:form>
<p:panel id="myPanel" header="F.C. Barcelona" footer="Visca el Barca!">
<p:tabView id="myTabView" tabChangeListener="#{disableTag.onChange}" >
<p:tab id="tab1" title="Godfather Part I">
<h:panelGrid columns="2" cellpadding="10">
<p:panel header="Basit" footer="Basit">
</p:panel>
<h:outputText value="In tab1." />
</h:panelGrid>
<h:outputText value="Click to hideGodfather Part II " />
<h:selectBooleanCheckbox id="Mark"
value="#{disableTag.disable}"
valueChangeListener="#{disableTag.changeMark}">
<f:ajax render="@this myTabView" />
</h:selectBooleanCheckbox>
</p:tab>
<p:tab id="tab2"
title="Godfather Part II"
rendered="#{disableTag.rendered}">
<h:panelGrid columns="2" cellpadding="10">
<h:outputText value="In tab2." />
</h:panelGrid>
</p:tab>
<p:tab id="tab3" title="Godfather Part III">
<h:panelGrid columns="2" cellpadding="10">
<h:outputText value="In tab3." />
</h:panelGrid>
</p:tab>
</p:tabView>
</p:panel>
</h:form>
</h:body>
@ManagedBean
@ViewScoped
public class DisableTag implements Serializable {
private boolean disable;
private boolean rendered;
/** Creates a new instance of DisableTag */
public DisableTag() {
rendered = false;
} //end of constructor
public boolean isDisable() {
return disable;
}
public void setDisable(boolean disable) {
this.disable = disable;
}
public boolean isRendered() {
return rendered;
}
public void setRendered(boolean rendered) {
this.rendered = rendered;
}
public void changeMark(ValueChangeEvent vcEvent){
rendered = Boolean.valueOf(vcEvent.getNewValue().toString()).booleanValue();
System.out.println();
}
} //end of class DisableTag