1

I am trying to display elements of arrayList on xhtml page, but every time i upload new file then on status page i get multiple entries of last uploaded file rather then having details about all elements present in the array.

Here is the code

XHTML Code:

<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 Code:

 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
  • do your managed bean has ViewScope or RequestScope? Commented Apr 16, 2012 at 20:11

1 Answer 1

2

I think your problem is that you are reusing your resultbean. You should create a new instance of ResultBean in your upload method, this should fix the problem.

Sign up to request clarification or add additional context in comments.

6 Comments

No, it would not fix the issue as then how get getters be called?
maybe i didn't understood you clearing, what did you meant by creating new resultBean in upload Method
right "below public void uploadFile(FileEntryEvent event) {" add resultBean = new ResultBean()
it works now but i didn't understood the reason why, can you elaborate?
You were overwriting your old objects before. The list is just an object storer - it does not copy the object.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.