我的问题有一个简单的例子。我有一个数据表,我想在排序,过滤器或页面事件中禁用页脚中的按钮。我更新了页脚中的按钮,但没有任何变化。另一种形式的另一个按钮工作正常。如果我使用“@form”更新整个表格,表格将被销毁。
我找到了Primefaces Extensions的解决方案pe:RemoteCommand(http://fractalsoft.net/primeext-showcase-mojarra/sections/remoteCommand/basicUsage.jsf)...如果我使用事件的onComplete-Methode并调用remoteCommand,那么我可以从那里更新页脚中的按钮。
有人可以解释一下吗? 感谢您的时间。
XHTML:
<html lang="en" 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:p="http://primefaces.org/ui">
<h:head></h:head>
<h:body>
<h:form id="tableform">
<p:dataTable value="#{bean.personList}" var="person" paginator="true"
rows="5" rowKey="#{person.id}">
<p:ajax event="page" listener="#{bean.onPaging}"
update=":outform:buttonOut buttonIn" />
<p:ajax event="filter" listener="#{bean.onFilter}"
update=":outform:buttonOut buttonIn" />
<p:ajax event="sort" listener="#{bean.onSort}"
update=":outform:buttonOut buttonIn" />
<p:column headerText="id" sortBy="#{person.id}"
filterBy="#{person.id}">
#{person.id}
</p:column>
<p:column headerText="name" sortBy="#{person.name}"
filterBy="#{person.name}">
#{person.name}
</p:column>
<f:facet name="footer">
<p:commandButton id="buttonIn" value="ButtonIn"
disabled="#{!bean.visible}" />
</f:facet>
</p:dataTable>
</h:form>
<h:form id="outform">
<p:commandButton id="buttonOut" value="ButtonOut" disabled="#{!bean.visible}" />
</h:form>
豆:
@ManagedBean
@ViewScoped
public class Bean {
private List<Person> personList;
private boolean visible = true;
@PostConstruct
public void init(){
personList = new ArrayList<Person>();
for(int i = 0 ; i < 100 ; i++){
personList.add(new Person(i, "Person" +i));
}
}
public void onPaging(PageEvent event){
visible = false;
}
public void onSort(SortEvent event){
visible = false;
}
public void onFilter(FilterEvent event){
visible = false;
}
public boolean isVisible() {
return visible;
}
public void setVisible(boolean visible) {
this.visible = visible;
}
public List<Person> getPersonList() {
return personList;
}
public void setPersonList(List<Person> personList) {
this.personList = personList;
}
}
答案 0 :(得分:1)
如果您使用remoteCommand,您可以这样做:
<h:form id="tableform">
.....
<p:remoteCommand name="doAction" actionListener="#{bean.changeFlag}"
update="idOfYourDataTable:buttonIn"
immediate="true"/>
.......
</h:form>
在ajax调用中:
<p:ajax event="page" oncomplete="doAction();"/>
<p:ajax event="filter" oncomplete="doAction();"/>
<p:ajax event="sort" oncomplete="doAction();"/>
在Bean中:
public void changeFlag(){
visible = false;
}