0

how can I refresh all page components

asked 2009-04-15 02:16:56 +0800

leoyc gravatar image leoyc
163 3

sample code like this:
******************
<zk>
<window id="orderfrm">
<decimalbox format="#,##0.#" id="amount">
.....
.....
<button label="Save" width="60px" onClick="submit();" />

<zscript>
void submit()
{
Map arg = new HashMap();
arg.put("orderid",orderid.value);
Components.removeAllChildren(view);
Executions.createComponents("/zul/orderdetail.zul",view,arg);

}
</zscript>

</window>

<window id="view"/>

</zk>
****************
when I delete item in "orderdetail.zul" ,how can I refresh "amount"?

delete flag offensive retag edit

10 Replies

Sort by » oldest newest

answered 2009-04-15 07:57:40 +0800

iantsai gravatar image iantsai
2755 1

You need to design a global controller yourself for this situation.
Maybe call it "orderfrmCtrl" and put it in page attributes, then in your "/zul/orderdetail.zul" you retrieve "CollectionData" from this orderfrmCtrl,
and this CollectionData is being monitored which means any modifications of this collection would trigger a listener to do something.

Then, add a listener to this ctrl which will change the value of your "amount" decimalbox .

PS: If you're seeking good implementations of such kind of "Monitored Collection" you're lucky,
ZK is already done it for you, please take a look at ListModelList.

link publish delete flag offensive edit

answered 2009-04-15 12:13:03 +0800

leoyc gravatar image leoyc
163 3

hi,iantsai.can you give me a sample.

thank you very much.

--leoyc

link publish delete flag offensive edit

answered 2009-04-16 01:54:51 +0800

iantsai gravatar image iantsai
2755 1

I don't have the content of your orderDetail.zul.

If you can post it in short, I can point out which part shall do the trick.

link publish delete flag offensive edit

answered 2009-04-21 02:49:56 +0800

leoyc gravatar image leoyc
163 3

updated 2009-04-21 03:02:26 +0800

Thank you very much!

link publish delete flag offensive edit

answered 2009-04-21 02:52:49 +0800

leoyc gravatar image leoyc
163 3

updated 2009-04-21 03:00:49 +0800

Hi,iantsai,"OrdersDetail.zul" like this:
****************
<?xml version="1.0" encoding="GB2312"?>
<zk>

<hbox>
<window width="30px"/>
<window >
<zscript>
import my.ordersdManager;
orderitembean = new OrdersdManager().findAll(arg.get("orderid"));
</zscript>
<grid id="billdList" width="680px" height="160px" >
<columns >
<column label="Itemcode" width="60px" />
<column label="ItemDesc" width="210px" />
<column label="Unit" width="60px"/>
<column label="Type" width="60px"/>
<column label="Price" width="60px" />
<column label="qty" width="40px"/>
<column label="Discount" width="40px" />
<column label="Amount" width="80px" />

</columns>
<rows>
<row value="${each.Itemcode}" forEach="${orderitembean}" >
<label value="${each.Itemcode}" onClick="delrec(self.parent)" />
<label value="${each.Itemdesc}" />
<label value="${each.Unit}" />
<label value="${each.Type}" />
<label value="${each.Price}" />
<label value="${each.Qty}" />
<label value="${each.Discount}" />
<label value="${each.Amount}" />

</row>
</rows>
</grid>
<zscript>

String orderno=arg.get("orderid");
void delrec(Row row)
{
if (Messagebox.show("Confirm Delete?"+"("+self.value+")", "Information", Messagebox.OK|Messagebox.CANCEL,Messagebox.QUESTION)==Messagebox.OK)
{
import java.sql.*;
import javax.sql.DataSource;
import javax.naming.*;
import my.DBPool;
Connection conn = null;
PreparedStatement stmt = null;
conn = DBPool.getPool().getConnection();
stmt = conn.prepareStatement("delete from ordersd where orderid=? and itemcode=?");
stmt.setString(1, orderno);
stmt.setString(2, self.value);
stmt.executeUpdate();
conn.commit();
stmt = conn.prepareStatement("update orders a,(select orderid,sum(amount) as amount from ordersd where orderid=? group by orderid) b set a.amount=b.amount,disamount=b.amount-a.nosale where a.orderid=b.orderid");
stmt.setString(1, orderno);
stmt.executeUpdate();
conn.commit();

stmt.close();
conn.close();
row.detach();
}
}
</zscript>
</window>
</hbox>
</zk>
*************
when delete item in "ordersdetail",I want refresh amount.

link publish delete flag offensive edit

answered 2009-04-21 08:32:41 +0800

iantsai gravatar image iantsai
2755 1

<zscript>

orderRowRenderer = new OrderRowRenderer();// implement this by yourself!
</zscript> 


// your grid is only like this:
<grid id="billdList" model="${orderfrmCtrl.orders}" rowRenderer="${orderRowRenderer}" >
<columns >
<column label="Itemcode" width="60px" />
<column label="ItemDesc" width="210px" />
<column label="Unit" width="60px"/>
<column label="Type" width="60px"/>
<column label="Price" width="60px" />
<column label="qty" width="40px"/>
<column label="Discount" width="40px" />
<column label="Amount" width="80px" />

</columns>
// render your rows using a RowRenderer,
</grid> 

