【问题标题】:Iterating <rich:columns> having value contains List , that contains another list is not working?迭代具有值的 <rich:columns> 包含 List ,包含另一个列表不起作用?
【发布时间】:2012-01-23 11:23:39
【问题描述】:

我正在使用richFaces 3.3 和 JSF 1.2。

在我的示例应用程序中,我需要显示项目列表并包含 即(2列有,第三列是)

如果我尝试将另一个 List 中的 List 作为 rich:columns 的值,则意味着它不起作用,但直接 bean 值正在起作用 ???

主类

拥有 getter , setter of String item1 , String item2, List priceList

mainList

 contains item 1
          item 2
          List<price>  priceList like that...

so in  <rich:dataTable> if i try to  give value like 

                            <rich:dataTable  id="positions" value="#{bean.mainList}" var="var">


                                    <rich:column>
                                        <f:facet name="header">
                                            <h:outputText   value="item1"/>
                                        </f:facet>
                                        <h:outputText id="contname" value="#{var.item1}">
                                    </rich:column>


                                    <rich:column>
                                        <f:facet name="header">
                                            <h:outputText   value="item2"/>
                                        </f:facet>
                                        <h:outputText id="contname" value="#{var.item2}">
                                    </rich:column>

                                    <rich:columns value="#{var.priceList}" var="partnerPriceItem"  columns="2" index="ind">
                                        <f:facet name="header">
                                                <h:outputText id="output#{ind}" value="#{partnerPriceItem.id}"  />
                                            </f:facet>
                                                <h:outputText id="price#{ind}" value="#{partnerPriceItem.price}" />
                                    </rich:columns>

                                    </rich:dataTable>

这里的前 2 列工作正常。但是当我尝试从另一个列表中引用时意味着不起作用??

输出类似

项目 1 项目 2 价格 1 价格 2 价格 3

1 2 100 200 300

2 2 50 100 75

【问题讨论】:

    标签: jsf jsf-1.2


    【解决方案1】:

    要解决您的问题,您需要使用rich:dataTable 和rich:subTable。 exadel live demo 站点中有一个示例。

    让我们看一下代码(这不是网站的真实代码,这只是一个示例):

    Java 类

    //POJOs
    public class Expenses {
        private Date day;
        private decimal meals;
        private decimal hotels;
        private decimal transports;
        //getters and setters for the attributes;
    }
    
    public class Record {
        private String city;
        private List<Expenses> items;
        private decimal totalMeals;
        private decimal totalHotels;
        private decimal totalTransport;
        private decimal total;
        //getters and setters for the attributes;
    }
    
    public class ExpReport {
        private List<Record> records;
        private decimal totalMeals;
        private decimal totalHotels;
        private decimal totalTransport;
        private decimal grandTotal;
        //getters and setters for the attributes;
    }
    
    //Managed Bean
    public class Report {
        private ExpReport expReport;
        //getter and setter for the attribute;
    }
    

    我们有一个包含 ExpReport 实例的托管 bean Report。在 ExpReport 中,我们有一个记录列表(我们希望在表中显示的列表),但每条记录都有自己的内部费用列表(我们希望与记录一起显示的列表)。现在,我们只需要在其中设置rich:dataTable 和rich:subTable 即可让我们的jsp 中的魔法流动起来。

    注意:您可以在rich:column 的文档中获取更多信息。

    <!-- Here we set the data list for the dataTable as the list of records of our
         object expReport. Also, the name of the iterator will be 'record' -->
    <rich:dataTable width="100%" value="#{report.expReport.records}" var="record">
        <f:facet name="header">
            <!-- This columnGroup tag component will define a group of columns for
                 the header of the dataTable (the body of the dataTable can has
                 more columns, for this example there will be the same).-->
            <rich:columnGroup>
                <rich:column rowspan="2">
                    <rich:spacer />
                </rich:column>
                <rich:column colspan="3">
                    <h:outputText value="Expenses" />
                </rich:column>
                <rich:column rowspan="2">
                    <h:outputText value="subtotals" />
                </rich:column>
                <!-- The 'breakBefore' attribute tells the column  to start from the
                     next row to be rendered in the dataTable. This attribute doesn't
                     affect the rows generated in rich:extendedDataTable. For more
                     info, see the documentation (link above the code). -->
                <rich:column breakBefore="true">
                    <h:outputText value="Meals" />
                </rich:column>
                <rich:column>
                    <h:outputText value="Hotels" />
                </rich:column>
                <rich:column>
                    <h:outputText value="Transport" />
                </rich:column>
            </rich:columnGroup>
        </f:facet>
        <!-- Now, let's set the content of the rows of the dataTable -->
    
        <!-- This column will show city from our 'record' iterator. -->
        <rich:column colspan="5">
            <h:outputText value="#{record.city}" />
        </rich:column>
        <!-- After printing the city, we want to show the data from the expenses
             made in this record. For this, we will use the subTable tag
             component, setting the 'record.items' list as the data list for
             subTable and naming the inner iterator 'expense'. The syntax for the
             subTable is like the dataTable. -->
        <rich:subTable value="#{record.items}" var="expense">
            <rich:column>
                <h:outputText value="#{expense.day}" />
            </rich:column>
            <rich:column>
                <h:outputText value="#{expense.meals}">
                    <f:convertNumber pattern="$####.00" />
                </h:outputText>
            </rich:column>
            <rich:column>
                <h:outputText value="#{expense.hotels}">
                    <f:convertNumber pattern="$####.00" />
                </h:outputText>
            </rich:column>
            <rich:column>
                <h:outputText value="#{expense.transport}">
                    <f:convertNumber pattern="$####.00" />
                </h:outputText>
            </rich:column>
            <rich:column>
                <rich:spacer />
            </rich:column>
        </rich:subTable>
    </rich:dataTable>
    

    对不起,我的英语不好,我希望这对您的申请有所帮助。

    【讨论】:

    • 是的,非常感谢您的回复。听起来不错,让我有了清晰的想法。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-05-31
    • 2021-09-21
    • 1970-01-01
    • 1970-01-01
    • 2018-07-24
    • 2013-02-04
    • 2020-08-05
    相关资源
    最近更新 更多