0

The component ID in the zul file is not the same when i inspect my page with firebug

asked 2012-01-12 10:35:57 +0800

soulama gravatar image soulama
45

Hi,

I try to test a ZK Project with pureTest, and i need to know the IDs for my components before i start the testing process, because pureTest need it.
So, is it possible to define the same ID( in the zul file ) as the UUID generated form ZK, and how can I do that?

Thank you in advance.

Soulama

delete flag offensive retag edit

9 Replies

Sort by ยป oldest newest

answered 2012-01-13 04:29:18 +0800

TonyQ gravatar image TonyQ
642
https://www.masterbranch....

There's some way to do this
1.You could implements your own ID generator to generate same UUID as Id .
Reference to the document
http://books.zkoss.org/wiki/ZK_Configuration_Reference/zk.xml/The_system-config_Element/The_id-generator-class_Element

2.Extends existing component with RawId interface.

Steps :
1.write your own java class to extend the existing component and implements RawId interface.
2.use lang-addon.xml to re-define the tag, or simply use "use" attribute in the zul..

-----------

It's not recommended to do this,
because in web's rule , a ID could only be used once in one page ,
if you have two component used same uuid , it will throw Exception and cause issue in both ZK system and web page.

Let me know if you need further assistance.

link publish delete flag offensive edit

answered 2012-01-13 06:51:23 +0800

Maurus gravatar image Maurus
24

Lets assume I can create a ZK application with static ids in the way that no two ids are the same.

Will this application work in a strict single user use?
Will this application work in a multi user use?

In the multi user use all ids will be the same for user1 and user2.
In case the application will work in a multi user use, why generates ZK random ids in its default configuration?

link publish delete flag offensive edit

answered 2012-01-17 04:38:08 +0800

TonyQ gravatar image TonyQ
642
https://www.masterbranch....

updated 2012-01-17 04:38:45 +0800

Or I should explain it more clearly ,
the "a ID could only be used once in one page" means "One UUID (NOT ID) could only be used once per desktop" ,

A desktop is created when a user browsering a zul url ,and it doesn't matter if you have duplicated UUID in different desktop.

So if user go to another desktop(redirect to another url) or another user is accessing the page,
the UUID is in different desktop , there's no issue .


About the reason for why generating a uuid , here's some reason .

1.Because ZK have to do some operation (remove / add ...etc) to our dom element FOR EACH COMPONENT you attach/remove in zul file or java code,
ZK have to have a unique ID to do this , or ZK will get wrong widget/dom element.

And it's hard to find the specific component in server side when system have to do some AU operation by UUID ,
all the ajax (in ZK,so-called AU ) will use UUID to communicate with server side.

So that's the reason for why UUID is not as same as ID, ZK assume ID could be duplicated , buy UUID not.

2.About why randon UUID

The fact is , the UUID is not random , it depend how many components you create and the desktop ID ,then ZK just encode it .
(Encode for less memory usage in IE6/IE7. )
and if you want , you could overwrite the ID generator , just be careful for not to use two same UUID in same desktop.


You could also take a look with DesktopImpl#getNextUuid and ComponentsCtrl #toAutoId for more details
https://github.com/zkoss/zk/blob/master/zk/src/org/zkoss/zk/ui/impl/DesktopImpl.java
https://github.com/zkoss/zk/blob/master/zk/src/org/zkoss/zk/ui/sys/ComponentsCtrl.java

link publish delete flag offensive edit

answered 2012-01-17 04:41:15 +0800

TonyQ gravatar image TonyQ
642
https://www.masterbranch....

There's some docs about testing tips , please reference to http://books.zkoss.org/wiki/ZK_Developer%27s_Reference/Testing/Testing_Tips#ID_and_UUID.

link publish delete flag offensive edit

answered 2012-01-19 06:53:26 +0800

Maurus gravatar image Maurus
24

I do not understand your answer.

I asked three questions. The first two questions have to be answered yes or no.

In the default configuration of ZK the UUID's are random (random means not predictable in an easy way).

PureTest uses the HTML protocol to run the test. This means you have to know the parameters and their values send by a HTML request. You can have a look at these parameters by using Firebug in Firefox.

Firebug shows clearly that the UUID's are used as parameter values. To be able to generate PureTest tests I have to know the UUID's in advance.

The use of a CustomIdGenerator is of no use as the UUID's are only constant for one application. As soon as there is the smallest change in the application all tests have to be redone. This is clearly not an option.

The only way I can see is to tie the UUID to the component id given in the zul file.

The use of comp.getId(); in public String nextComponentUuid(Desktop desktop, Component comp) {....} does not work as comp.getId(); returns null or an empty String (my ZK version is 5.0.7.1).

I changed AbstractUiFactory in the following way:

@Override
	public Component newComponent(Page page, Component parent,
			ComponentInfo compInfo) {
		final Component comp = compInfo.newInstance(page, parent);

		// ++++++++++++++++++++++++++++++++++++++++++
		for (Object property : compInfo.getProperties()) {
			Property prop = (Property) property;
			if (prop.getName().equals("id")) {
				prop.assign(comp);
			}
		}
		// ++++++++++++++++++++++++++++++++++++++++++

		if (parent != null)
			comp.setParent(parent);
		else
			comp.setPage(page);

		if (comp instanceof BeforeCompose)
			((BeforeCompose) comp).beforeCompose();
		compInfo.applyProperties(comp); // include comp's definition
		return comp;
	}

The code added by myself is between +++.

I got this code from the thread http://www.zkoss.org/forum/listComment/17628-How-to-replace-id-to-uuid-on-testing.

