更新Primefaces Extensions Sheet组件的数据后,如何解决列标题和数据消失的问题?

时间:2019-04-25 14:43:13

标签: primefaces primefaces-extensions

我正在使用primeface扩展(版本6.2),并开始使用Sheet组件。我上传一个excel文件,对其进行解析,然后基于此数据创建对象,然后将其添加到列表中,该列表是我用于工作表的value属性的对象。直到最近,一切都运转良好。问题是完成所有解析,创建对象等方法并更新了工作表之后,没有数据显示,并且标题甚至消失了。有人知道是什么问题吗?

这是fileuploader,工作表和执行魔术的方法的组成部分

<p:fileUpload
                id="excelUploader"
                mode="advanced"
                value="#{excelDemoBean.file}"
                invalidSizeMessage="Please upload file within file size limits"
                sizeLimit="104857600"
                process="@this"
                update=":#{p:component('sheet')}"
                fileUploadListener="#{excelDemoBean.handleFileUpload}"
                allowTypes="/(\.|\/)(xls|xlsx)$/i">
            </p:fileUpload>
<pe:sheet
    id="sheet"
    widgetVar="sheetWidget"
    value="#{excelDemoBean.wpList}"
    var="row"
    rowKey="#{row.id}"
    height="400"
    fixedCols="2"
    stretchH="all"
    showRowHeaders="true"
    resizableCols="true"
    resizableRows="true"
    sortOrder="ascending"
    readOnly="false">

    <f:facet name="header">  
        <h:outputText value="Uploaded Excel File" />  
    </f:facet>  

    <pe:sheetcolumn
        headerText="Name"
        value="#{row.name}"
        sortBy="#{row.name}"
        colWidth="150"
        filterBy="#{row.name}" />
    <pe:sheetcolumn
        headerText="DCMS ID"
        value="#{row.associatedLegacyProduct.leagcyProductId}"
        colWidth="100"
        sortBy="#{row.associatedLegacyProduct.leagcyProductId}"
        filterBy="#{row.associatedLegacyProduct.leagcyProductId}"
        colType="dropdown"
        readOnly="true" />
    <pe:sheetcolumn
        headerText="FP Product Name"
        value="#{row.fpProductName}"
        colWidth="100"
        sortBy="#{row.fpProductName}"
        filterBy="#{row.fpProductName}"
        colType="autocomplete"
        autoCompleteStrict="false"
        autoCompleteVisibleRows="4" />
    <pe:sheetcolumn
        headerText="PID"
        value="#{row.processInstanceId}"
        readOnly="true"
        colWidth="100"
        sortBy="#{row.processInstanceId}"
        filterBy="#{row.processInstanceId}" />
    <pe:sheetcolumn
        headerText="Issuer"
        value="#{row.issuer}"
        colWidth="100" />
    <pe:sheetcolumn
        headerText="Processor"
        value="#{row.processor}"
        colWidth="100" />
    <pe:sheetcolumn
        headerText="Product Line"
        value="#{row.productLine}"
        colWidth="100" />
    <pe:sheetcolumn
        headerText="UPC"
        value="#{row.upc}"
        colWidth="100"
        colType="numeric" />
    <pe:sheetcolumn
        headerText="Requester"
        value="#{row.requester}"
        colWidth="100" />
    <pe:sheetcolumn
        headerText="Country"
        value="#{row.country}"
        colWidth="100" />
    <pe:sheetcolumn
        headerText="Date Approved"
        value="#{row.dateApproved}"
        colWidth="100" />
    <pe:sheetcolumn
        headerText="Date Requested"
        value="#{row.dateRequested}"
        colWidth="100" />
</pe:sheet>

public void handleFileUpload(FileUploadEvent event) {
UploadedFile excelFile = event.getFile();
            SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy hh:mm a");
            Random rand = new Random();
            if (StringUtils.equalsIgnoreCase(FilenameUtils.getExtension(excelFile.getFileName()), "xls")) {
                File tempFileForUploadedExcelFile = File.createTempFile("tempCopyOfExcel", ".xls");
                FileUtils.copyInputStreamToFile(excelFile.getInputstream(), tempFileForUploadedExcelFile);
                FileInputStream inputStreamForTempFile = new FileInputStream(tempFileForUploadedExcelFile);
                HSSFWorkbook workbook = new HSSFWorkbook(inputStreamForTempFile);
                HSSFSheet sheet = workbook.getSheetAt(0);
                Iterator<Row> rowIterator = sheet.rowIterator();
                WorkflowProduct temp;
                wpList = new ArrayList<>();
                while (rowIterator.hasNext()) {
                    Row row = rowIterator.next();
                    if (row.getRowNum() != 0) {
                        temp = new WorkflowProduct();
                        Iterator<Cell> cellIterator = row.cellIterator();
                        temp.setName(cellIterator.next().getStringCellValue());
                        temp.setFpProductName(cellIterator.next().getStringCellValue());
                        temp.setProcessInstanceId(cellIterator.next().getStringCellValue());
                        temp.setIssuer(cellIterator.next().getStringCellValue());
                        temp.setProductLine(cellIterator.next().getStringCellValue());
                        temp.setProcessor(cellIterator.next().getStringCellValue());
                        temp.setUpc(cellIterator.next().getStringCellValue());
                        temp.setRequester(cellIterator.next().getStringCellValue());
                        temp.setCreator(cellIterator.next().getStringCellValue());
                        temp.setApprover(cellIterator.next().getStringCellValue());
                        String date1 = cellIterator.next().getStringCellValue();
                        String date2 = cellIterator.next().getStringCellValue();
                        temp.setDateApproved(format.parse(date1));
                        temp.setDateRequested(format.parse(date2));
                        temp.setCountry(cellIterator.next().getStringCellValue());
                        temp.setClassification(cellIterator.next().getStringCellValue());
                        temp.setType(cellIterator.next().getStringCellValue());
                        temp.setDenomType(cellIterator.next().getStringCellValue());
                        temp.setDenomValue(cellIterator.next().getStringCellValue());
                        temp.setFpProductLine(cellIterator.next().getStringCellValue());
                        temp.setFpProductType(cellIterator.next().getStringCellValue());
                        String value = cellIterator.next().getStringCellValue();
                        temp.setFpProductCode(StringUtils.isBlank(value) ? 0 : Integer.parseInt(value));
                        temp.setId(rand.nextInt());
                        wpList.add(temp);
                    }
                }
                Files.delete(tempFileForUploadedExcelFile.toPath());
                inputStreamForTempFile.close();
                workbook.close();
}

0 个答案:

没有答案