0

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

asked 2010-03-11 11:29:29 +0800

xadim gravatar image xadim
61 1

updated 2010-03-11 11:31:20 +0800

Hi

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

thanks

delete flag offensive retag edit

7 Replies

Sort by ยป oldest newest

answered 2010-03-11 14:56:24 +0800

terrytornado gravatar image terrytornado flag of Germany
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

link publish delete flag offensive edit

answered 2010-03-12 11:16:51 +0800

xadim gravatar image xadim
61 1

Hi terrytornado!!!

OK it's a good idea.

Can you give me a complete example please?

Thanks for answer.

xadim
The First ZK user in Senegal

link publish delete flag offensive edit

answered 2010-03-12 13:32:36 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

updated 2010-03-12 13:35:19 +0800

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

link publish delete flag offensive edit

answered 2010-03-13 00:55:07 +0800

xadim gravatar image xadim
61 1

Very kind terrytornado

Thanks

link publish delete flag offensive edit

answered 2010-03-23 21:09:53 +0800

aktejo gravatar image aktejo
155 3

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

link publish delete flag offensive edit

answered 2010-07-10 11:30:24 +0800

Arsen gravatar image 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?

link publish delete flag offensive edit

answered 2010-07-10 15:44:06 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

updated 2010-07-10 15:48:15 +0800

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

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2010-03-11 11:29:29 +0800

Seen: 803 times

Last updated: Jul 10 '10

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More