primefaces数据表导出器

时间:2014-04-12 03:02:54

标签: primefaces datatable export

在XHTML页面中支持多种语言。我使用数据表显示数据,如:

<p:column style="text-align:center; width:7%;" exportPosition="center">
      <f:facet name="header">
           <h:outputText value="#{msg['common']['identityIssuePlace']}" />
      </f:facet>
      <h:outputText value="#{element.getLocalizedName(bean.locale)}" />
</p:column>

它显示确定。但我使用dataExporter导出数据,它会引发异常:

avax.el.PropertyNotFoundException: /backend/gms/account-manage.xhtml at line 170 and column 109 value="#{element.getLocalizedName(bean.locale)}": Property 'getLocalizedName' not found on type safp.acms.common.domain.IdentityIssuePlace

dataExporter无法绑定方法?谢谢高级。

3 个答案:

答案 0 :(得分:1)

我用这个解决了它

Xhtml代码:

<p:commandButton image="ui-icon-xls" styleClass="botonExcel" value="mylabel" ajax="false">                              
   <p:dataExporter type="xls" target=":formEditar:tablaEditar" fileName="myFilename"  postProcessor="#{parametrosMB.postProcessXLS}" />  
</p:commandButton> 

Java代码:

  public void postProcessXLS(Object document) {
        HSSFWorkbook wb = (HSSFWorkbook) document;
        HSSFSheet sheet = wb.getSheetAt(0);

        //Loop for all datafiles 
        //(sheet.getLastRowNum() + 1) => because file 0 is a header
        for (int i = 0; i < sheet.getLastRowNum() + 1; i++) {
            HSSFRow header = sheet.getRow(i);              

            //Loop for each cell
            for (int j = 0; j < header.getPhysicalNumberOfCells(); j++) {
                HSSFCell cell = header.getCell(j);                    

                //Here you need verify the cell to change value and assign new value
                cell.setCellValue("the new value!!");
            }
        }
    }

启发:http://www.primefaces.org/showcase/ui/data/dataexporter/customizedDocuments.xhtml

抱歉我的英文不好

答案 1 :(得分:1)

解决!!!!

使用此p:dataExporter does not recognize p:cellEditor

我的解决方案太相似了,只更改了一个功能&#34; exportValue&#34;和类的延伸。

XHTML:可

 <h:commandLink value="Excel" action="#{myBean.exportExcel(table, 'filename')}" />

<p:dataTable id="tablaDatos" binding="#{table}" etc...> 
<!-- data -->
</p:dataTable>

bean上的方法:

public void exportExcel(DataTable table, String filename) throws IOException {
    FacesContext context = FacesContext.getCurrentInstance();
    MyExporterXls exporter = new MyExporterXls();
    exporter.export(context, table, filename, false, false, "UTF-8", null, null);
    context.responseComplete();
}

我的解决方案

public class MyExporterXls extends ExcelExporter {

    @Override
    protected String exportValue(FacesContext fc, UIComponent uic) {
        String valor = "";
        System.out.println("uic = " + uic);

        if (uic instanceof HtmlOutputText) {
            valor = parseValorCelda(((HtmlOutputText) uic).getValue());
        }
        return valor;           
    }

    private String parseValorCelda(Object valor) {
        String retorno = "";

        //Cadenas
        if (valor instanceof String) {
            retorno = (String) valor;
        }

        //Numeros ENTEROS
        if (valor instanceof Short) {
            retorno = ((Short) valor).toString();
        }

        if (valor instanceof Integer) {
            retorno = ((Integer) valor).toString();
        }

        if (valor instanceof BigInteger) {
            retorno = ((BigInteger) valor).toString();
        }

        if (valor instanceof Long) {
            retorno = ((Long) valor).toString();
        }

        //Numeros decimales
        if (valor instanceof Double) {
            retorno = ((Double) valor).toString();
        }

        if (valor instanceof Float) {
            retorno = ((Float) valor).toString();
        }

        if (valor instanceof BigDecimal) {
            retorno = ((BigDecimal) valor).toString();
        }

        return retorno;
    }

}

答案 2 :(得分:0)

自从提出这个问题已经有很长一段时间了,@ dmnoguera给出的唯一答案对我来说并不满意。

有效地看来,primefaces'dataExporter不支持对方法的绑定。但是我有办法解决这个问题:

这是dataTable中我可以导出的列:

<p:column>
    <f:facet name="header">
        <h:outputText value="#{messages['portfolioOfUser']}" />
    </f:facet>
    <h:outputText id="portfoliosOfUser"
        value="#{editPortfolio.portfoliosOfUser(listCustomerTableRow)}"
        escape="false" />
</p:column>

这是我的豆子:

public class EditPortfolioManagedBean extends EnhancedManagedBean {

    private String portfoliosOfUser ;

    public String getPortfoliosOfUser() {
        return "Coucou";
    }

    public void setPortfoliosOfUser(String portfoliosOfUser) {
        this.portfoliosOfUser = portfoliosOfUser;
    }

//Cool stuf - Start
...
//Cool stuf - End

public String portfoliosOfUser(Customer customer)
    {
        String listOfPortfolios = new String("");

        //Really sexy computation and high level algorithms

        return listOfPortfolios;

    }
}

这样我欺骗dataExporter,当我导出表格时,StringportfoliosOfUser(Customer customer)而不是“Coucou”给出。希望它对其他人有用!