This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 255421

Summary: Replacing a @Model reference has to be notified to knockout.js
Product: platform Reporter: Jaroslav Tulach <jtulach>
Component: Html4jAssignee: Jaroslav Tulach <jtulach>
Status: RESOLVED FIXED    
Severity: normal    
Priority: P1    
Version: 8.1   
Hardware: PC   
OS: Linux   
Issue Type: DEFECT Exception Reporter:

Description Jaroslav Tulach 2015-09-19 13:02:22 UTC
Holger reported:

I found the problem or currently I don't know if it is a bug or not.
In my program I had the following statement:
Models.toRaw(ui);
This statement was left from playing around with the router example from the blog.
My program worked with version 1.1 but with your version 1.2.1 it stopped working because of that statement.
Here is a small test program:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div>
    <label>Produk 1:</label>
</div>
<div>
    <p>
    <span>
      <input id="produkt1No" title="produkt1 unchecked" type="radio" name="produkt1Group" value="no"
             data-bind="checked: produktAuswahl().produkt1"/><label for="produkt1No">No</label>
      <input id="produkt1Yes" title="produkt1 checked" type="radio" name="produkt1Group" value="yes"
             data-bind="checked: produktAuswahl().produkt1"/><label for="produkt1Yes">Yes</label>
    </span>
    </p>
</div>
<div>
    <button data-bind="click: $root.validate">Validate</button>
</div>
Result from produkt1:<span data-bind="text: produktAuswahl().produkt1"></span><br>
Result from validation:<span data-bind="text: result"></span>
<script>
    $(document).foundation();
</script>
</body>
</html>


package eu.sample.test;

import net.java.html.json.*;

@Model(className = "UI", targetId = "", properties = {
        @Property(name = "produktAuswahl", type = ProduktAuswahl.class),
        @Property(name = "result", type = String.class)
})
public class DataModel {

    @Function
    static void validate(UI ui) {
        System.out.println("ui.getProduktAuswahl().getValidate() = [" + ui.getProduktAuswahl().getValidate() + "]");
        ui.setResult(ui.getProduktAuswahl().getValidate());
    }

    /**
     * Called when the page is ready.
     */
    static void onPageLoad() throws Exception {
        UI ui = new UI();
        Models.toRaw(ui);
        final ProduktAuswahl produktAuswahl = new ProduktAuswahl();
        ui.setProduktAuswahl(produktAuswahl);
        ui.applyBindings();
    }

    @Model(className = "ProduktAuswahl", targetId = "", properties = {
            @Property(name = "produkt1", type = String.class)
    })
    static class ProduktAuswahlModel {
        @ComputedProperty
        static String validate(String produkt1) {
            return produkt1;
        }
    }

}


With Version 1.1: After pressing "validate" the text "Result from validation" will show the radio button selection
With Version 1.2.1: After pressing "validate" the text after "Result from validation" is empty and the log shows "ui.getProduktAuswahl().getValidate() = [null]"
Comment 1 Jaroslav Tulach 2015-09-19 13:03:34 UTC
Turns out to be caused by value equality of @Model generated classes.
Comment 2 Jaroslav Tulach 2015-09-19 13:07:48 UTC
Kind of regression:
http://hg.netbeans.org/html4j/rev/581f50820e5e
should be part of HTML/Java 1.2.3 release and hopefully also part of 8.1 release.
Comment 3 Jaroslav Tulach 2015-09-22 20:18:06 UTC
http://hg.netbeans.org/ergonomics/rev/d300ce172688