# How to calculate et set sum of a listbox price column in a footer???

61 1

Hi

How can i calculate et set sum of a listbox price column in a footer???

thanks

delete retag edit

## 7 Replies

9393 3 7 16
http://www.oxitec.de/

In my cases, i do it with an extra call against the database.

Because it can be that the sum is for 120 records that are paged in 6 x 20 records per listbox page.
In that case a sum for only 20 pieces of the cake is not relevant.

best
Stephan

61 1

OK it's a good idea.

Can you give me a complete example please?

The First ZK user in Senegal

9393 3 7 16
http://www.oxitec.de/

Hi, first ZK user in Senegal :-)

you can find the whole sources in the Zksample2 application here.
Look at the de.forsthaus.webui.order.OrderListCtrl.java and the corresponding zul file, listed namely in that class description.

Here are only the important lines:

                   private void paintComponents() {

. . .

/** +++ get the SUM of the orderpositions for the ListFooter +++ */
String s = String.valueOf(getOrderService().getOrderSum(anOrder));
if (s != "null") {
listfooter_OrderPosList_WholePrice.setLabel(s);
} else
listfooter_OrderPosList_WholePrice.setLabel("0.00");

}


The hibernate DAO code:

	/**
* Gets the sum for all 'aupGesamtwert' fields of the table orderPositions
* for an order (auftrag).<br>
*
*
* @see de.forsthaus.backend.dao.OrderDAO#getOrderSum(de.forsthaus.backend.model.Order)
*/
@Override
public BigDecimal getOrderSum(Order order) {
DetachedCriteria criteria = DetachedCriteria.forClass(Orderposition.class);
criteria.setProjection(Projections.sum("aupGesamtwert"));

BigDecimal sumResult = (BigDecimal) DataAccessUtils.uniqueResult(getHibernateTemplate().findByCriteria(criteria));

return sumResult;
}


best
Stephan

61 1

Thanks

aktejo
155 3

whoa, have just know that zk List having such a list foot, thats kindof useful,... great !!!

Arsen
381 2

Good day, Stephan.
Could you help me too? Your example works fine, if you have explicilty declared footer component.
But how could I get the same target, if I'm using model+renderer? When model is updated, it fires DataChange event and causes Renderer to redraw listiem - I need the same thing for footer, because code, which changes model, knows nothing about listbox(es) assigned to this model. Is there any way to set renderer for footer or somthing like that?

9393 3 7 16
http://www.oxitec.de/

Hmmmm, i haven't this before. But think what i say about the informational value between a sum of the first paged 20 listitems or the sum of an order that are exists of 120 records that are paged 6 x 20.
In your case i would do an extra call for calculating the footer value in the methode where you fill the model aka pseudoCode

setOrders(ListModelList orders) {
footerSum = getMyDAO().getOrderSum(anOrder);
this.orders = getMyDAO().getOrderPositions(anOrder);
};

(Listbox.getModel(new ListModelList(getOrders))))

where you can force the Model changes.

best
Stephan

[hide preview]

## Stats

Seen: 803 times

Last updated: Jul 10 '10

## Related questions

Support Options
• Email Support
• Training
• Consulting
• Outsourcing