2011-10-13 58 views
3

我有一个应用程序包含Primefaces数据表中的commandLinks。 commandLinks链接到应用程序中的其他页面并传递参数。当我尝试使用Primefaces的ExcelExporter导出dataTable时,生成的.xls文件包含commandLink的value属性,而不是包含在commandLink中的outputText的value属性。 dataTable的代码中带有CommandLinks的Primefaces ExcelExporter

柱:

<p:dataTable var="dataRow" id="myTable"> 
    <p:column> 
     <f:facet name="header"> 
      <h:outputText value="MyColumn" /> 
     </f:facet> 
     <h:outputLink value="myPage.xhtml"> 
      <f:param name="columnId" value="#{dataRow.columnId}" /> 
      <h:outputText value="#{dataRow.columnName }" /> 
     </h:outputLink> 
    </p:column> 
</p:dataTable> 

ExcelExporter代码:

<h:commandLink> 
    <h:outputText value="Export" /> 
     <p:dataExporter type="xls" target="myTable" fileName="tableResults"/> 
</h:commandLink> 

当我出口使用ExcelExporter表,导出的数据是 “myPage.xhtml”,当我把它想是“#{dataRow.columnId}”中包含的数据。有没有一种方法来格式化链接,以便将它们与我想要的文本一起导出?

回答

1

我能够通过改变链接到commandLinks来解决这个问题,通过确定导航和setPropertyActionListeners传递参数的动作。它看起来像PrimeFaces总是从父组件获取值,所以这似乎是最好的解决方法。 dataExporter代码保持不变。

改性XHTML代码:

<p:dataTable var="dataRow" id="myTable"> 
    <p:column> 
     <f:facet name="header"> 
      <h:outputText value="MyColumn" /> 
     </f:facet> 
     <h:commandLink value="#{dataRow.columnName}" action="myPage"> 
      <f:setPropertyActionListener target="#{myPage.columnId}" 
       value="#{dataRow.columnId}"/> 
     </h:commandLink> 
    </p:column> 
</p:dataTable> 

导航规则添加到faces-config.xml中:

<navigation-rule> 
    <navigation-case> 
     <from-outcome>myPage</from-outcome> 
     <to-view-id>/myPage.xhtml</to-view-id> 
     <redirect /> 
    </navigation-case> 
</navigation-rule>