//----------Java---------------
public class OrderFormCtrl {

private ListModelList orders;
Decimalbox amount; // try yourself to get amount.

public ListModelList getOrders(){
  if(orders==null){
      orders = new ListModelList (new OrdersdManager().findAll(arg.get("orderid")));
      orders.addListDataListener(new ListDataListener(){
         public void onChange(ListDataEvent event){
            amount.setValue(orders.size());
         }});//end of class...
  }
  return orders;
}

}

link publish delete flag offensive edit

answered 2009-04-22 02:28:54 +0800

leoyc gravatar image leoyc
163 3

Hi,iantsai. Thanks for your reply.

I have two questions:
1.How can I use "orderitembean" in OrderRowRenderer()? ;
2.use "OrderFormCtrl" can Listener "amount" change,but I want change "amount" not in "OrdersDetail.zul" .


----Leoyc

link publish delete flag offensive edit

answered 2009-04-22 09:41:18 +0800

iantsai gravatar image iantsai
2755 1

About question 1, Google Code search:"rowrederer zk", you'll got tons of sample.

About question 2, I'm not understand your question, I thought that you want to "amount" reflect the modifications from ListModel, so can you explain it more precisely?

link publish delete flag offensive edit

answered 2009-04-24 08:16:00 +0800

leoyc gravatar image leoyc
163 3

updated 2009-04-25 19:12:58 +0800

I have two zul files, one is "orders.zul",the other is "ordersdetail.zul". I click "save" button in "orders.zul",it's runing:Executions.createComponents("/zul/ordersdetail.zul",view,arg), when I delete item in "ordersdetail.zul",I want refresh "ordersamount" in "orders.zul".

The following code desc "orders.zul" and "ordersdetail.zul":

*****************
"orders.zul"
******************
<zk>
<window id="ordersfrm">
<decimalbox format="#,##0.#" id="ordersamount">
.....
.....
<button label="Save" width="60px" onClick="submit();" />

<zscript>
void submit()
{
Map arg = new HashMap();
arg.put("orderid",orderid.value);
Components.removeAllChildren(view);
Executions.createComponents("/zul/ordersdetail.zul",view,arg);

}
</zscript>

</window>

<window id="view"/>
</zk>

*****************
"OrdersDetail.zul"
****************
<?xml version="1.0" encoding="GB2312"?>
<zk>

<hbox>
<window width="30px"/>
<window >
<zscript>
import my.ordersdManager;
orderitembean = new OrdersdManager().findAll(arg.get("orderid"));
</zscript>
<grid id="billdList" width="680px" height="160px" >
<columns >
<column label="Itemcode" width="60px" />
<column label="ItemDesc" width="210px" />
<column label="Unit" width="60px"/>
<column label="Type" width="60px"/>
<column label="Price" width="60px" />
<column label="qty" width="40px"/>
<column label="Discount" width="40px" />
<column label="Amount" width="80px" />

</columns>
<rows>
<row value="${each.Itemcode}" forEach="${orderitembean}" >
<label value="${each.Itemcode}" onClick="delrec(self.parent)" />
<label value="${each.Itemdesc}" />
<label value="${each.Unit}" />
<label value="${each.Type}" />
<label value="${each.Price}" />
<label value="${each.Qty}" />
<label value="${each.Discount}" />
<label value="${each.Amount}" />

</row>
</rows>
</grid>
<zscript>

String orderno=arg.get("orderid");
void delrec(Row row)
{
if (Messagebox.show("Confirm Delete?"+"("+self.value+")", "Information", Messagebox.OK|Messagebox.CANCEL,Messagebox.QUESTION)==Messagebox.OK)
{
import java.sql.*;
import javax.sql.DataSource;
import javax.naming.*;
import my.DBPool;
Connection conn = null;
PreparedStatement stmt = null;
conn = DBPool.getPool().getConnection();
stmt = conn.prepareStatement("delete from ordersd where orderid=? and itemcode=?");
stmt.setString(1, orderno);
stmt.setString(2, self.value);
stmt.executeUpdate();
conn.commit();
stmt = conn.prepareStatement("update orders a,(select orderid,sum(amount) as amount from ordersd where orderid=? group by orderid) b set a.amount=b.amount,disamount=b.amount-a.nosale where a.orderid=b.orderid");
stmt.setString(1, orderno);
stmt.executeUpdate();
conn.commit();

stmt.close();
conn.close();
row.detach();
}
}
</zscript>
</window>
</hbox>
</zk>
*************

link publish delete flag offensive edit

answered 2009-04-26 05:40:02 +0800

iantsai gravatar image iantsai
2755 1

Because you already use a "ListModel" to control your Grid, so you shouldn't delete the Row by yourself, you should remove one reccord from ListModel and let the model deteach the corresponding row automatically for you.


in your RowRenderer, do somthing like this:

//...
row.setValue(data);
//...

Then at the end of your Code block in "void delrec(Row row)" method:

stmt.close();
conn.close();

You can do:

((java.util.List)myGridListModel).remove(row.getValue());


If you followed what I said before to implement ListModel + RowRenderer + ModelListener, Then the value of "amount" should react perfectly.

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: 2009-04-15 02:16:56 +0800

Seen: 453 times

Last updated: Apr 26 '09

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