0

ZK6: Inputfields with constraints and ZK Bind

asked 2011-12-12 08:47:36 +0800

Matze2 gravatar image Matze2
773 7

Are ordinary constraints still supported with the new data-binding?

I tried to port a ZUL file which uses the old data-binding to the new ZK bind method.
This page has input fields, where the initial value would violate the given constraint, for example

<intbox cols="6" width="100px" constraint="no empty, no negative, no zero" value="@{model.intvalue}" />

where the intvalue in the model was initialized to 0.

I ported that to ViewModel - more or less there was almost no change to the model code needed. The new intbox looks like the following:

<intbox cols="6" width="100px" constraint="no empty, no negative, no zero" value="@bind(vm.intvalue)" />

intvalue is still initialized to 0 in the ViewModel.

The difference is, that I get now a WrongValueException, since the new data binder calls setValue on the Intbox while the old data binder called setRawValue.

Question: is this behavior intended - i.e. constraints are not supported anymore - or is it a bug?
In case of the latter, I can also provide a complete example if needed.

delete flag offensive retag edit

11 Replies

Sort by ยป oldest newest

answered 2011-12-13 11:08:19 +0800

dennis gravatar image dennis
3679 1 6
http://www.javaworld.com....

Hi, Matze
I know this issue, the problem is binder don't know when to call setRawValue or setValue. Always call setRawValue maybe is incorrect in some scenario.
We will figure out a easy to do this. currently, you could use.

<intbox cols="6" width="100px" constraint="no empty, no negative, no zero" value="@save(vm.intvalue)"  rawValue="@load(vm.intValue)"/>

/Dennis

link publish delete flag offensive edit

answered 2011-12-14 07:03:10 +0800

dennis gravatar image dennis
3679 1 6
http://www.javaworld.com....

Hi, Matze
We decided to call this a bug, and will fix it, the tracker is here , http://tracker.zkoss.org/browse/ZK-682
Thanks.

link publish delete flag offensive edit

answered 2011-12-14 08:43:57 +0800

Matze2 gravatar image Matze2
773 7

Thanks. Now I can continue with ZK6 testing.
Your other suggestion would have meant too much migration changes and a big part of them would have been only temporarily as far as I understood your workaround.

link publish delete flag offensive edit

answered 2011-12-14 10:27:29 +0800

dennis gravatar image dennis
3679 1 6
http://www.javaworld.com....

Matze,
Are you evaluating to port old application to zk 6 or for new applications?

link publish delete flag offensive edit

answered 2011-12-14 12:11:31 +0800

Matze2 gravatar image Matze2
773 7

I try to port a private project of medium size, which runs with 5.0.9 currently. It heavily uses the old data binding, so it is a good candidate to try ZK bind.

This is just for evaluation to try the new features, detecting problems with the new concepts upfront and to estimate possible migration efforts.
Currently, this is only private interest, but the gained knowledge will also get used in our company, e.g. to generate some design rules for ZK5 applications to be able to port them to ZK6 easier, e.g. to work already with a kind of ViewModel class.

But there are no concrete plans yet for "really" moving to ZK6, neither with old nor with new applications.

link publish delete flag offensive edit

answered 2011-12-15 15:27:56 +0800

Matze2 gravatar image Matze2
773 7

updated 2011-12-15 15:29:32 +0800

Dennis,

just tried the latest freshly zk-bin-6.0.0-FL-2011-12-15, the fix for ZK-682 seems to work. Thank you very much.
BTW: the issue is not listed in release-note.

But now something else is broken with annotations and the old data binder:
It seems that Annotation.getAttributes now returns a Map<String, String[]>, but at least AnnotateDataBinder.loadComponent is not prepared for it.
There is a cast to String in

List expr = parseExpression((String) me.getValue(), ";");

which leads to a ClassCastException.

link publish delete flag offensive edit

answered 2011-12-16 01:19:50 +0800

dennis gravatar image dennis
3679 1 6
http://www.javaworld.com....

Yes, the annotation spec. is changed in zk6.
could you provide the exception, then I can post to bug tracker, thanks.

link publish delete flag offensive edit

answered 2011-12-16 07:20:38 +0800

Matze2 gravatar image Matze2
773 7

Hi Dennis,

here is the relevant part of the stack:

java.lang.ClassCastException: [Ljava.lang.String; cannot be cast to java.lang.String
	at org.zkoss.zkplus.databind.AnnotateDataBinder.loadComponentAnnotation(AnnotateDataBinder.java:444)
	at org.zkoss.zkplus.databind.AnnotateDataBinder.loadComponentAnnotation(AnnotateDataBinder.java:431)
	at org.zkoss.zkplus.databind.AnnotateDataBinder.loadAnnotations(AnnotateDataBinder.java:403)
	at org.zkoss.zkplus.databind.AnnotateDataBinder.loadAnnotations(AnnotateDataBinder.java:408)
	at org.zkoss.zkplus.databind.AnnotateDataBinder.loadAnnotations(AnnotateDataBinder.java:408)
	at org.zkoss.zkplus.databind.AnnotateDataBinder.init(AnnotateDataBinder.java:399)
	at org.zkoss.zkplus.databind.AnnotateDataBinder.<init>(AnnotateDataBinder.java:303)

and here is the problematic code section
			Map attrs = ann.getAttributes();
			for(final Iterator it = attrs.entrySet().iterator(); it.hasNext();) {
				Entry me = (Entry) it.next();
				String attr = (String) me.getKey();
				//[0] bean value, [1 ~ *] tag:expression
				List expr = parseExpression((String) me.getValue(), ";");

The Map entry of ann.getAttributes() is <String, String[]>, but the entry's value gets casted to String below.
It seems that this the only place where the use of generics is not extended beyond the call to getAttributes().
Must have been sneaked through...

link publish delete flag offensive edit

answered 2011-12-16 07:26:04 +0800

Matze2 gravatar image Matze2
773 7

Looks like you found it yourself already.

link publish delete flag offensive edit

answered 2011-12-19 07:57:02 +0800

Matze2 gravatar image Matze2
773 7

Just an update for your info: with FL-2011-12-16, everything works now.

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: 2011-12-12 08:47:36 +0800

Seen: 662 times

Last updated: Dec 19 '11

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