Etc Id Generator"

From Documentation
(Created page with "=zk.xml Setting= <source lang="xml"> <system-config> <id-generator-class>foo.jmtest.SequenceIdGenerator</id-generator-class> </system-config> </source> =SequenceIdGenerator=...")
 
Line 119: Line 119:
  
 
public String nextDesktopId(Desktop desktop) {
 
public String nextDesktopId(Desktop desktop) {
if (desktop.getAttribute("Id_Num") == null) {
 
String number = "0";
 
desktop.setAttribute("Id_Num", number);
 
}
 
 
return null;
 
return null;
 
}
 
}

Revision as of 07:31, 30 November 2012

zk.xml Setting

<system-config>
    <id-generator-class>foo.jmtest.SequenceIdGenerator</id-generator-class>
</system-config>

SequenceIdGenerator

For Jmeter stree test: Execute a Loading or Performance Test on ZK using JMeter

import javax.servlet.http.HttpServletRequest;

import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Desktop;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.Page;
import org.zkoss.zk.ui.sys.IdGenerator;
import org.zkoss.zk.ui.metainfo.ComponentInfo;

public class SequenceIdGenerator implements IdGenerator{
	public String nextComponentUuid(Desktop desktop, Component comp) {
		String number;
		if ((number = (String)desktop.getAttribute("Id_Num")) == null) {
			number = "0";
			desktop.setAttribute("Id_Num", number);
		}
		int i = Integer.parseInt(number);
		i++;// Start from 1
		desktop.setAttribute("Id_Num", String.valueOf(i));
		return "t_" + i;
	}
	
	public String nextComponentUuid(Desktop desktop, Component comp,
			ComponentInfo info) {
		return nextComponentUuid(desktop, comp);
	}
 
	public String nextDesktopId(Desktop desktop) {
		HttpServletRequest req = (HttpServletRequest)Executions.getCurrent().getNativeRequest();
		String dtid = req.getParameter("tdtid");
		if(dtid!=null){
			System.out.println(" use client dtid "+dtid + "\turl: " + req.getParameter("pageURL"));
			
		}
		return dtid==null?null:dtid;
	}

	public String nextPageUuid(Page page) {
		return null;
	}
}


SimpleIdGenerator

import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Desktop;
import org.zkoss.zk.ui.Page;
import org.zkoss.zk.ui.metainfo.ComponentInfo;
import org.zkoss.zk.ui.sys.IdGenerator;

public class SimpleIdGenerator implements IdGenerator {

	private static final String PREFIX = "zk_comp_";

	public String nextComponentUuid(Desktop desktop, Component comp) {
		int i = Integer.parseInt(desktop.getAttribute("Id_Num").toString());
		i++;// Start from 1
		desktop.setAttribute("Id_Num", String.valueOf(i));
		return PREFIX + i;
	}
	
	public String nextComponentUuid(Desktop desktop, Component comp,
			ComponentInfo info) {
		return nextComponentUuid(desktop, comp);
	}

	public String nextDesktopId(Desktop desktop) {
		if (desktop.getAttribute("Id_Num") == null) {
			String number = "0";
			desktop.setAttribute("Id_Num", number);
		}
		return null;
	}

	public String nextPageUuid(Page page) {
		return null;
	}
}

IdAsUuidGenerator

import java.util.Iterator;

import org.zkoss.lang.Strings;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Desktop;
import org.zkoss.zk.ui.Page;
import org.zkoss.zk.ui.metainfo.Property;
import org.zkoss.zk.ui.sys.IdGenerator;

public class IdAsUuidGenerator implements IdGenerator {

	public String nextComponentUuid(Desktop desktop, Component comp,
			ComponentInfo compInfo) {
		
		for (Iterator it = compInfo.getProperties().iterator(); it.hasNext();) {
			Property p = (Property) it.next();
			if ("id".equals(p.getName())) {
				return p.getRawValue();
			}
		}
		return null;
	}

	public String nextDesktopId(Desktop desktop) {
		return null;
	}

	public String nextPageUuid(Page page) {
		return null;
	}

}

==