单击按钮时,我正在检索文件夹中的文件列表。检索文件夹的功能有效,如果我在呈现表格之前加载它,则值将按应有的方式显示。但是,如果我尝试使用调用初始化值列表的函数的命令按钮填充表,则不会对数据表进行任何更改。这是我的代码:
<h:form id="resultform">
<p:dataTable id="resulttable" value="#{ViewBean.resultList}" var="result">
<p:column>
<f:facet name="header">
<h:outputText value="GFEXP_NOM_BDOC" />
</f:facet>
<h:outputText value="#{result.name}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="GFEXP_DATE_MODIF" />
</f:facet>
<h:outputText value="#{result.date}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="GFEXP_PATH" />
</f:facet>
<h:outputText value="#{result.path}" />
</p:column>
<f:facet name="footer">
<p:commandButton value="REFRESH exploitation" action="#{ViewBean.refresh}" update=":resultform:resulttable" ajax="true" />
</f:facet>
</p:dataTable>
</h:form>
这是支持 bean 的代码:
@ManagedBean(name = "ViewBean")
@ViewScoped
public class ViewBean implements Serializable {
private static final long serialVersionUID = 9079938138666904422L;
@ManagedProperty(value = "#{LoginBean.database}")
private String database;
@ManagedProperty(value = "#{ConfigBean.envMap}")
private Map<String, String> envMap;
private List<Result> resultList;
public void initialize() {
setResultList(Database.executeSelect(database));
}
public void refresh() {
List<File> fileList = readDirectory();
List<Result> tmpList = new ArrayList<Result>();
for (File f : fileList) {
Result result = new Result(f.getName().substring(0,
f.getName().lastIndexOf(".")), String.valueOf(f
.lastModified()), f.getPath().substring(0,
f.getPath().lastIndexOf("\\") + 1));
tmpList.add(result);
}
setResultList(tmpList);
}
//GETTERS AND SETTERS