-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi community,
I tried to implement the ToDo demo but don't get things done. I think the main code snippets are the controller and the zul file which I have attached below.
Can anybody of you tell me how the demo can be make running?
TIA
Stephan
// Controller -------------------------------------------------------------
package events;
import java.util.List;
import java.util.UUID;
import org.zkoss.zk.ui.util.GenericForwardComposer;
import org.zkoss.zul.Button;
import org.zkoss.zul.Listbox;
import groovyjarjarantlr.debug.Event;
public class EventController extends GenericForwardComposer {
private static final long serialVersionUID = 1L;
private Button btn_add;
private Button btn_update;
private Button btn_delete;
private Listbox listbox_events;
private EventDAO evtdao = new EventDAO();
public List<ToDoEvent> getAllEvents() {
return evtdao.findAll();
}
public void onClick$btn_add(Event event) {
// insert into database
ToDoEvent newEvt = new ToDoEvent(UUID.randomUUID().toString(), current
.getName(), current.getPriority(), current.getDate());
evtdao.insert(newEvt);
}
public void onClick$btn_update(Event event) {
if (listbox_events.getSelectedItem() != null) {
// update database
evtdao.update((ToDoEvent) listbox_events.getSelectedItem().getValue());
}
}
public void onClick$btn_delete(Event event) {
if (listbox_events.getSelectedItem() != null) {
evtdao.delete((ToDoEvent) listbox_events.getSelectedItem().getValue());
}
}
ToDoEvent current = new ToDoEvent();
public ToDoEvent getCurrent() {
return current;
}
public void setCurrent(ToDoEvent current) {
this.current = current;
}
}
// ZUL -------------------------------------------------------------
<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit"?>
<window id="win" title="To do list" width="640px" border="normal"
apply="events.EventController">
<listbox id="listbox_events" multiple="true" rows="5"
model="@{win$composer.allEvents}" selectedItem="@{win$composer.current}">
<listhead>
<listheader label="Item" />
<listheader label="Priority" width="50px" />
<listheader label="Date" width="90px" />
</listhead>
<listitem self="@{each='event'}" value="@{event}">
<listcell label="@{event.name}" />
<listcell label="@{event.priority}" />
<listcell label="@{event.date}" />
</listitem>
</listbox>
<groupbox>
<caption label="Event" />
Item:
<textbox id="name" cols="25"
value="@{win$composer.current.name}" />
Priority:
<intbox id="priority" cols="1"
value="@{win$composer.current.priority}" />
Date:
<datebox id="date" cols="8"
value="@{win$composer.current.date}" />
<button id="add" label="Add" width="36px" height="24px" />
<button id="update" label="Update" width="46px" height="24px" />
<button id="delete" label="Delete" width="46px" height="24px" />
</groupbox>
</window>
It seems your problem is here
zul button id="add" java private Button btn_add; public void onClick$btn_add
if buttons id is "add" then composer's class member should be private Button add but not private Button btn_add The same thing is with method name.
By the way, you don't need to register class member private Button add if you are not planning to change it's properties - method public void onClick$add() is enough to register event listener.
Hope this helps you.
Thanks for your hint Arsen, but it still doesn't work. I changed the zul file as follows:
<button id="btn_add" label="Add" width="36px" height="24px" />
<button id="btn_update" label="Update" width="46px" height="24px" />
<button id="btn_delete" label="Delete" width="46px" height="24px" />
But the button shows no reaction. Debugging Java (using breakpoints) shows that the onClick$XXX-methods are not triggered. It seems that I missed some parameter or things like that which are essential but also trivial. Might have anyone have further suggestions?
Parascus
Asked: 2010-06-19 04:56:39 +0800
Seen: 199 times
Last updated: Jun 20 '10