JSF:ArrayList的元素没有正确呈现?

时间:2012-04-16 19:54:16

标签: java jsf data-structures arraylist

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

这是代码

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

1 个答案:

答案 0 :(得分:2)

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