summaryRow listener?

UI Components for JSF
Post Reply
arturo
Posts: 90
Joined: 23 Aug 2011, 09:57
Location: Mexico

15 Dec 2011, 15:31

Hi there,

I don't understand how summaryRow listener attribute should be used:

The 3.0 RC1 users guide says the following on page 355:
Method expression to execute before rendering summary
row. (e.g. to calculate totals).
For example, assuming that I want to calculate totals depending on the current sorted column, how can I do that with this listener? What is the method signature?

The example shown on the showcase and the users guide only puts a random value, so i dont see this listener in action

Thanks
Last edited by arturo on 18 Dec 2011, 05:59, edited 1 time in total.
PrimeFaces 4.0 | Extensions 1.1.0 | GlassFish 4.0 | Mojarra 2.2.4 | NetBeans 7.3.1

syphinx
Posts: 24
Joined: 09 Nov 2010, 16:50

15 Dec 2011, 17:53

Hi,

I also don't understand how we can use summary row ? Can you give a more understandable example instead of generating random number in summary row?

Regards,

arturo
Posts: 90
Joined: 23 Aug 2011, 09:57
Location: Mexico

19 Dec 2011, 23:36

I read the 3.0 RC2 Users guide and have not found information about sumaryRow listerner usage.

Can someone explain how to use it?

Thanks
PrimeFaces 4.0 | Extensions 1.1.0 | GlassFish 4.0 | Mojarra 2.2.4 | NetBeans 7.3.1

csmart
Posts: 2
Joined: 26 Jan 2012, 06:33

26 Jan 2012, 06:34

Now that 3.0 is GA - is there any way to specify what the grouping is so a total could be calculated?

vineet
Posts: 387
Joined: 14 Oct 2011, 23:40

26 Jan 2012, 07:21

I am also looking for something similar so that summary row can be updated on varoius events like filter etc . also how to have a summary row without grouping ?

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

26 Jan 2012, 10:15

Listener gets the group property which is the sortBy value which you can use to calculate totals or any other operation.

yamada
Posts: 13
Joined: 20 Mar 2012, 19:20

22 Mar 2012, 15:28

First you need to get the proper column sorting event:

viewtopic.php?f=3&t=13365&p=61077#p61077

With this you will know which column is being sorted in the backing bean.

Second you need to created the summaryRow listener to handle each summary case:

In the XHTML (in dataTable):

Code: Select all

<p:summaryRow listener="#{backingBean.calculateTotal}">  
                            <p:column colspan="3" style="text-align:right">  
                                Total:  
                            </p:column>  

                            <p:column>  
                                #{backingBean.total} 
                            </p:column>  
                        </p:summaryRow>
In the bean:

Code: Select all

public void calculateTotal(Object o) {
        this.total = 0.0d;
        String name = "";
        if(o != null) {
            if(o instanceof String) {
                name = (String) o;
                for(MyRowObject p : (List<MyRowObject>) dataTableModel.getWrappedData()) { // The loop should find the sortBy value rows in all dataTable data.
                    switch(sortColumnCase) { // sortColumnCase was set in the onSort event
                        case 0:
                            if(p.getcolumn0data().getName().equals(name)) {
                                this.total += p.getcolumn0data().getValue();
                            }
                            break;
                        case 1:
                            if(p.getcolumn1data().getName().equals(name)) {
                                this.total += p.getcolumn1data().getValue();
                            }
                            break;
                    }
                }
            }
        }
    }
Just keep in mind that this calculateTotal method is called at each summaryRow, and each time it scan all the table model data using string comparison. So use with care when you have several users at the same time.
JDK 1.7
PRIMEFACES 5.0
NB 8.0
JSF 2.2
GlassFish 4.0 (Mojarra 2.2.8)

chuckedw
Posts: 9
Joined: 31 Jul 2014, 14:54

31 Jul 2014, 14:59

If you are working with a fix sorting order in your datatable, then its just simple as this:

Code: Select all

								<p:summaryRow listener="#{view.calculateTotal(entity.field)}">
									<p:column colspan="11" style="text-align:right">
										<h:outputText value="Total:" />
									</p:column>
									<p:column>
										<div style="text-align: right;">
											R$
											<h:outputText value="#{view.totalSummary}"
												converter="#{doubleConverterNull}" />
										</div>
									</p:column>
								</p:summaryRow>

And...

Code: Select all

	public void calculateTotal(Object valueOfThisSorting) {
		BigDecimal total = CurrencyUtils.getBigDecimalCurrency(0.0);
		for (Entity r : getList()) { // this is the list used in the value attribute of datatable
			if (r.getField().equals(valueOfThisSorting)) {
				total = total.add(CurrencyUtils.getBigDecimalCurrency(r.getTotal()));
			}
		}
		setTotalSummary(total.doubleValue());
	}

FalcoNChileno
Posts: 3
Joined: 06 Aug 2014, 19:24

31 Dec 2014, 18:53

I do not work, you can make a short code.

Thank You :)

Cekelence
Posts: 1
Joined: 18 Aug 2016, 10:04

19 Aug 2016, 12:28

i have problem with
dataTableModel
sortColumnCase
getcolumn0data()
getcolumn1data()

i don't now how to init this it's not define in my class how to do it

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 31 guests