基本上,我正尝试从<p:commandLink>
触发操作以更新<p:datatable>
和<p:growl>
。
<p:growl>
会立即更新,但只有在第二次点击后才会更新<p:datatable>
。
以下是XHTML代码:
<h:body>
<h:form id="form1" >
<p:layout id="layout">
<p:layoutUnit id="north" position="north">
<p:growl id="msg" showDetail="true" />
<h:column>
<p:commandButton id="searchdate"
value="Rechercher"
actionListener="#{dyna.search}"
update=":form1:tabexam,:form1:msg"/>
</h:column>
</p:layoutUnit>
<p:layoutUnit position="center"
resizable="true"
collapsible="true"
effect="drop"
size="300"
styleClass="heighter">
<p:dataTable id="tabexam"
paginatorPosition="bottom"
var="exam"
value="#{dyna.listexam}"
widgetVar="examTable"
emptyMessage="aucun résultat."
filteredValue="#{dyna.filteredexams}"
paginator="true"
rows="20"
rowsPerPageTemplate="10,20,40,80"
binding="#{dyna.table}">
<f:facet name="header" >
<h:outputText value="Rechercher: "/>
<p:inputText id="globalFilter"
onkeyup="examTable.filter();"
style="width:200px" />
</f:facet>
</p:dataTable>
</p:layoutUnit>
<p:layoutUnit position="west" resizable="false" header="Liste Perso.">
<ui:repeat var="list" value="#{userBean.userLists}">
<center>
<p:commandLink id="listerlink"
title="Afficher la liste"
action ="#{dyna.refreshChildren(list.id.tbCode)}"
update=":form1:tabexam,:form1:msg">
<p:graphicImage id="imglist" value="/images/Liste_Cold.png"/><br></br>
<p:outputLabel value="#{list.id.tbCode}" /><br></br>
</p:commandLink>
</center>
</ui:repeat>
</p:layoutUnit>
</h:form>
</h:body>
以下是我的ManagedBean中的一些代码。
@ManagedBean(name = "dyna", eager = true)
@SessionScoped
public class DynamicDatatable implements java.io.Serializable {
@PostConstruct
public void init() {
listexam = DAO_Examen.getAllExamens();
selectedExamen = new Cotation();
etatExamOptions = createFilterOptions();
payExamOptions = createFilterOptions2();
salleOptions = DAO_Salle.getAllSalle(UserBean.user.getUserId());
refreshChildren("default");
}
public void refreshChildren(String listid) {
try {
//config
FacesContext fc = FacesContext.getCurrentInstance();
Application application = fc.getApplication();
ExpressionFactory ef = application.getExpressionFactory();
ELContext elc = fc.getELContext();
//Table
table = (DataTable) application.createComponent(DataTable.COMPONENT_TYPE);
//columns spec.
ArrayList<ColumnModel> columnmodel = DAO_UserLists.createUserColumnSpec(UserBean.user.getUserId(), "SITE1", listid);
if (columnmodel != null) {
for (int i = 0; i < columnmodel.size(); i++) {
if ((columnmodel.get(i) != null) && (columnmodel.get(i).getDbname() != null)) {
Column column = (Column) application.createComponent(Column.COMPONENT_TYPE);
column.setHeaderText(columnmodel.get(i).getUserListname());
column.setWidth("10");
column.setId("Col_" + columnmodel.get(i).getHeadername());
column.setStyleClass("dispo");
column.setSortBy(columnmodel.get(i).getDbname());
column.setRendered(columnmodel.get(i).isVisible());
table.getChildren().add(column);
}
}
FacesMessage msg = new FacesMessage("Terminé avec succes", "la liste " + listid + " est bien chargée");
FacesContext.getCurrentInstance().addMessage(null, msg);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
API的版本: JSF 2.2 primefaces 4.0