我在更改tabView时尝试更新outputPanel组件,但我找不到方法。我发现其他方法是更新完整的表格,但我宁愿只更新组件。
我尝试更新:frmTest:grpButtons和frmTest:grpButtons,它唯一有效的是frmTest。
任何关于错误的想法。
test.xhtml
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
template="/WEB-INF/template.xhtml">
<ui:define name="pageTitle">Test</ui:define>
<ui:define name="content">
<h:form id="frmTest" prependId="true">
<div class="Container100">
<div class="ContainerIndent">
<div class="Card ShadowEffect TexAlLeft">
<p:tabView id="tabView">
<p:ajax event="tabChange" listener="#{testBean.onTabChange}"
update=":frmTest:grpButtons"/>
<p:tab title="First" id="tab1">
<div class="Card ShadowEffect TexAlCenter">
<br/>
<h2>Empty Page 1</h2>
<br/>
<span class="gray">Use this page to start from scratch and place your custom content.</span>
<br/><br/>
</div>
</p:tab>
<p:tab title="Second" id="tab2">
<div class="Card ShadowEffect TexAlCenter">
<br/>
<h2>Empty Page 1</h2>
<br/>
<span class="gray">Use this page to start from scratch and place your custom content.</span>
<br/><br/>
</div>
</p:tab>
</p:tabView>
<p:separator/>
<p:outputPanel id="grpButtons" rendered="#{testBean.showButtons}">
<p:commandButton id="btnSaveSol" value="#{msgs.save}"
styleClass="Fright GreenButton"
action="#{testBean.save}"
ajax="true"
update=":frmTest"/>
</p:outputPanel>
</div>
</div>
</div>
</h:form>
</ui:define>
</ui:composition>
TestBean.java
@ViewScoped
@ManagedBean
public class TestBean implements Serializable {
private static final long serialVersionUID = 4078818945032342504L;
private Arxiu arxiu;
private boolean showButtons = true;
@PostConstruct
private void init() {
loadLocale();
}
//----------------------------------------------------------------
// Methods
//----------------------------------------------------------------
public void onTabChange(TabChangeEvent event) {
showButtons = !event.getTab().getId().equals("tab2");
}
public void save() {
System.out.println("save");
}
//Getters and setters
}
答案 0 :(得分:0)
我找到了一种有效的方法,但我仍然不知道为什么它不像我在问题中那样工作。这可能是一个表面错误吗?
我用一个面板和属性widgetVar =&#34; var&#34;包装了outputPanel。然后更新=&#34; @widgetVar(var)&#34;。
修改代码
<p:ajax event="tabChange" listener="#{testBean.onTabChange}"
update="pnlButtons"/>
...
<p:panel id="pnlButtons">
<p:outputPanel id="grpButtons" rendered="#{testBean.showButtons}">
<p:commandButton id="btnSave" value="#{msgs.save}"
styleClass="Fright GreenButton"
action="#{testBean.save}" ajax="true"
rendered="#{testBean.showButtons}"/>
</p:outputPanel>
</p:panel>