-
FEATURED COMPONENTS
First time here? Check out the FAQ!
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?
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
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 ! :/
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
[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
Asked: 2010-03-03 03:14:13 +0800
Seen: 417 times
Last updated: Mar 03 '10