0

Problem with 2 windows and annotation

asked 2008-06-22 08:23:02 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=5045057

By: madruga0315

Hey,

This problem is kind a strange to explain...

I have an window which show some data with a annotated listbox. The form for this data is another window file, which is also annotated.
So when user clicks in new or edit button, the view window call Executions.createComponents("/form.zul", this, null);

After this executions the listbox, which was showing content, no longer shows, giving the impressions that the list has no items.
But it does, it can be seen in debug.

Both zul files have the AnnotateDataBinderInit declaration.

So I believe that this is a bug related with the annotation process, because if I set the parent of the form.zul on another window that is not annotated, then ir works.

/Madruga

delete flag offensive retag edit

5 Replies

Sort by ยป oldest newest

answered 2008-06-25 01:33:24 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=5052715

By: waterbottle

Hi, Madruga.
Why not post a reproducible code here?
It will help us to figure out the problem more easier.

/Dennis

link publish delete flag offensive edit

answered 2008-06-25 04:40:58 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=5052872

By: madruga0315

Hey Dennis,

Ive made a simple code to show the problem, there are 5 files, personView.zul, personForm.zul, Person.java, PersonWnd.java and PersonFormWnd.java Run personView.zul, double click in any listitem and you'll see.

To make it work just remove the tag <?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit"?> from the personForm.zul.

BTW, while doing this, i saw that if you have and window with closable="true"
but with no title, to "X" button do not appear, is it right?

Here are the codes:

#############################################################
personView.zul
#############################################################

<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit"?>
<window xmlns="http://www.zkoss.org/2005/zul"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.zkoss.org/2005/zul
http://www.zkoss.org/2005/zul/zul.xsd"
xmlns:a="http://www.zkoss.org/2005/zk/annotation"
id="personWnd" use="PersonWnd" border="normal">

<groupbox mold="3d">
<listbox id="personList" model="@{personModel}"
selectedItem="@{personWnd.selected}">
<listhead sizable="true">
<listheader label="First Name"/>
<listheader label="Last Name"/>
</listhead>
<listitem self="@{each=person}"
forward="onDoubleClick=onPersonEdit">
<listcell label="@{person.firstName}" />
<listcell label="@{person.lastName}" />
</listitem>
</listbox>
</groupbox>
</window>

#############################################################
personForm.zul
#############################################################

<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit"?>
<window xmlns="http://www.zkoss.org/2005/zul"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.zkoss.org/2005/zul
http://www.zkoss.org/2005/zul/zul.xsd"
xmlns:a="http://www.zkoss.org/2005/zk/annotation"
use="PersonFormWnd" border="normal" mode="highlighted" width="400px"
closable="true" title="test">

<grid id="grdInput">
<rows>
<row>
Firstname:<textbox id="firstname" value="@{selected.firstName, save-when='btnSave.onClick'}" width="95%"/>
Lastname:<textbox id="lastname" value="@{selected.lastName, save-when='btnSave.onClick'}" width="95%" />
</row>
</rows>
</grid>

<div align="center">
<button id="btnSave" label="Save" forward="onBindingValidate=onSave"/>
</div>
</window>

#############################################################
Person.java
#############################################################

public class Person
{
private String firstName;
private String lastName;

public String getFirstName() {
return this.firstName;
}

public void setFirstName(String firstName) {
this.firstName = firstName;
}

public String getLastName() {
return this.lastName;
}

public void setLastName(String lastName) {
this.lastName = lastName;
}
}

#############################################################
PersonWnd.java
#############################################################

public class PersonWnd extends Window
{
public Person selected = new Person();

private Collection<Person> populatePerson()
{
ArrayList<Person> al = new ArrayList<Person>();
for(int i = 1; i < 10; i++)
{
Person person = new Person();
person.setFirstName("first name " + i);
person.setLastName("last name " + i);
al.add(person);
}
return al;
}

public void onCreate()
{
Listbox personList = (Listbox)this.getFellow("personList");
ListModelList lml = (ListModelList)personList.getModel();
lml.addAll(populatePerson());
}

public void onPersonEdit()
{
PersonFormWnd pfw = (PersonFormWnd) Executions.createComponents("/personForm.zul",
this, null);
pfw.setSelected(this.selected);
}
}

#############################################################
PersonFormWnd.java
#############################################################

public class PersonFormWnd extends Window {
private Person selected;

public void setSelected(Person person)
{
this.selected = person;
}

public Person getSelected()
{
return this.selected;
}
}

Thanks for the help,
/Madruga

link publish delete flag offensive edit

answered 2008-06-25 06:06:51 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=5052959

By: waterbottle

