0

Bloody newby needs a lttle piece of help regarding Eventhandling and buttons

asked 2010-06-19 04:56:39 +0800

parascus gravatar image parascus
93

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>

delete flag offensive retag edit

4 Replies

Sort by ยป oldest newest

answered 2010-06-19 05:22:31 +0800

Arsen gravatar image Arsen
383 4

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.

link publish delete flag offensive edit

answered 2010-06-19 06:56:52 +0800

parascus gravatar image parascus
93

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

link publish delete flag offensive edit

answered 2010-06-19 18:12:08 +0800

vinhvo gravatar image vinhvo
369 3

Found it. Wrong import : import groovyjarjarantlr.debug.Event --> import org.zkoss.zk.ui.event.Event;
Cheer !!!

link publish delete flag offensive edit

answered 2010-06-20 03:02:23 +0800

parascus gravatar image parascus
93

YEEAHH!!!

One of those easy, simple, ridiculous mistakes where starring at the code doesn't have any effect ... as long as you can't read. ;-)

Thanks a lot, vinhvo!!!

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-06-19 04:56:39 +0800

Seen: 199 times

Last updated: Jun 20 '10

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