0

Client side post invalid "items" to server

asked 2012-09-19 03:23:53 +0800

dliu gravatar image dliu
15

updated 2012-09-19 03:39:27 +0800

Hi,

I am blocked by a problem for the whole day about the tree componenent. I build a simple tree and the tree shows perfectly.

But the problem arises when I select a node then expand the node. A alert box pops up and says "java.lang.String cannot be cast to java.util.List".

I traced the problem and found the function in org.zkoss.zk.ui.event.SelectEvent:

@SuppressWarnings("unchecked")
	public static final <T extends Component, E> SelectEvent<T,E> 
			getSelectEvent(AuRequest request, SelectedObjectHandler<T> handler) {
		final Map<String, Object> data = request.getData();
		final Desktop desktop = request.getDesktop();
		final List<String> sitems = cast((List)data.get("items"));
		final Set<T> items = AuRequests.convertToItems(desktop, sitems);
		final Set<E> objs = (Set<E>) (handler == null ? null : handler.getObjects(items));
		return new SelectEvent<T,E>(request.getCommand(), request.getComponent(),
			items, objs, (T) desktop.getComponentByUuidIfAny((String)data.get("reference")),
			null, AuRequests.parseKeys(data));
	}

As far as I understand, it tries to extract event info from the information post by client which is actually a JSON on the wire. So I took a look at the data using firebug
and found the snippet:
dtid:z_vgb
cmd_0:onSelect
uuid_0:mSHQ1
data_0:{"items":"","reference":"mSHQ7","clearFirst":false,"pageX":528,"pageY":86,"which":1,"x":62,"y":50}
cmd_1:onOpen
uuid_1:mSHQ7
data_1:{"open":false}

It is a STRING but I guess the client engine tries to send an array. Why the client engine send the wrong data?

My environment: the zul page is used together Prototype framework and some other 3rd party libraries.

Cound someone help on this? Your help is really appreciated!

delete flag offensive retag edit

4 Replies

Sort by ยป oldest newest

answered 2012-09-19 03:44:42 +0800

dliu gravatar image dliu
15

More Information:

I used ZK 6.0.2, found the problem, upgradde to ZK 6.5.0. But unfortunately the problems still exist.

About the data snippet: in "items" , there is a square bracket enclosing a string with no double quotes. It seems it is swallowed somehow in the post.

link publish delete flag offensive edit

answered 2012-09-19 05:22:55 +0800

dliu gravatar image dliu
15

Update:

I access the .zul directly in order to isolate zk from other client side js. It works as expected.

The same operation(select and expand) sends out different data:

dtid:z_2hb
cmd_0:onOpen
uuid_0:h0APi1
data_0:{"open":true}

Only "onOpen" event is sent while in the faulty case, "onSelect" is send at the same time. Could it be a clue for somebody with more ZK experience to guess what's going wrong?

I doubt the problem is caused by client side js interference :(

link publish delete flag offensive edit

answered 2012-10-02 02:21:41 +0800

samchuang gravatar image samchuang
4084 4

hi , can you provide runnable sample code ?

link publish delete flag offensive edit

answered 2012-10-02 04:58:42 +0800

gekkio gravatar image gekkio flag of Finland
899 1
http://gekkio.fi/blog

I'm quite sure it's a compatibility problem introduced by Prototype. My quick analysis is that zk.copy function uses for...in loop on an Array, but that won't work because Prototype modifies the built-in Javascript Array. This is something that is explicitly warned about in the Prototype documentation.

Note that this isn't really a ZK bug, but a compatibility problem due to the extremely invasive nature of Prototype. I would strongly recommend against mixing it with ZK, because there might be other incompatibilities too.

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-09-19 03:23:53 +0800

Seen: 89 times

Last updated: Oct 02 '12

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