1

我正在尝试arrayListxhtml页面上显示元素,但是每次我上传新文件时,然后在状态页面上,我都会获得上次上传文件的多个条目,而不是有关数组中存在的所有元素的详细信息。

这是代码

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);
        }
    }
4

1 回答 1

2

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

于 2012-04-16T20:03:27.747 回答