diff -r 44cb743c3a5b json/src/main/java/org/netbeans/html/json/impl/Bindings.java
--- a/json/src/main/java/org/netbeans/html/json/impl/Bindings.java Fri Dec 12 11:50:20 2014 +0100
+++ b/json/src/main/java/org/netbeans/html/json/impl/Bindings.java Fri Dec 12 12:32:48 2014 +0100
@@ -42,6 +42,8 @@
*/
package org.netbeans.html.json.impl;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import net.java.html.BrwsrCtx;
import org.netbeans.html.json.spi.FunctionBinding;
import org.netbeans.html.json.spi.PropertyBinding;
@@ -53,6 +55,8 @@
* @author Jaroslav Tulach
*/
public final class Bindings {
+ private static final Logger LOG = Logger.getLogger(Bindings.class.getName());
+
private Data data;
private final Technology bp;
@@ -105,7 +109,18 @@
}
}
- public void applyBindings() {
+ public void applyBindings(String id) {
+ if (bp instanceof Technology.ApplyId) {
+ Technology.ApplyId ai = (Technology.ApplyId) bp;
+ ai.applyBindings(id, data);
+ return;
+ }
+ if (id != null) {
+ LOG.log(Level.WARNING,
+ "Technology {0} does not implement ApplyId extension. Can''t apply to {1}. Applying globally.",
+ new Object[]{bp, id}
+ );
+ }
bp.applyBindings(data);
}
diff -r 44cb743c3a5b json/src/main/java/org/netbeans/html/json/impl/ModelProcessor.java
--- a/json/src/main/java/org/netbeans/html/json/impl/ModelProcessor.java Fri Dec 12 11:50:20 2014 +0100
+++ b/json/src/main/java/org/netbeans/html/json/impl/ModelProcessor.java Fri Dec 12 12:32:48 2014 +0100
@@ -504,12 +504,26 @@
+ "In case of using Knockout technology, this means to \n"
+ "bind JSON like data in this model instance with Knockout tags in \n"
+ "the surrounding HTML page.\n"
+ + "@return returns this
\n"
+ "*/\n"
);
w.write(" public " + className + " applyBindings() {\n");
w.write(" proto.applyBindings();\n");
w.write(" return this;\n");
w.write(" }\n");
+ w.write(" /** Activates this model instance in the current {@link \n"
+ + "net.java.html.json.Models#bind(java.lang.Object, net.java.html.BrwsrCtx) browser context}. \n"
+ + "In case of using Knockout technology, this means to \n"
+ + "bind JSON like data in this model instance with Knockout tags in \n"
+ + "the surrounding HTML page.\n"
+ + "@param id identifies the element to apply the model to\n"
+ + "@return returns this
\n"
+ + "*/\n"
+ );
+ w.write(" public " + className + " applyBindings(String id) {\n");
+ w.write(" proto.applyBindings(id);\n");
+ w.write(" return this;\n");
+ w.write(" }\n");
w.write(" public boolean equals(Object o) {\n");
w.write(" if (o == this) return true;\n");
w.write(" if (!(o instanceof " + className + ")) return false;\n");
diff -r 44cb743c3a5b json/src/main/java/org/netbeans/html/json/spi/Proto.java
--- a/json/src/main/java/org/netbeans/html/json/spi/Proto.java Fri Dec 12 11:50:20 2014 +0100
+++ b/json/src/main/java/org/netbeans/html/json/spi/Proto.java Fri Dec 12 12:32:48 2014 +0100
@@ -193,7 +193,21 @@
* of the current model to the body element of the page.
*/
public void applyBindings() {
- initBindings().applyBindings();
+ initBindings().applyBindings(null);
+ }
+
+ /** Initializes the associated model to the specified element's subtree.
+ * The technology is taken from the current {@link #getContext() context} and
+ * in case of knockout.js applies given bindings
+ * of the current model to the element of the page with 'id' attribute
+ * set to the specified id
value.
+ *
+ * @param id the id of element to apply the binding to
+ * @since 1.1
+ * @see Technology.ApplyId
+ */
+ public void applyBindings(String id) {
+ initBindings().applyBindings(id);
}
/** Invokes the provided runnable in the {@link #getContext() context}
diff -r 44cb743c3a5b json/src/main/java/org/netbeans/html/json/spi/Technology.java
--- a/json/src/main/java/org/netbeans/html/json/spi/Technology.java Fri Dec 12 11:50:20 2014 +0100
+++ b/json/src/main/java/org/netbeans/html/json/spi/Technology.java Fri Dec 12 12:32:48 2014 +0100
@@ -173,4 +173,22 @@
*/
public void valueHasMutated(D data, String propertyName, Object oldValue, Object newValue);
}
+
+ /** Apply technology bindings at selected subtree of the HTML page.
+ * Can be accessed via {@link Proto#applyBindings(java.lang.String)} or
+ * via method applyBindings(String)
generated when one
+ * is using the {@link Model} annotation.
+ *
+ * @param
Memory model when using Knockout bindings has been improved (required additions of two new methods: {@link org.netbeans.html.json.spi.PropertyBinding#weak()} and