Bringing in the work on default branch beans
authorJaroslav Tulach <jtulach@netbeans.org>
Tue, 05 Aug 2014 18:31:51 +0200
branchbeans
changeset 8148573ad9106a2
parent 808 d116ca60ae79
parent 809 57c6bd4c5261
child 1036 05139f7b3629
Bringing in the work on default branch
     1.1 --- a/boot-script/src/test/java/net/java/html/boot/script/ko4j/KnockoutEnvJSTest.java	Mon Aug 04 19:00:41 2014 +0200
     1.2 +++ b/boot-script/src/test/java/net/java/html/boot/script/ko4j/KnockoutEnvJSTest.java	Tue Aug 05 18:31:51 2014 +0200
     1.3 @@ -158,6 +158,7 @@
     1.4              case "paintTheGridOnClick":
     1.5              case "displayContentOfArrayOfPeople":
     1.6              case "connectUsingWebSocket":
     1.7 +            case "selectWorksOnModels":
     1.8                  return "Does not work on JDK8, due to JDK-8046013";
     1.9          }
    1.10          return null;
     2.1 --- a/json-tck/src/main/java/net/java/html/json/tests/KnockoutTest.java	Mon Aug 04 19:00:41 2014 +0200
     2.2 +++ b/json-tck/src/main/java/net/java/html/json/tests/KnockoutTest.java	Tue Aug 05 18:31:51 2014 +0200
     2.3 @@ -65,6 +65,8 @@
     2.4      @Property(name="enabled", type=boolean.class),
     2.5      @Property(name="latitude", type=double.class),
     2.6      @Property(name="choice", type=KnockoutTest.Choice.class),
     2.7 +    @Property(name="archetype", type=ArchetypeData.class),
     2.8 +    @Property(name="archetypes", type=ArchetypeData.class, array = true),
     2.9  }) 
    2.10  public final class KnockoutTest {
    2.11      private KnockoutModel js;
    2.12 @@ -169,6 +171,66 @@
    2.13          }
    2.14      }
    2.15      
    2.16 +    private static String getSetSelected(int index, Object value) throws Exception {
    2.17 +        String s = "var index = arguments[0];\n"
    2.18 +        + "var value = arguments[1];\n"
    2.19 +        + "var n = window.document.getElementById('input'); \n "
    2.20 +        + "if (value != null) {\n"
    2.21 +        + "  n.options[index].value = 'me'; \n"
    2.22 +        + "  n.value = 'me'; \n"
    2.23 +        + "  ko.dataFor(n.options[index]).archetype(value); // haven't found better way to trigger ko change yet \n"
    2.24 +        + "} \n "
    2.25 +        + "var op = n.options[n.selectedIndex]; \n"
    2.26 +        + "return op ? op.text : n.selectedIndex;\n";
    2.27 +        Object ret = Utils.executeScript(
    2.28 +            KnockoutTest.class,
    2.29 +            s, index, value
    2.30 +        );
    2.31 +        return ret == null ? null : ret.toString();
    2.32 +    }
    2.33 +    
    2.34 +    @Model(className = "ArchetypeData", properties = {
    2.35 +        @Property(name = "artifactId", type = String.class),
    2.36 +        @Property(name = "groupId", type = String.class),
    2.37 +        @Property(name = "version", type = String.class),
    2.38 +        @Property(name = "name", type = String.class),
    2.39 +        @Property(name = "description", type = String.class),
    2.40 +        @Property(name = "url", type = String.class),
    2.41 +    })
    2.42 +    static class ArchModel {
    2.43 +    }
    2.44 +    
    2.45 +    @KOTest public void selectWorksOnModels() throws Exception {
    2.46 +        if (js == null) {
    2.47 +            Utils.exposeHTML(KnockoutTest.class, 
    2.48 +                "<select id='input' data-bind=\"options: archetypes,\n" +
    2.49 +"                       optionsText: 'name',\n" +
    2.50 +"                       value: archetype\">\n" +
    2.51 +"                  </select>\n" +
    2.52 +""
    2.53 +            );
    2.54 +            
    2.55 +            js = Models.bind(new KnockoutModel(), newContext());
    2.56 +            js.getArchetypes().add(new ArchetypeData("ko4j", "org.netbeans.html", "0.8.3", "ko4j", "ko4j", null));
    2.57 +            js.getArchetypes().add(new ArchetypeData("crud", "org.netbeans.html", "0.8.3", "crud", "crud", null));
    2.58 +            js.getArchetypes().add(new ArchetypeData("3rd", "org.netbeans.html", "0.8.3", "3rd", "3rd", null));
    2.59 +            js.setArchetype(js.getArchetypes().get(1));
    2.60 +            js.applyBindings();
    2.61 +            
    2.62 +            String v = getSetSelected(0, null);
    2.63 +            assert "crud".equals(v) : "Second index (e.g. crud) is selected: " + v;
    2.64 +            
    2.65 +            String sel = getSetSelected(2, Models.toRaw(js.getArchetypes().get(2)));
    2.66 +            assert "3rd".equals(sel) : "3rd is selected now: " + sel;
    2.67 +        }
    2.68 +        
    2.69 +        if (js.getArchetype() != js.getArchetypes().get(2)) {
    2.70 +            throw new InterruptedException();
    2.71 +        }
    2.72 +        
    2.73 +        Utils.exposeHTML(KnockoutTest.class, "");
    2.74 +    }
    2.75 +    
    2.76      @KOTest public void modifyValueAssertAsyncChangeInModel() throws Exception {
    2.77          if (js == null) {
    2.78              Utils.exposeHTML(KnockoutTest.class, 
     3.1 --- a/ko4j/src/main/java/org/netbeans/html/ko4j/Knockout.java	Mon Aug 04 19:00:41 2014 +0200
     3.2 +++ b/ko4j/src/main/java/org/netbeans/html/ko4j/Knockout.java	Tue Aug 05 18:31:51 2014 +0200
     3.3 @@ -116,7 +116,8 @@
     3.4          + "  };\n"
     3.5          + "  if (!readOnly) {\n"
     3.6          + "    bnd['write'] = function(val) {\n"
     3.7 -        + "      prop.@org.apidesign.html.json.spi.PropertyBinding::setValue(Ljava/lang/Object;)(val);\n"
     3.8 +        + "      var model = val['ko-fx.model'];\n"
     3.9 +        + "      prop.@org.apidesign.html.json.spi.PropertyBinding::setValue(Ljava/lang/Object;)(model ? model : val);\n"
    3.10          + "    };\n"
    3.11          + "  };\n"
    3.12          + "  var cmpt = ko['computed'](bnd);\n"