gpt4 book ai didi

java - JSF : Elements of ArrayList are not rendered properly?

转载 作者:行者123 更新时间:2023-11-30 04:49:24 26 4
gpt4 key购买 nike

我试图在 xhtml 页面上显示 arrayList 的元素,但是每次我上传新文件,然后在状态页面上,我都会收到上次上传文件的多个条目,而不是具有有关数组中存在的所有元素的详细信息。

这是代码

XHTML 代码:

<ace:dataTable id ="archiveResults" resizableColumns="true" paginatorPosition="bottom" paginator="true" page="1" value="${fileUpload.resultBeanList}" var="result">
<ace:column id="fileUploadFileName" headerText="uploaded file" sortBy="#{result.fileName}" filterBy="#{result.fileName}" filterMatchMode="contains">
<h:outputFormat id="cellFileUploadFileName" value="${result.fileName}" />
</ace:column>
<ace:column id="fileUploadTime" headerText="time run" sortBy="#{result.timeRun}" filterBy="#{result.timeRun}" filterMatchMode="contains">
<h:outputFormat id="cellFileUploadTime" value="${result.timeRun}" />
</ace:column>
<ace:column id="fileUploadJobType" headerText="job type" sortBy="#{result.jobType}" filterBy="#{result.jobType}" filterMatchMode="contains">
<h:outputFormat id="cellFileUploadJobType" value="${result.jobType}" />
</ace:column>
<ace:column id="fileUploadStatus" headerText="Status" sortBy="#{result.status}" filterBy="#{result.status}" filterMatchMode="contains">
<h:outputFormat id="cellFileUploadStatus" value="${result.status}" />
</ace:column>
</ace:dataTable>

Java 代码:

  private List<ResultBean> resultBeanList = new ArrayList<ResultBean>();
private ResultBean resultBean = new ResultBean();

public ResultBean getResultBean() {
return resultBean;
}

public void setResultBean(ResultBean resultBean) {
this.resultBean = resultBean;
}

public List<ResultBean> getResultBeanList() {
System.out.println("resultBeanList: "+resultBeanList.toString());
return resultBeanList;
}

public void setResultBeanList(List<ResultBean> resultBeanList) {
this.resultBeanList = resultBeanList;
}

public void uploadFile(FileEntryEvent event) {
FileEntry fileEntry = (FileEntry) event.getSource();
FileEntryResults results = fileEntry.getResults();
FileEntry fe = (FileEntry) event.getComponent();
FacesContext ctx = FacesContext.getCurrentInstance();
FacesMessage msg = new FacesMessage();
for (FileEntryResults.FileInfo fileInfo : results.getFiles()) {
if (fileInfo.isSaved()) {
File file = fileInfo.getFile();
String filePath = file.getAbsolutePath();
resultBean.setStatus(fileInfo.getStatus().toString());
resultBean.setFileName(fileInfo.getFileName());
resultBean.setJobType(selectedItem);
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Date date = new Date();
Calendar cal = Calendar.getInstance();
dateFormat.format(cal.getTime());
resultBean.setTimeRun(dateFormat.format(cal.getTime()));
}
resultBeanList.add(resultBean);
}
}

最佳答案

我认为你的问题是你正在重用你的resultbean。您应该在上传方法中创建一个新的 ResultBean 实例,这应该可以解决问题。

关于java - JSF : Elements of ArrayList are not rendered properly?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10180709/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com