-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4773394
By: msurov
Hi All,
I have a grid is a follows.
I should implement capability to delete/edit current row by using buttons.
I want to make it is as follows:
<button label="Edit"
onClick="PersonnelWnd.onEditPerson(self.getAttribute("person"))">
<custom-attributes person="@{user}"/> </button>
But it seems @{user annotation does not work for custom attribute.
How could I implement this by using other approaches?
<grid id="grid" model="@{users,load-when='self.onBeanChange', access='both'}"
mold="paging" pageSize="5">
<columns sizable="true">
<column id="lastName" sortAscending="${asc}" sortDescending="${dsc}"
label="???????"/>
<column id="firstName" sortAscending="${asc}" sortDescending="${dsc}"
label="???"/>
<column id="middleName" sortAscending="${asc}" sortDescending="${dsc}"
label="????????"/>
<column id="mainPhone" sortAscending="${asc}" sortDescending="${dsc}"
label="???????"/>
<column id="mobile1" sortAscending="${asc}" sortDescending="${dsc}"
label="???????1"/>
<column id="mobile2" sortAscending="${asc}" sortDescending="${dsc}"
label="???????2"/>
<column id="login" sortAscending="${asc}" sortDescending="${dsc}"
label="??? ????????????"/>
<column label=""/>
</columns>
<rows>
<row self="@{each=user}">
<label value="@{user.lastName}"/>
<label value="@{user.firstName}"/>
<label value="@{user.middleName}"/>
<hbox>
<label value="@{user.mainPhone}"/>
<checkbox disabled="true" checked="@{user.mainPhoneVisible}"
label="??????????"/>
</hbox>
<hbox>
<label value="@{user.mobile1}"/>
<checkbox disabled="true" checked="@{user.mobile1Visible}"
label="??????????"/>
</hbox>
<hbox>
<label value="@{user.mobile2}"/>
<checkbox disabled="true" checked="@{user.mobile2Visible}"
label="??????????"/>
</hbox>
<label value="@{user.login}"/>
<hbox>
<button label="Edit"
onClick="PersonnelWnd.onEditPerson(self.getAttribute("person"))">
<custom-attributes person="@{user}"/>
</button>
</hbox>
</row>
</rows>
</grid>
Regards,
Maxim
Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4774966
By: robbiecheng
Hi Maxim,
Databinding wont' be able to get/set attributes saved in a map. I recommend you to save the the person object in the row component, and then invoke parent.parent.value to get the person object.
/robbie
Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4775204
By: msurov
Hi Robbie,
Tnank you. It works fine.
<row value="@{person}" self="@{each=person}">
<label value="@{person.lastName}"/>
<label value="@{person.firstName}"/>
<label value="@{person.middleName}"/>
<hbox>
<label value="@{person.mainPhone}"/>
<checkbox disabled="true" checked="@{person.mainPhoneVisible}"
label="??????????"/>
</hbox>
<hbox>
<label value="@{person.mobile1}"/>
<checkbox disabled="true" checked="@{person.mobile1Visible}"
label="??????????"/>
</hbox>
<hbox>
<label value="@{person.mobile2}"/>
<checkbox disabled="true" checked="@{person.mobile2Visible}"
label="??????????"/>
</hbox>
<label value="@{person.login}"/>
<hbox>
<button label="???????"
onClick="PersonnelWnd.onPersonDelete(self.parent.parent.value)">
</button>
<button label="?????????????"
onClick="PersonnelWnd.onEditPerson(self.parent.parent.value)">
</button>
</hbox>
</row>
Regards,
Maxim
Solution does not work - please help
=====================================
I am looking for exactly the same functionality: a grid with an annotated model and 'edit' or 'delete' buttons.
However, the solution suggested above does not work (at least, where I am).
Help is highly appreciated. Thanks in advance.
This is my code:
================
<grid model="@{win.family.children}">
<columns>
<column label="Name" />
<column width="35px;" />
</columns>
<rows id="children">
<row self="@{each=child}" value="@{child}">
<textbox value="@{child.name}" />
<button image="/img/remove.png"
onClick="win.removeChild((Person) self.parent.value);" />
</row>
</rows>
</grid>
Problem:
===============
The self.parent.value ALWAYS refers to the FIRST row element, no matter what row I click on delete.
Seems like either of these is the case:
a) value="@{child}" is evalutated only once ?
b) the button is created only once, and reused in all rows for performance
Can any one help?
Thanks very much.
Maarten Hogendoorn
Hi,
The old article may only match to old standard, I don't know whether old code can work on Zk 3.5.2 or not. So I revised your code to make it work as expectation, I used my class to be child information, please note it.
code :
<window id="win" title="new page title" border="normal"> <zscript> class Children{ String name="xx"; public Children(String s){ name = s; } public String getName(){ return name; } } List child = new ArrayList(4); child.add(new Children("child1")); child.add(new Children("child2")); child.add(new Children("child3")); child.add(new Children("child4")); String lastChildName = ((Children) child.get(child.size()-1)).getName(); </zscript> <grid model="@{child}" id="grid"> <columns> <column label="Name" /> <column width="35px;" /> </columns> <rows id="children"> <row forEach="${child}" id="${each.name}" onClick="delete_name.setValue(self.id);"> <textbox value="${each.name}" /> <button label="delete me" if="${lastChildName == each.name}" onClick='win.getFellow(delete_name.getValue()).detach()'/> </row> <row> <hbox> <label>delete value = </label> <label id="delete_name"/> </hbox> </row> </rows> </grid> </window>
When you click a row of the grid, and then clicking the button, the selected row will be deleted.
Dear hideokidd,
Thank you for your response. I am sorry to say it's not a complete solution.
First, the values of the text boxes in your code are not bound to a value bean (setting a new value doesn't get saved in a backing bean)
Second, not every row has it's own operational button(s).
Third, you only detach a component from the view, in stead of shrinking a backing list (called 'child' in your example).
I am looking for a solution way to work with the backing bean inside each annotated row of an annotated grid.
Here, annotated means bound to a specific data record.
Thanks a lot
Here is my example:
<grid model="@{win.family.children}"> <columns> <column label="Name" /> <column width="35px;" /> </columns> <rows id="children"> <row self="@{each=child}" value="@{child}"> <textbox value="@{child.name}" /> <button id="trash" image="/img/remove.png" /> </row> </rows> </grid>
Javacode (autowired Event, check MVC-Smalltak or add the forward-attribute to the button).
Note this resolution requires the value in the row (like your example)
public void onClick$trash(ForwardEvent event) { Row target = (Row) event.getOrigin().getTarget().getParent(); Person child = (Person) row.getValue(); }
>> The self.parent.value ALWAYS refers to the FIRST row element, no matter what row I click on delete.
>> Seems like either of these is the case:
>> a) value="@{child}" is evalutated only once ?
>> b) the button is created only once, and reused in all rows for performance
I think this problem is, that the row in the zul-file is the template for the databinder. The template will be cloned for all dataentries from the model. I think
onClick="win.removeChild((Person) event.target.parent.value);"
However i prefer the non-interpreted java-way. Note: You have update path to the parent grid when i.e. you do i.e. <hbox><button>.. - you need one more getParent();
Here is generic utilcode (for grid and listbox) (requires a set value in (listitem or row):
public Object getListBindingData(ForwardEvent event) { Component target = event.getOrigin().getTarget(); while(!(target instanceof Row || target instanceof Listitem)) { target = target.getParent(); }; if (target instanceof Row) { Row row = (Row) target; return ((Row) target).getValue(); } if (target instanceof Listitem) { return ((Listitem) target).getValue(); } return null; }
// I use it like this - no headache, when the layout is changing
public void onClick$trash(ForwardEvent event) { Person child = (Person) getListBindingData(event); System.out.println("Delete " + child.getName()); }
/Robert
Asked: 2008-02-12 13:03:52 +0800
Seen: 554 times
Last updated: Feb 04 '09