-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi
How can i calculate et set sum of a listbox price column in a footer???
thanks
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
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> * * (non-Javadoc) * * @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.add(Restrictions.eq("order", order)); criteria.setProjection(Projections.sum("aupGesamtwert")); BigDecimal sumResult = (BigDecimal) DataAccessUtils.uniqueResult(getHibernateTemplate().findByCriteria(criteria)); return sumResult; }
best
Stephan
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?
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
Asked: 2010-03-11 11:29:29 +0800
Seen: 806 times
Last updated: Jul 10 '10