0

List Item Double click event on selected Item MVVM

asked 2012-11-09 04:09:52 +0800

longdv1208 gravatar image longdv1208
98 4

when double click row do not run method onDoubleClicked

<?page title="Sec Right Name" contentType="text/html;charset=UTF-8"?>
<?taglib uri="http://www.zkoss.org/dsp/web/core" prefix="c"?>
<zk>
	<window border="none" apply="org.zkoss.bind.BindComposer"
		viewModel="@id('vm') @init('com.evnit.fmis.identitymanager.viewmodel.RightViewModel')">
		<listbox id="secRightList" height="500px" vflex="true" hflex="1"
			model="@bind(vm.rightList)" emptyMessage="Nothing in Right."
			mold="paging" pageSize="23" selectedItem="@bind(vm.rightSelected)">
			<listhead menupopup="auto" sizable="true">
				<listheader id="listheader_SecRightList_rigName"
					image="/images/icons/create_doc.gif"
					label="${c:l('listheader_SecRightList_rigName.label')}" width="70%"
					sort="auto(rigName)">
				</listheader>
				<listheader id="listheader_SecRightList_rigType"
					image="/images/icons/exdDataPerspective.gif" width="30%"
					label="${c:l('listheader_SecRightList_rigType.label')}"
					sort="auto(rigType)">
				</listheader>
			</listhead>

			<!--  <template name="model">
				<listitem onDoubleClick="@command('onDoubleClicked')">
				<listcell label="@bind(each.rigName)" />
				</listitem>
				</template>
				<template name="model">
				<row>
				<label value="@load(each.rigName)" />
				<label value="@load(each.rigType)" />
				</row>
				</template>
			-->
		</listbox>
	</window>
</zk>

package com.evnit.fmis.identitymanager.viewmodel;

import java.util.List;

import org.zkoss.bind.annotation.AfterCompose;
import org.zkoss.bind.annotation.ContextParam;
import org.zkoss.bind.annotation.ContextType;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.select.Selectors;
import org.zkoss.zk.ui.select.annotation.Wire;
import org.zkoss.zk.ui.select.annotation.WireVariable;
import org.zkoss.zk.ui.sys.ComponentsCtrl;
import org.zkoss.zul.Listbox;
import org.zkoss.zul.Listcell;
import org.zkoss.zul.Listitem;
import org.zkoss.zul.ListitemRenderer;
import org.zkoss.zul.Messagebox;

import de.forsthaus.backend.model.SecRight;
import de.forsthaus.backend.model.SecTyp;
import de.forsthaus.backend.service.SecurityService;

public class RightViewModel {

	@WireVariable
	private SecurityService securityService;
	@Wire("#secRightList")
	private Listbox secRightList;

	private List<SecRight> rightList = null;
	private SecRight rightSelected;

	/**
	 * @Init public void init(@ContextParam(ContextType.VIEW) Component view) {
	 *       Selectors.wireComponents(view, this, false);
	 *       secRightList.setItemRenderer(new ListitemRenderer<SecRight>() {
	 * @Override public void render(Listitem item, SecRight data, int index)
	 *           throws Exception { item.appendChild(new
	 *           Listcell(data.getRigName())); SecTyp typ =
	 *           getSecurityService().getTypById( data.getRigType().intValue());
	 *           item.appendChild(new Listcell(typ.getStpTypname()));
	 *           item.setAttribute("secRight", data);
	 *           ComponentsCtrl.applyForward(item,
	 *           "onDoubleClick=onDoubleClicked"); } }); }
	 */

	@AfterCompose
	public void afterCompose(@ContextParam(ContextType.VIEW) Component view) {
		Selectors.wireComponents(view, this, false);
		secRightList.setItemRenderer(new ListitemRenderer<SecRight>() {
			@Override
			public void render(Listitem item, SecRight data, int index)
					throws Exception {
				item.appendChild(new Listcell(data.getRigName()));
				SecTyp typ = getSecurityService().getTypById(
						data.getRigType().intValue());
				item.appendChild(new Listcell(typ.getStpTypname()));
				item.setAttribute("data", data);
				ComponentsCtrl.applyForward(item,
						"onDoubleClick=onDoubleClicked");
			}
		});
		/**
		 * Apply Grid secRightGrid.setRowRenderer(new RowRenderer<SecRight>() {
		 * 
		 * @Override public void render(Row row, SecRight secRight, int arg2)
		 *           throws Exception { row.appendChild(new
		 *           Label(secRight.getRigName())); SecTyp typ =
		 *           getSecurityService().getTypById(
		 *           secRight.getRigType().intValue()); row.appendChild(new
		 *           Label(typ.getStpTypname())); } });
		 */
	}

	public void onDoubleClicked(Event event) throws Exception {
		Listitem item = secRightList.getSelectedItem();
		SecRight secRight = (SecRight) item.getAttribute("secRight");
		System.out.println(secRight.getRigName());
		Messagebox.show(secRight.getRigName());
	}

	public SecurityService getSecurityService() {
		return securityService;
	}

	public void setSecurityService(SecurityService securityService) {
		this.securityService = securityService;
	}

	public List<SecRight> getRightList() {
		rightList = securityService.getAllRights();
		rightList.size();
		return rightList;
	}

	public void setRightList(List<SecRight> rightList) {
		this.rightList = rightList;
	}

	public SecRight getRightSelected() {
		return rightSelected;
	}

	public void setRightSelected(SecRight rightSelected) {
		this.rightSelected = rightSelected;
	}
}

delete flag offensive retag edit

3 Replies

Sort by ยป oldest newest

answered 2012-11-09 06:12:29 +0800

Senthilchettyin gravatar image Senthilchettyin flag of India
2611 3 8
http://emrpms.blogspot.in...

Check here

link publish delete flag offensive edit

answered 2012-11-09 06:17:27 +0800

longdv1208 gravatar image longdv1208
98 4

I want Override render

@Override
public void render(Listitem item, SecRight data, int index)
throws Exception {
item.appendChild(new Listcell(data.getRigName()));
SecTyp typ = getSecurityService().getTypById(
data.getRigType().intValue());
item.appendChild(new Listcell(typ.getStpTypname()));
item.setAttribute("data", data);
ComponentsCtrl.applyForward(item,
"onDoubleClick=onDoubleClicked");
}

link publish delete flag offensive edit

answered 2012-11-14 09:12:22 +0800

ashishd gravatar image ashishd flag of Taiwan
1972 6

Hi longdv1208,
You can not mix @Command with applyForward() API ... for MVVM pattern annotate your onDoubleClicked() method with @Command as shown by example linked by Senthilchettyin

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: 2012-11-09 04:09:52 +0800

Seen: 213 times

Last updated: Nov 14 '12

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