-
FEATURED COMPONENTS
First time here? Check out the FAQ!
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"?
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.
Thank you very much!
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.
<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; } }
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
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?
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>
*************
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.
Asked: 2009-04-15 02:16:56 +0800
Seen: 453 times
Last updated: Apr 26 '09