0

Grid and databinding

asked 2008-02-12 13:03:52 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


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

delete flag offensive retag edit

6 Replies

Sort by ยป oldest newest

answered 2008-02-13 03:46:21 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


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

link publish delete flag offensive edit

answered 2008-02-13 08:02:27 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


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


link publish delete flag offensive edit

answered 2009-02-03 22:53:17 +0800

mhogendoorn gravatar image mhogendoorn
54
http://www.solvedo.com

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

link publish delete flag offensive edit

answered 2009-02-04 02:21:18 +0800

hideokidd gravatar image hideokidd
750 1 2

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.

link publish delete flag offensive edit

answered 2009-02-04 07:48:24 +0800

mhogendoorn gravatar image mhogendoorn
54
http://www.solvedo.com

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

link publish delete flag offensive edit

answered 2009-02-04 11:36:26 +0800

robertpic71 gravatar image robertpic71
1275 1

updated 2009-02-04 11:38:19 +0800

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);"
should work also.

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

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: 2008-02-12 13:03:52 +0800

Seen: 554 times

Last updated: Feb 04 '09

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