Now comp.getId(); used in public String nextComponentUuid(Desktop desktop, Component comp) {...} of the CustomIdGenerator gives the id used in the zul file.
However the UUID generated by the CustomIdGenerator does not appear as expected on the HTML page (As test application I am using BugMS 1.1 (http://sourceforge.net/projects/bugms/). The test inserts a new bug.).

Further investigastion showed that ZK uses a recycling of UUID's.
Only when I removed the UUID recycling the UUID's appeared in the expected way on the HTML page (see below):

I changed DesktopImpl in the following way to remove UUID recycling:

     @Override
	public String getNextUuid(Component comp) {
		// The reason to recycle UUID is to keep it short (since _nextUuid won't
		// grow too fast)
		// Thus, it takes fewer memory at the client

		// removed
		// ++++++++++++++++++++++++++++++++++++++++++

		// if (_uuidRecycle != null && !_uuidRecycle.isEmpty()) {
		// final int execId = getExecId();
		// for (Iterator it = _uuidRecycle.iterator(); it.hasNext();) {
		// final RecycleInfo ri = (RecycleInfo)it.next();
		// if (ri.execId != execId) { //reuse if diff
		// final String uuid = (String)ri.uuids.remove(0);
		// if (ri.uuids.isEmpty())
		// it.remove();
		// return uuid;
		// }
		// }
		// }

             // ++++++++++++++++++++++++++++++++++++++++++

		final IdGenerator idgen = ((WebAppCtrl) _wapp).getIdGenerator();
		String uuid = idgen != null ? idgen.nextComponentUuid(this, comp)
				: null;
		if (uuid == null)
			return nextUuid();

		ComponentsCtrl.checkUuid(uuid);
		return uuid;
	}

The code removed by myself is between +++.

I further tried to tie the UUID to the zul file name by using

Page page = comp.getPage();
page.getRequestPath();

in String nextComponentUuid(Desktop desktop, Component comp) { ...} of my CustomIdGenerator. This only worked for the login page.

As you can see I had to change your code to get an id generation which might be useful.
However this can not be the way to go.

First I do not know ZK good enough to be sure that my changes will not break something.

Second it seems to me that all testers are facing the same problem.

Therefore I believe ZK should offer a general solution. This general solution has to create predictable UUID's, DesktopId's and any other id's which are send by HTML requests. The created ids have to stay the same as long as the component to which the id belongs does not change e.g the addition or removal of components should not result in a change of the ids of the untouched components.
Needless to say that this general solution has to be stable over new ZK releases.

My approch to this problem would be generation of ids out of SessionId, zul file name, id given in zul file and counter for each id e.g

SessionId_zulFileName_zulFileId_counter

So each time the same id is used the counter is increased by one.
This should garantee that each id is used only once and the id will be predictable.
As soon as a session is invalidated all ids belonging to this session will not be needed anymore and they can be removed from the internal bookeeping.
In this approach it is always clear from where an id comes from which will be very helpful for test maintainability.

link publish delete flag offensive edit

answered 2012-01-20 07:54:24 +0800

TonyQ gravatar image TonyQ
642
https://www.masterbranch....

updated 2012-01-20 07:54:54 +0800

ok , let me try to answer your question more clearly.

-------

Will this application work in a strict single user use?
Yes.

Will this application work in a multi user use?
Yes.

---------
Btw the code you comment should be equivalent as this properties , i will add this to testing tip .
http://books.zkoss.org/wiki/ZK_Configuration_Reference/zk.xml/The_Library_Properties/org.zkoss.zk.ui.uuidRecycle.disabled

link publish delete flag offensive edit

answered 2012-01-23 16:26:21 +0800

Maurus gravatar image Maurus
24

You have not answered the two questions below.

Will ZK provide a general solution for the id problem yes or no?

If yes till when will this solution be available?

link publish delete flag offensive edit

answered 2012-02-21 01:26:30 +0800

ashishd gravatar image ashishd flag of Taiwan
1972 6

Hi Maurus,
>>Will ZK provide a general solution for the id problem yes or no?
Well it is not a problem per say. It is the way it is designed to be. There are two main reasons to have unique IDs (aka UUID) for HTML DOM elements generated by ZK on the client side
1. In ZK there is a concept of IdSpace i.e. ZK allows scoping of child components within parent component and some of the components like Window form there own IdSpace meaning you can have only unique IDs for child components within this IdSpace component. On the other hand you can reuse IDs across different IdSpace. For eg. imagine you have two form to submit different set of data and each form has a submit button. Now in ZK you can have a Window containing a form and each Window can have a submit button with id "submit". However on the client side browsers if you have two HTML elements with same ids it is not easy to manage. Hence for ZK client engine to correctly and uniquely identify the right html DOM element it is essential to have unique ids.
2. Another reason components IDs in zul page do not correspond to their HTML DOM element IDs is for security. If the HTML DOM elements are known just by looking at the firebug then anyone can write a malicious script to automate attack on the application (for example repeatedly submit form and thereby overloading server)
>>If yes till when will this solution be available?
As I said above it is a design consideration to make your application more secure. For testing purpose you can either implement a custom ID generator (Ian gives one solution in this thread) or use ZTL (ZK Testing Lanaguage) Refer here

Feel free to ask more further questions if required.

link publish delete flag offensive edit

answered 2013-05-16 12:18:31 +0800

ank gravatar image ank
1 1

updated 2013-05-16 12:21:12 +0800

In my case I have performed load test on application build with zk framework using jmeter the script is running but after random time (say 8 to 10 hours) uuid changes and the script starts to fail. If I replaced the uuid of old script with the new uuid(which I got after record new script) the script start passing.

how can I handle this kind of behaviour of uuid.

Thanks

Ank

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-01-12 10:35:57 +0800

Seen: 673 times

Last updated: May 16 '13

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