0

Databinding / getting out a referenced object

asked 2010-03-03 03:14:13 +0800

arnodup gravatar image arnodup
15

Hi all,

I want to use the databinding but I have a problem and I don't find the way. Here is my code similar to an online example.

<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit"?>
<window border="normal" title="" id="win1"
style="border: 1px outset;background-color:white;padding:5px">

<zscript>
eu.akka.kplab.ws.monitoring.controller.WsInfoUpdateService svce=eu.akka.kplab.ws.monitoring.controller.WsInfoUpdateService.lookup();
List wsis = svce.getWebSites();
</zscript>

<caption label=""
style="border: 1px outset;background-color:white;padding:5px">

<image src="/images/KP-Lab-project-logoV2.bmp" align="left"></image>
</caption>

<listbox rows="4" model="@{wsis}" selectedItem="@{selected}">
<listhead>
<listheader label="Status" width="100px"/>
<listheader label="Url Name" width="100px"/>
<listheader label="Description" width="100px"/>
<listheader label="Action" width="100px"/>
</listhead>
<listitem self="@{each='wsi'}">
<listcell label="@{wsi.isAlive}"/>
<listcell label="@{wsi.url}"/>
<listcell label="@{wsi.description}"/>
<listcell>

<button label="Delete"
onClick="alert("I want to delete this object")"
tooltiptext="Click to delete this web service">
<custom-attributes wsiId="@{wsi.url}"/>
</button>


</listcell>
</listitem>
</listbox>
</zk></window>

A listbox is fulfilled with wsi objects and there is one wsi per row. What I want to do is to get out this wsi object when the user clicks on the delete button. How can I do?

Thanks for your help?

delete flag offensive retag edit

4 Replies

Sort by ยป oldest newest

answered 2010-03-03 07:34:23 +0800

robertpic71 gravatar image robertpic71
1275 1

Sine ZK 5.0 (databinding for custom-attributes) it should be easy:

1.) Check the onClick event
2.) getTarget = button
3.) button.getAttribute("wsiId") --> your object

Check this thread for a complete example.

/Robert

link publish delete flag offensive edit

answered 2010-03-03 09:38:04 +0800

arnodup gravatar image arnodup
15

Thank you Robert for your reply.
I read the thread and I don't understand where does come from the 'event' param in the onClick attribute :

<toolbarbutton onClick="someFunction(event)" label="@{person.fullName}">

However, I've modified the code as

<listbox rows="4" model="@{wsis}" selectedItem="@{selected}">Bold Text
<listhead>
<listheader label="Status" width="100px"/>
<listheader label="Url Name" width="100px"/>
<listheader label="Description" width="100px"/>
<listheader label="Action" width="100px"/>
</listhead>
<listitem self="@{each='wsi'}">
<listcell label="@{wsi.isAlive}"/>
<listcell label="@{wsi.url}"/>
<listcell label="@{wsi.description}"/>
<listcell>
<button label="Delete"
onClick="alert(self.getAttribute("wsiRef"))"
tooltiptext="Click to delete this web service">
<custom-attributes wsiRef="@{wsi}"/>
</button>

</listcell>
</listitem>
</listbox>

but I have the following error

Sourced file: inline evaluation of: `` alert(self.getAttribute("wsiRef"));'' : Attempt to resolve method: getAttribute() on undefined variable or class name: self : at Line: 35 : in file: inline evaluation of: `` alert(self.getAttribute("wsiRef"));'' : self .getAttribute ( "wsiRef" )

What a headhache ! :/

link publish delete flag offensive edit

answered 2010-03-03 11:08:01 +0800

robertpic71 gravatar image robertpic71
1275 1

updated 2010-03-03 11:12:36 +0800

I changed my example to self - and it works!

onClick="alert(self.getAttribute("value"))" (in your case wsi instead value)
[EDIT you have to quote the value & q u o t; - the forum doesn't show the quotes/]

However i do not work with self, because this is only a valid option for zscript (= interpreted java).

In my projects i always use the GenericForwardcomposer

zul-File:
<button id="deleteButton" label="Delete" tooltip... custom-attributes...

Java source

// autowired event
public void onClick$deleteButton(MouseEvent event) {
Wsis deleteThis = (Wsis) event.getTarget().getAttribute("wsi");
// delete f
}

BTW: i wonder about:
onClick="alert(self.getAttribute("wsiRef"))"
this is not xml-conform quotes insides quotes (i've got an error with this syntax)

/Robert

link publish delete flag offensive edit

answered 2010-03-03 11:41:55 +0800

robertpic71 gravatar image robertpic71
1275 1

updated 2010-03-03 11:43:55 +0800

[CORRECTION for the Java source]
// autowired event
public void onClick$deleteButton(MouseEvent event) {
Component comp = (Component) event.getTarget(); // use Component or Button
Wsis deleteThis = (Wsis) comp.getAttribute("wsi");
// delete the object
}


About your question:
>> I read the thread and I don't understand where does come from the 'event' param in the onClick attribute :

Like a Desktop-UI like Swing, every click and/or change (could) fire an event. You have to catch the event.
The event knows this source and target. Your listbox contains items and deletebutton's. You can get
the "clicked" button with event.getTarget(). This returns the Component (in your case button). Because
you have assigned a custom-attribute to each button you can get the corresponding object.

There are still other ways to catch events, but with databinding you have to use this way.

/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: 2010-03-03 03:14:13 +0800

Seen: 417 times

Last updated: Mar 03 '10

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