-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hello everyone,
I'm trying to display a list of data, and each listitem has a listcell with a toolbarbutton inside to be clicked and the form for that item is opened.
So what I'm looking for something like this
<listhead> <listheader label="Name"/> </listhead> <listitem self="@{each=contact}" value="@{contact}"> <listcell label="@{contact.name}"/> <listcell > <toolbarbutton image="/images/skin/database_edit.png" forward="onClick=onClickImgEdit(${contact})" /> </listcell> </listitem>
The contact data is showed correctly, but the data from the ForwardEvent is null. I also trying passing the listitem, to get the value from listitem.getValue(), but the value is also null.
Am I doing something wrong? Or this is a feature request?
Thank you,
Regards
Var 1.)
Any action on the listbox select the item. You can fetch the selected contact.
Contact selected; // in your javacode <listbox model="@{contacts}" selectedItem="@{selected}">
In you onClickImgEdit you could work with the selected contact.
Var 2.)
Retrieve the targetComponent from the event and retrieve the parant until you have the listitem - there you could retrieve the value.
I think EL's inside forward in not support or done in renderingphase.
/Robert
I have to check my code an post variante 3 soon.
I agree with Robert.
However, instead of the variant 2 (where you have to loop through the parents until you get the Listitem object), I prefer
to set the data as an attribute of the button ( toolbarbutton.setAttribute("AttributeName", VALUE) ).
So, my third variant would be:
Var 3.)
1. Retrieve the source event from the forward event (getOrigin).
2. Retrieve the event source Component (the toolbar button) from the source event (getTarget)
3. Retrieve the attribute value from the Component object (getAttribute("AttributeName")).
4. Do what you want with the value (in your case, the value will be 'contact').
>> I have to check my code an post variante 3 soon.
Now it's variante 4: Here is my utilcode for the "loop". I use the binding template for a generic way to retrieve the model.
This should work with Grids(list) and Listbox. No extra attributes are required. I used this for my grid's, because there is
no selectitem like the listbox.
public Object getBindingData(ForwardEvent event) { Component target = event.getOrigin().getTarget(); try { while(!(target instanceof Row || target instanceof Listitem)) { target = target.getParent(); }; Map map = (Map) target.getAttribute("zkplus.databind.TEMPLATEMAP"); return map.get(target.getAttribute("zkplus.databind.VARNAME")); } catch (NullPointerException e) { return null; } }
Example:
public void onClick$trash(ForwardEvent event) { KundenUmsetzung ku = (KundenUmsetzung) getBindingData(event); guiModel.remove(ku); // delete gui-entry kundenTabelle.delete(ku); // delete model/xml-entry }
In your case:
Contact contact = (Contact) getBindingData(event);
/Robert
Hey guys, thanks for the quick response.
So now I tested option 1, 2 and 3
1) The onClick event is sent first to Image, and then to listcell, so in my event handler the selectItem has not been setted yet.
3) I guess that this should work fine if did in java, however In zul it did not, I guess that is the same reason of rendering phase pointed by robert, here are some of my attempts
<listcell> <image src="/images/skin/database_edit.png" forward="onClick=onClickImgEdit(${self})" > <custom-attributes contact1="${self.parent.parent.value}" <!-- attribute contact1 does not exist --> contact2="test1" <!-- "test1" --> contact3="@{contact}" <!-- "@{contact1}" --> /> </listcell>
2) It worked - forwardEvent.getOrigin().getTarget().getParent().getParent()
but if I pass the Image object in the forward data, don't work (i can get to the listitem object, but the value of listitem is null) - forwardEvent.getData().getParent().getParent()
Thank you guys for the help!
Madruga
>> forwardEvent.getData().getParent().getParent()
? getData
I have only testet with Gridbox, but i could retrieve the data (from the row) for the imageevent.
/Robert
Asked: 2008-11-19 23:44:19 +0800
Seen: 1,349 times
Last updated: Nov 20 '08