0

How to pass a grid row ID via forward event?

asked 2009-05-12 07:10:08 +0800

davout gravatar image davout
1435 3 18

I'm trying to work out how to pass a unique row ID via a forward event mapping, like...

<grid id="qualificationsGrid" width="100%" mold="paging"
	pageSize="10" model="@{summaryWin$ExpertSummaryComposer.qualificationsModel}">
	<columns sizable="true" menupopup="auto">
		<column label="Type" width="10%" />
		<column label="Title" width="40%" />
		<column label="Grade" width="10%" />
		<column label="Awarded" width="10%" align="center" />
		<column label="Provider" width="30%" />
	</columns>
	<rows>
	   <row self="@{each=qualification}">
	      <label value="@{qualification.type}"/>
	      <toolbarbutton label="@{qualification.title}" 
	                     forward="onQualificationTitleClick(@{qualification.ID})">
	      </toolbarbutton>               
	      <label value="@{qualification.grade}"/>
	      <label value="@{qualification.awarded}"/>
	      <label value="@{qualification.provider}"/>
	   </row>
	</rows>
</grid>



I'm trying to pass back 'qualification.ID' in some way. I've tried a variety of options and none of which work. I've looked at using attributes under the toolbarbutton, but can't find a way of setting the '@{qualification.ID}' value into an attribute.

Any ideas?

delete flag offensive retag edit

3 Replies

Sort by ยป oldest newest

answered 2009-05-12 08:11:55 +0800

davout gravatar image davout
1435 3 18

I have a work around. I eventually found a way of setting the 'qualification.ID' into the row value and then accessing the row as a parent of the toolbar button, like...

See the 'value' setting at the <row> tag level...

	<grid id="qualificationsGrid" width="100%" mold="paging"
		pageSize="10"
		model="@{summaryWin$ExpertSummaryComposer.qualificationsModel}">
		<columns sizable="true" menupopup="auto">
			<column label="Type" width="10%" />
			<column label="Title" width="40%" />
			<column label="Grade" width="10%" />
			<column label="Awarded" width="10%" align="center" />
			<column label="Provider" width="30%" />
		</columns>
		<rows>
			<row self="@{each=qualification}" value="@{qualification.ID}">
				<label value="@{qualification.type}" />
				<toolbarbutton label="@{qualification.title}"
					forward="onQualificationTitleClick()">
					<custom-attributes qualificationid="@{qualification.ID}"/>
					<variables simple="qualificationid=@{qualification.ID}"/>
				</toolbarbutton>
				<label value="@{qualification.grade}" />
				<label value="@{qualification.awarded}" />
				<label value="@{qualification.provider}" />
			</row>
		</rows>
	</grid>



This allows my event handler to access the row value...
   public void onQualificationTitleClick(ForwardEvent anEvent) {
      int q = ((Integer) ((Row) anEvent.getOrigin().getTarget().getParent()).getValue()).intValue();
      KnowledgeNavigator.ShowExpertQualificationDefDisplay(KnowledgeNavigator.getCurrentExpertID(),q,true);
   }


Still, I think the lack of support for data binding in <custom-attributes> and <variables> and as event parameters is a serious weakness.

link publish delete flag offensive edit

answered 2009-05-12 08:14:20 +0800

robertpic71 gravatar image robertpic71
1275 1

updated 2009-05-12 08:15:41 +0800

Edit: i was a little bit to slow...

You have to retrieve the UI-Element from the event.

Here is my generic code to handle this:

public Object getBindingData(ForwardEvent event) {
	Component target = event.getOrigin().getTarget();
	try {
	    while(!(target instanceof Row || target instanceof Listitem)) {
		target = target.getParent(); 
	    };
	    Map map = (Map) target.getAttribute("zkplus.databind.TEMPLATEMAP");
	    return map.get(target.getAttribute("zkplus.databind.VARNAME"));
	} catch (NullPointerException e) {
	    return null;
	}
    }

Attention! Create any utilclass for this peace of code, because the map could be change in the new databinder.
If there a new databinder i post the new utilcode (i need that for my applications).

Here is the code in action:

public void onClick$quatitle(ForwardEvent event) {
   Qualification qu = (Qualification) getBindingData(event);
   // do what you want with the clicked Qualification
}

A non-generic way (but w/o go deep inside the bindingcode) to solve this issue is:

<row self="@{each=qualification}" value="@{qualifaction}">

and replace the

Map map = (Map) target.getAttribute("zkplus.databind.TEMPLATEMAP");
return map.get(target.getAttribute("zkplus.databind.VARNAME"));

with return target.getValue();

However, i like that. I do 99% of my work with beans and not with UI-Elements. I.e. this

/Robert

link publish delete flag offensive edit

answered 2009-09-01 09:26:28 +0800

spike gravatar image spike
30

I am new to ZK so if it's a horrible solution let me know.

in the GUI part I passed the desired variable to the function.
<row forEach="${items.listItems}" self="@{each}" id="${each.aid}" forward="onClick=onClickRow(${each.aid})" action="onclick:if(zkau.insamepos(event)) onSelect(this)">

in the java the data parameter hold the row ID

public void onClickRow(Event event){
Object obj = event.getData();
}

Eyal

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: 2009-05-12 07:10:08 +0800

Seen: 1,413 times

Last updated: Sep 01 '09

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