>>if you have and window with closable="true"
>>but with no title, to "X" button do not appear, is it right?
yes, close button only show up when window has non-empty title.

link publish delete flag offensive edit

answered 2008-06-27 03:21:21 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=5056980

By: waterbottle

Hi Madruga,
I think you are wrong using the databinder.
If there is no variable named "personModel", then there is nothing to bind.
don't modify the binding target object(listbox.getModel() in this case), modify the binding source object(personModel variable in this case)

I modify some code, just follow it.
public class PersonWnd extends Window implements AfterCompose {
public Person selected = new Person();

private Collection<Person> populatePerson()
{
ArrayList<Person> al = new ArrayList<Person>();
for(int i = 1; i < 10; i++)
{
Person person = new Person();
person.setFirstName("first name " + i);
person.setLastName("last name " + i);
al.add(person);
}
return al;
}

public void afterCompose(){
ListModelList lml = new ListModelList();
lml.addAll(populatePerson());
setVariable("personModel", lml,true);
}

public void onPersonEdit()
{
PersonFormWnd pfw = (PersonFormWnd)
Executions.createComponents("/06/personForm.zul",this, null);
pfw.setSelected(this.selected);
}
}

By the way, it is better to assign a target id for AnnotateDataBinderInit when use it nested.

A discuss talking about nested AnnotateDataBinderInit performance issue :
http://sourceforge.net/forum/forum.php?thread_id=2037091&forum_id=510208


/Dennis


link publish delete flag offensive edit

answered 2008-06-27 21:47:33 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=5058837

By: madruga0315

Hey Dennis,

Now everything works fine and faster!

Thank you very much!

/Madruga



link publish delete flag offensive edit

answered 2008-09-08 01:31:31 +0800

sandwichya gravatar image sandwichya
21

HI Dennis ,

I encounter this problem. I try the last code in this discuss. It still occurs "Page is already covered by another Data Binder. Cannot be covered by this Data Binder again. Page:z_39_0" in 3.5.0-FL-2008-08-29 version. It seems ok in 3.0.7. But after clicks the item of the listbox, it still has no any binding data in the modal window.

I can pass objects to the created window by the params<Map> and get them in the afterCompose() method. Is there any better way to passing objects to the createdComponent?? Like the code posted by Dennis.

public void onPersonEdit()
{
  PersonFormWnd pfw = (PersonFormWnd)
    Executions.createComponents("/06/personForm.zul",this, null);
  pfw.setSelected(this.selected);
}

Thank you very much!

/Sand

link publish delete flag offensive edit

answered 2008-09-08 01:31:57 +0800

sandwichya gravatar image sandwichya
21

updated 2008-09-08 04:00:16 +0800

HI Dennis ,

I think the questions I posted have some solutions.

By this link, the question "Page is already covered by another Data Binder. Cannot be covered by this Data Binder again. Page:z_39_0" has the solution. Now by specifying "arg0" in AnnotateDataBinderInit in the modal window page. Just specify arg0 to self window object.

personForm.zul:

<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" arg0="./personFormWnd"?>
<window xmlns="http://www.zkoss.org/2005/zul"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.zkoss.org/2005/zul
http://www.zkoss.org/2005/zul/zul.xsd"
xmlns:a="http://www.zkoss.org/2005/zk/annotation"
use="PersonFormWnd" border="normal" mode="highlighted" width="400px"
closable="true" title="test" id="personFormWnd">


personView.zul:

<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" arg0="./personWnd"?>


For my question2, passing objects to the create component, I use the auto-wire feature and update the value of the firstname/lastname textbox in the setSelected() method. It seems work now. But it seems missing the feature of data binder. And It is not work if uses binder.loadComponent(firstname) or binder.loadAll(). Do I miss this ?

import org.zkoss.zk.ui.Components;
import org.zkoss.zk.ui.ext.AfterCompose;
import org.zkoss.zkplus.databind.AnnotateDataBinder;
import org.zkoss.zul.Textbox;
import org.zkoss.zul.Window;

public class PersonFormWnd extends Window implements AfterCompose {
private Person selected;
private Textbox firstname;
private Textbox lastname;

public void afterCompose() {
// wire variables
Components.wireVariables(this, this);
// NO need to register onXxx event listeners
// auto forward
Components.addForwards(this, this);
}


public void setSelected(Person person) {
this.selected = person;
firstname.setValue(selected.getFirstName());
lastname.setValue(selected.getLastName());

}

public Person getSelected() {
return this.selected;
}
}

Thanks to all.

/Sand

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-06-22 08:23:02 +0800

Seen: 578 times

Last updated: Jun 27 '08

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