0

ZK6. How to get a component was clicked?

asked 2011-12-21 10:16:58 +0800

ctapobep gravatar image ctapobep
163 2

updated 2011-12-21 10:17:38 +0800

There is a button whith

onClick="@command('blah')"
How can I get the reference to the component of that button in the command method? There is no way I can know the ID of the component, so looking for ways to get that component from Execution or some place like this.. Or maybe it's possible to get access to the event? It should contain the ID of the clicked button I think..

delete flag offensive retag edit

7 Replies

Sort by ยป oldest newest

answered 2011-12-22 08:46:01 +0800

ctapobep gravatar image ctapobep
163 2

updated 2011-12-22 08:46:29 +0800

As for now I found this solution:

onClick="@command('showGroupsDialog', params=self.getId())"
And respective Java:
    @Command
    public void showGroupsDialog(@BindingParam("params") String params)

link publish delete flag offensive edit

answered 2011-12-22 10:07:11 +0800

Matze2 gravatar image Matze2
773 7

If you work with template (e.g. with grid around), then you can maybe also pass the template variable via params.
Just as an idea.

link publish delete flag offensive edit

answered 2011-12-22 10:38:20 +0800

ctapobep gravatar image ctapobep
163 2

updated 2011-12-22 10:38:39 +0800

You can't, if you recall the other topic I created, you can't use EL inside @command. That's why first I assign EL expression to the ID, and then pass self.getId() to the @command. This is the only workaround I've found.

link publish delete flag offensive edit

answered 2011-12-22 12:17:23 +0800

Matze2 gravatar image Matze2
773 7

Yes, but there you talked about "$" EL. I have "@" EL in mind.
But I have no time to try that. Maybe on weekend.

link publish delete flag offensive edit

answered 2012-01-04 02:17:31 +0800

Matze2 gravatar image Matze2
773 7

A little bit later than I thought, but I was successful using the following construct:

<listbox ...>
		<listhead sizable="true">
...
		</listhead>
		<template name="model" var="sec">
		<listitem>
			<listcell>
				<checkbox checked="@load(sec.active)"
					onCheck="@command('toggleActive', sec=sec)"/>
			</listcell>
...

The corresponding method signature looks like this:
	@Command
	public void toggleActive(@BindingParam("sec") Sec sec) {

link publish delete flag offensive edit

answered 2012-01-04 06:15:23 +0800

ctapobep gravatar image ctapobep
163 2

And what Sec (and sec) is?

link publish delete flag offensive edit

answered 2012-01-04 07:33:10 +0800

Matze2 gravatar image Matze2
773 7

The listbox model is a List<Sec>. It's the object that represents a row.
In this example, the object has an "active" property which can be enabled/disabled using a checkbox in the first column.
To operate on the correct object the toggleActive command needs the correct Sec object.

The central part is the "sec=sec" parameter in the @command definition. Left hand is the binding parameter, right hand is a ZK bind expression and is evaluated to the underlying business object.

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-12-21 10:16:58 +0800

Seen: 298 times

Last updated: Jan 04 '12

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