我的 JSF 页面上有 commandButton
组件:
<p:commandButton id="period"
value="#{myBean.isMonthly == false ? 'Yearly' : 'Monthly'}"
action="#{myBean.doSomeOtherStuff()}"
update="period myDataTable">
</p:commandButton>
我正在尝试通过单击上面的按钮来更新dataTable
。
当我单击它时,dataTable
根据需要进行更新,而 commandButton
的行为很奇怪,导致显示如下:
有人可以帮助我了解这种奇怪情况的原因,并告诉我解决方案(如果可能)吗?
注释:
- JSF 实现和版本: Mojarra (javax.faces-2.1.11.jar)
- 查看技术: Facelets (XHTML)
- 复制、粘贴和运行示例! (SSCCE)如下:
FilterBean.java:
package com.turkcell.mdealer.bean.impl;
import org.springframework.stereotype.Component;
@Component
public class FilterBean {
private boolean monthly = true;
public String applyPeriod(String caller) {
monthly = !monthly;
return caller;
}
public boolean isMonthly() {
return monthly;
}
public void setMonthly(boolean monthly) {
this.monthly = monthly;
}
}
sample.xhtml:
<f:view xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:turkcell="http://turkcell.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui" xmlns:o="http://omnifaces.org/ui"
xmlns:of="http://omnifaces.org/functions"
xmlns:pm="http://primefaces.org/mobile" contentType="text/html"
renderKitId="PRIMEFACES_MOBILE">
<pm:page title="Bayi Raporlari">
<pm:view id="FaturasizAktivasyon" swatch="c">
<p:outputPanel id="FaturasizPanel">
<h:form id="FaturasizForm">
<pm:content>
<p:commandButton id="period"
value="#{filterBean.monthly == false ? 'Yearly' : 'Monthly'}"
action="#{filterBean.applyPeriod('sample')}" update="period">
</p:commandButton>
</pm:content>
</h:form>
</p:outputPanel>
</pm:view>
</pm:page>
</f:view>
库的总体 View :
最佳答案
我不知道这种奇怪行为的原因
但是,您可以使用两个条件渲染按钮来达到相同的效果:
<p:panelGroup>
<p:commandButton value="Monthly"
action="#{myBean.doSomeOtherStuff()}"
update="myDataTable @parent" rendered="#{myBean.isMonthly}" />
<p:commandButton value="Yearly"
action="#{myBean.doSomeOtherStuff()}"
update="myDataTable @parent" rendered="#{not myBean.isMonthly}" />
</p:panelGroup>
关于java - PrimeFaces 组件未根据需要更新(生成嵌套按钮),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15676571/