Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge branch '6.0' into zkoss-master

  • Loading branch information...
commit 61ddca66d53fcb167300b718887b411c53d0378d 2 parents 5a3c87a + 2360dde
Dennis Chen dennischen authored
23 zel/src/org/zkoss/zel/impl/parser/AstValue.java
@@ -213,18 +213,19 @@ public void setValue(EvaluationContext ctx, Object value)
213 213 //for ZK-1178: check t.property(method name) of t.base has polymorphism?
214 214 boolean flag = false;
215 215 Class<?> baseClass = t.base.getClass();
  216 +
  217 + //logic of propertySetterName is from java.beans.NameGenerator#capitalize()
  218 + //XXX the same in BeanELResolver#setValue()
  219 + String propertySetterName = t.property.toString();
  220 + if(propertySetterName != null && propertySetterName.length()>0){
  221 + propertySetterName =
  222 + "set"+
  223 + propertySetterName.substring(0,1).toUpperCase(Locale.ENGLISH) +
  224 + propertySetterName.substring(1);
  225 + }
  226 + ////
  227 +
216 228 for (Method m : baseClass.getMethods()) {
217   - //logic of propertySetterName is from java.beans.NameGenerator#capitalize()
218   - //XXX the same in BeanELResolver#setValue()
219   - String propertySetterName = t.property.toString();
220   - if(propertySetterName != null && propertySetterName.length()>0){
221   - propertySetterName =
222   - "set"+
223   - propertySetterName.substring(0,1).toUpperCase(Locale.ENGLISH) +
224   - propertySetterName.substring(1);
225   - }
226   - ////
227   -
228 229 //method name must the same as t.property (setter)
229 230 if (m.getName().equals(propertySetterName)) {
230 231 Class<?>[] clazzes = m.getParameterTypes();
24 zkbind/src/org/zkoss/bind/impl/InitFormBindingImpl.java
@@ -12,6 +12,10 @@
12 12
13 13 package org.zkoss.bind.impl;
14 14
  15 +import java.util.Collections;
  16 +import java.util.Comparator;
  17 +import java.util.LinkedList;
  18 +import java.util.List;
15 19 import java.util.Map;
16 20
17 21 import org.zkoss.bind.BindContext;
@@ -23,6 +27,7 @@
23 27 import org.zkoss.bind.sys.ConditionType;
24 28 import org.zkoss.bind.sys.InitFormBinding;
25 29 import org.zkoss.bind.sys.InitPropertyBinding;
  30 +import org.zkoss.bind.xel.zel.BindELContext;
26 31 import org.zkoss.xel.ExpressionX;
27 32 import org.zkoss.zk.ui.Component;
28 33
@@ -57,7 +62,24 @@ public void load(BindContext ctx) {
57 62 //sets the last loaded bean express of the form
58 63 comp.setAttribute(BinderImpl.LOAD_FORM_EXPRESSION, getPropertyString());
59 64
60   - for (String field : fex.getLoadFieldNames()) {
  65 + //ZK-1259, for the case of nested form expression in same loading, e.g. @load(fx.hash[fx.key]),
  66 + //it will produce 2 loadField name, 'hash[fx.key]' & 'key',
  67 + //and fx + 'hash[fx.key]' will get null if fx + 'key' is not loaded yet and throw exception
  68 + //i sort the field name to let inner value be loaded into form first.
  69 + final String fomrid = getFormId();
  70 + List<String> fields = new LinkedList<String>(fex.getLoadFieldNames());
  71 + Collections.sort(fields, new Comparator<String>() {
  72 + @Override
  73 + public int compare(String o1, String o2) {
  74 + o1 = BindELContext.appendFields(fomrid, o1);
  75 + o2 = BindELContext.appendFields(fomrid, o2);
  76 + if(o1.indexOf(o2)>0) return 1;
  77 + if(o2.indexOf(o1)>0) return -1;
  78 + return 0;
  79 + }
  80 + });
  81 +
  82 + for (String field : fields) {
61 83 final ExpressionX expr = getFieldExpression(eval, field);
62 84 if (expr != null) {
63 85 final Object fieldval = eval.getValue(ctx, comp, expr);
23 zkbind/src/org/zkoss/bind/impl/LoadFormBindingImpl.java
@@ -12,7 +12,10 @@
12 12
13 13 package org.zkoss.bind.impl;
14 14
  15 +import java.util.Collections;
  16 +import java.util.Comparator;
15 17 import java.util.HashSet;
  18 +import java.util.LinkedList;
16 19 import java.util.List;
17 20 import java.util.Map;
18 21 import java.util.Set;
@@ -68,7 +71,25 @@ public void load(BindContext ctx) {
68 71 //sets the last loaded bean express of the form
69 72 comp.setAttribute(BinderImpl.LOAD_FORM_EXPRESSION, getPropertyString());
70 73
71   - for (String field : fex.getLoadFieldNames()) {
  74 +
  75 + //ZK-1259, for the case of nested form expression in same loading, e.g. @load(fx.hash[fx.key]),
  76 + //it will produce 2 loadField name, 'hash[fx.key]' & 'key',
  77 + //and fx + 'hash[fx.key]' will get null if fx + 'key' is not loaded yet and throw exception
  78 + //i sort the field name to let inner value be loaded into form first.
  79 + final String fomrid = getFormId();
  80 + List<String> fields = new LinkedList<String>(fex.getLoadFieldNames());
  81 + Collections.sort(fields, new Comparator<String>() {
  82 + @Override
  83 + public int compare(String o1, String o2) {
  84 + o1 = BindELContext.appendFields(fomrid, o1);
  85 + o2 = BindELContext.appendFields(fomrid, o2);
  86 + if(o1.indexOf(o2)>0) return 1;
  87 + if(o2.indexOf(o1)>0) return -1;
  88 + return 0;
  89 + }
  90 + });
  91 +
  92 + for (String field : fields) {
72 93 final ExpressionX expr = getFieldExpression(eval, field);
73 94 if (expr != null) {
74 95 final Object value = eval.getValue(ctx, comp, expr);
21 zkbind/src/org/zkoss/bind/xel/zel/BindExpressionBuilder.java
@@ -44,7 +44,7 @@
44 44 public class BindExpressionBuilder extends ExpressionBuilder {
45 45
46 46 private static final Log _log = Log.lookup(BindExpressionBuilder.class);
47   -
  47 + private static final String _isVisitedKey = BindExpressionBuilder.class+"_isVisted";
48 48 private final BindELContext _ctx;
49 49 public BindExpressionBuilder(String expression, ELContext ctx) throws ELException {
50 50 super(expression, ctx);
@@ -72,7 +72,17 @@ private static Component getDependsOnComponent(BindContext ctx) {
72 72 private void addTracking(List<String> series) {
73 73 final Binding binding = _ctx.getBinding();
74 74 final boolean dotracker = !_ctx.ignoreTracker();
  75 +
75 76 if (binding != null && series != null && !series.isEmpty()) {
  77 +
  78 + //to prevent unnecessary from-save in nested expression in from binding and cause save error
  79 + //e.g @bind(fx.hash[fx.key]) or @bind(vm.hash[fx.key])
  80 +
  81 + final Boolean isVisted = (Boolean)_ctx.getAttribute(_isVisitedKey);
  82 + if(!Boolean.TRUE.equals(isVisted)){
  83 + _ctx.setAttribute(_isVisitedKey, Boolean.TRUE);
  84 + }
  85 +
76 86 final Iterator<String> it = series.iterator();
77 87 final String prop = (String) it.next();
78 88 final Binder binder = binding.getBinder();
@@ -88,18 +98,19 @@ private void addTracking(List<String> series) {
88 98 if (base instanceof Form) {
89 99 final Form formBean = (Form) base;
90 100 final String fieldName = fieldName(it);
  101 +
91 102 if (fieldName != null) {
92   - if (binding instanceof SavePropertyBinding) {
  103 + if (binding instanceof SavePropertyBinding && !Boolean.TRUE.equals(isVisted)) {
93 104 if(_log.debugable()){
94   - _log.debug("add save-filed %s to form %s", fieldName,formBean);
  105 + _log.debug("add save-filed '%s' to form '%s'", fieldName,formBean);
95 106 }
96   - if(formBean instanceof FormExt){
  107 + if(formBean instanceof FormExt ){
97 108 ((FormExt)formBean).addSaveFieldName(fieldName);
98 109 }
99 110 ((BinderCtrl)binder).addFormAssociatedSaveBinding(comp, prop, (SavePropertyBinding)binding, fieldName);
100 111 } else if (binding instanceof LoadPropertyBinding) {
101 112 if(_log.debugable()){
102   - _log.debug("add load-filed %s to form %s", fieldName,formBean);
  113 + _log.debug("add load-filed '%s' to form '%s'", fieldName,formBean);
103 114 }
104 115 if(formBean instanceof FormExt){
105 116 ((FormExt)formBean).addLoadFieldName(fieldName);
1  zkdoc/release-note
@@ -118,6 +118,7 @@ ZK 6.0.3
118 118 ZK-1336: Liferay 6.1 + JBoss 7.1 + ZK 6 : Cannot encode relative URLs
119 119 ZK-1368: the right edge of the textboxes split over to a new line when you specify a percentage width and set the mold to rounded
120 120 ZK-1383: The value of Map.Entry returned from ListModelMap.getElementAt() don't support Serializable
  121 + ZK-1259: zul with hashmap not load key from a fx
121 122
122 123 * Upgrade Notes
123 124 + The default names of a composer will still be assigned no matter you set a composerName by custom-attributes or not.
51 zktest/src/archive/bind/issue/B01259HaskMapInFx1.zul
... ... @@ -0,0 +1,51 @@
  1 +<zk>
  2 + <window border="normal" title="hello"
  3 + apply="org.zkoss.bind.BindComposer" viewModel="@id('vm') @init('org.zkoss.zktest.bind.issue.B01259HaskMapInFx')">
  4 + <label multiline="true" >
  5 + 1.the left text value should equal to left side value
  6 + </label>
  7 + <vbox form="@id('fx') @load(vm)">
  8 + <hbox>
  9 + <label id="l11" value="@load(fx.hash[vm.key])"/> = Hello World
  10 + </hbox>
  11 + <hbox>
  12 + <label id="l12" value="@load(vm.hash[vm.key])"/> = Hello World
  13 + </hbox>
  14 + <hbox>
  15 + <label id="l13" value="@load(fx.hash[fx.key])"/> = Hello World
  16 + </hbox>
  17 + <hbox>
  18 + <label id="l14" value="@load(fx.hash[fx.hash[fx.key3]])"/> = Hi Dennis
  19 + </hbox>
  20 + <hbox>
  21 + <label id="l15" value="@load(vm.hash[vm.hash[vm.key3]])"/> = Hi Dennis
  22 + </hbox>
  23 + </vbox>
  24 + <label multiline="true" >
  25 + 2.check the value to 'A' and 'B' then click save
  26 + 3.the value above label should change to 'A' , 'A', 'A', 'B','B'
  27 + </label>
  28 + <vbox form="@id('fx') @load(vm) @save(vm,before='save')">
  29 + <hbox>
  30 + <textbox id="t21" value="@bind(fx.hash[fx.key])"/>
  31 + </hbox>
  32 + <hbox>
  33 + <textbox id="t22" value="@bind(fx.hash[fx.hash[fx.key3]])"/>
  34 + </hbox>
  35 + <button id="btn2" label="save" onClick="@command('save')" />
  36 + </vbox>
  37 + <label multiline="true" >
  38 + 2.check the value to 'C' and 'D' then click save
  39 + 3.the value label text should change to 'C' , 'C', 'C', 'D','D'
  40 + </label>
  41 + <vbox form="@id('fx') @load(vm) @save(vm,before='save2')">
  42 + <hbox>
  43 + <textbox id="t31" value="@bind(vm.hash[fx.key])"/>
  44 + </hbox>
  45 + <hbox>
  46 + <textbox id="t32" value="@bind(vm.hash[fx.hash[fx.key3]])"/>
  47 + </hbox>
  48 + <button id="btn3" label="save" onClick="@command('save2')" />
  49 + </vbox>
  50 + </window>
  51 +</zk>
25 zktest/src/archive/bind/issue/B01259HaskMapInFx2.zul
... ... @@ -0,0 +1,25 @@
  1 +<zk>
  2 + <window border="normal" title="hello"
  3 + apply="org.zkoss.bind.BindComposer" viewModel="@id('vm') @init('org.zkoss.zktest.bind.issue.B01259HaskMapInFx')">
  4 + <label multiline="true" >
  5 + 1.the left text value should equal to left side value
  6 + </label>
  7 + <vbox form="@id('fx') @init(vm)">
  8 + <hbox>
  9 + <label id="l11" value="@load(fx.hash[vm.key])"/> = Hello World
  10 + </hbox>
  11 + <hbox>
  12 + <label id="l12" value="@load(vm.hash[vm.key])"/> = Hello World
  13 + </hbox>
  14 + <hbox>
  15 + <label id="l13" value="@load(fx.hash[fx.key])"/> = Hello World
  16 + </hbox>
  17 + <hbox>
  18 + <label id="l14" value="@load(fx.hash[fx.hash[fx.key3]])"/> = Hi Dennis
  19 + </hbox>
  20 + <hbox>
  21 + <label id="l15" value="@load(vm.hash[vm.hash[vm.key3]])"/> = Hi Dennis
  22 + </hbox>
  23 + </vbox>
  24 + </window>
  25 +</zk>
37 zktest/src/org/zkoss/zktest/bind/issue/B01259HaskMapInFx.java
... ... @@ -0,0 +1,37 @@
  1 +package org.zkoss.zktest.bind.issue;
  2 +import java.util.HashMap;
  3 +import java.util.Map;
  4 +
  5 +import org.zkoss.bind.annotation.Command;
  6 +import org.zkoss.bind.annotation.NotifyChange;
  7 +public class B01259HaskMapInFx {
  8 + private Map<String, String> hash = new HashMap<String, String>();
  9 + private String key = "mykey";
  10 + private String key2 = "mykey2";
  11 + private String key3 = "mykey3";
  12 +
  13 + public B01259HaskMapInFx() {
  14 + this.hash.put(key, "Hello World");
  15 + this.hash.put(key2, "Hi Dennis");
  16 + this.hash.put(key3, key2);
  17 + }
  18 +
  19 + public Map<String, String> getHash() {
  20 + return this.hash;
  21 + }
  22 +
  23 + public String getKey() {
  24 + return this.key;
  25 + }
  26 + public String getKey2() {
  27 + return this.key2;
  28 + }
  29 + public String getKey3() {
  30 + return this.key3;
  31 + }
  32 +
  33 + @Command({"save","save2"}) @NotifyChange(".")
  34 + public void save(){
  35 +
  36 + }
  37 +}

0 comments on commit 61ddca6

Please sign in to comment.
Something went wrong with that request. Please try again.