Branco
26 Nov 2008, 6:50 AM
Hi,
I have a DataList with several DataListItem in there. I would like to perform a certain action when I click on a DataListItem.
Problem is that I can only set a listener for the DataList of the type Events.SelectionChange and then on the listener do list.getSelectedItem().fireEvent(Events.Select, ce);
This way I "forward" the event to the corresponding DataListItem , which knows how to respond.
The problem here is the SelectionChange event. If I want to click 2, 3, 4 times in a row on the same DataListItem, it doesn't trigger! It's a SelectionChange. So I need to select ANOTHER DataListItem and then re-select the other in order for the listener to execute.
How can I do this?
If I set an OnClick event listener on DataList, no matter where I click, it triggers. This is no good. I need only to trigger when the user clicks ON the datalistitem, wether it is selected or not.
Here is a portion of the code:
Listener<ComponentEvent> listener = new Listener<ComponentEvent>() {
public void handleEvent(ComponentEvent ce) {
DataList list = (DataList) ce.component;
list.getSelectedItem().fireEvent(Events.Select, ce);
}
};
DataList list = new DataList();
list.setSelectionMode(SelectionMode.SINGLE);
list.addListener(Events.SelectionChange, listener);
SelectionListener otherListener = new SelectionListener<ComponentEvent>() {
public void componentSelected(ComponentEvent ce) {
MyForm form = new MyForm();
form.show();
}
};
DataListItem subItem = new DataListItem(label);
subItem.addSelectionListener(otherListener);
list.add(subItem);
I have a DataList with several DataListItem in there. I would like to perform a certain action when I click on a DataListItem.
Problem is that I can only set a listener for the DataList of the type Events.SelectionChange and then on the listener do list.getSelectedItem().fireEvent(Events.Select, ce);
This way I "forward" the event to the corresponding DataListItem , which knows how to respond.
The problem here is the SelectionChange event. If I want to click 2, 3, 4 times in a row on the same DataListItem, it doesn't trigger! It's a SelectionChange. So I need to select ANOTHER DataListItem and then re-select the other in order for the listener to execute.
How can I do this?
If I set an OnClick event listener on DataList, no matter where I click, it triggers. This is no good. I need only to trigger when the user clicks ON the datalistitem, wether it is selected or not.
Here is a portion of the code:
Listener<ComponentEvent> listener = new Listener<ComponentEvent>() {
public void handleEvent(ComponentEvent ce) {
DataList list = (DataList) ce.component;
list.getSelectedItem().fireEvent(Events.Select, ce);
}
};
DataList list = new DataList();
list.setSelectionMode(SelectionMode.SINGLE);
list.addListener(Events.SelectionChange, listener);
SelectionListener otherListener = new SelectionListener<ComponentEvent>() {
public void componentSelected(ComponentEvent ce) {
MyForm form = new MyForm();
form.show();
}
};
DataListItem subItem = new DataListItem(label);
subItem.addSelectionListener(otherListener);
list.add(subItem);