0

How to get the right target comp?

asked 2011-11-29 09:11:47 +0800

chw gravatar image chw
24 1

Hello everybody out there,

I have a problem getting the right target component when catching the onClick event.
My page is composed of a listbox (see below).

	
<zul:div id="taskBoardViewFragment" class="section" 
		self="@{define(content) fragment(taskBoardViewFragment)}">

		<zul:borderlayout height="420px">
			<zul:north maxsize="200" size="100%" splittable="true" autoscroll="true" >

				<zul:listbox id="storyList" height="400px" multiple="true" apply="${taskBoardCtrl}">
        			
			        <zul:listhead>       
			            <zul:listheader hflex="1" label="stories" />
			            <zul:listheader hflex="1" label="not started" />
			            <zul:listheader hflex="1" label="in progress" />
			            <zul:listheader hflex="1" label="done" />     
			        </zul:listhead>      
				</zul:listbox>

			</zul:north>
		</zul:borderlayout>
	</zul:div>

The glued composer is catching the onClick event and sets the model and the ItemRenderer.

	@Override
    public void doAfterCompose(Component comp) throws Exception {
        super.doAfterCompose(comp);
         
        //create model
        storyList.setModel(new ListModelList(storyService.getAllStories()));
 
        //create renderer
        storyList.setItemRenderer(new StoryListRenderer());
    }

The listitems are composd in a ListItenRenderer (see below). The listitems has
panel components as children.

public class StoryListRenderer implements ListitemRenderer {

	@Override
	public void render(Listitem item, Object data) throws Exception {
		// Das Panel für die Story zusammenbauen
		Story story = (Story) data;

		Panel storyPanel = new Panel();
		storyPanel.setTitle(story.getTitel());

		Panelchildren storyPanelChild = new Panelchildren();
		storyPanel.appendChild(storyPanelChild);

		Textbox storyTxtbox = new Textbox(story.getDescription());
		storyTxtbox.setWidth("100%");
		storyTxtbox.setMultiline(true);

		storyPanelChild.appendChild(storyTxtbox);

		Listcell lc = new Listcell();
		lc.appendChild(storyPanel);

		item.appendChild(lc);

		// Die zugehörigen Aufgaben im Status "not started" ermitteln
		Set<Task> tasks = story.getTasks();
		Iterator<Task> it = tasks.iterator();

		Vbox vboxNotStartedTasks = new Vbox();
		Vbox vboxInProgressTasks = new Vbox();
		Vbox vboxDoneTasks = new Vbox();

		while (it.hasNext()) {
			Task task = it.next();

			Textbox taskTxtbox = new Textbox(task.getDescription());
			taskTxtbox.setWidth("100%");
			taskTxtbox.setMultiline(true);
			
			Panelchildren taskPanelChild = new Panelchildren();
			taskPanelChild.appendChild(taskTxtbox);
			
			Panel taskPanel = new Panel();
			taskPanel.setTitle(task.getTitel());
			taskPanel.appendChild(taskPanelChild);
			taskPanel.setDraggable("true");
			taskPanel.setId(Long.valueOf(task.getId()).toString());
			
			if (task.getStatus().equals("not started")) {
				vboxNotStartedTasks.appendChild(taskPanel);
			} else if(task.getStatus().equals("in progress")) {
				vboxInProgressTasks.appendChild(taskPanel);
			} else if(task.getStatus().equals("done")) {
				vboxDoneTasks.appendChild(taskPanel);
			}
		}

		Listcell lstcellNotStartedTasks = new Listcell();
		lstcellNotStartedTasks.appendChild(vboxNotStartedTasks);
		item.appendChild(lstcellNotStartedTasks);
		
		Listcell lstcellInProgressTasks = new Listcell();
		lstcellInProgressTasks.appendChild(vboxInProgressTasks);
		item.appendChild(lstcellInProgressTasks);
		
		Listcell lstcellDoneTasks = new Listcell();
		lstcellDoneTasks.appendChild(vboxDoneTasks);
		item.appendChild(lstcellDoneTasks);
	}

Now the question:

If I click a panel in the listbox I like to get the panel if I call event.getTarget() in the onClick method.
Unfortunatelly I get the listbox itself. Any suggestions?

Thanks in advanced. Christian

delete flag offensive retag edit

2 Replies

Sort by » oldest newest

answered 2011-11-30 14:32:04 +0800

zippy gravatar image zippy
504 1 2

You need to add eventlistener in a panel

By default listbox catch the onClick


Panel storyPanel = new Panel();
storyPanel.addEventListener("onClick", new EventListenerBLAH...)

link publish delete flag offensive edit

answered 2011-11-30 14:43:45 +0800

chw gravatar image chw
24 1

ok, many thanks. It works!
I thought an event will be propagated up the component tree.
Greets Christian

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: 2011-11-29 09:11:47 +0800

Seen: 144 times

Last updated: Nov 30 '11

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