vaadin / flow

Vaadin Flow is a Java framework binding Vaadin web components to Java. This is part of Vaadin 10+.
Apache License 2.0
616 stars 167 forks source link

It should be possible to set the initial model property value from the client side #3556

Open vlukashov opened 6 years ago

vlukashov commented 6 years ago

As a developer I want set the initial value of some model properties from the client side. Currently (as of alpha 20 of Flow 1.0) an attempt to do so leads to an inconsistent behavior (even though tere was an attempt to fix it earlier: https://github.com/vaadin/flow/issues/2897)

<template>
    <p>[[message]]</p>
    <p>client-side model property value is [[_formatBoolean(checkboxChecked)]]</p>
    <vaadin-checkbox checked="{{checkboxChecked}}">
        a vaadin-checkbox bound to a model property
    </vaadin-checkbox>
</template>
public interface ExampleModel extends TemplateModel {
    Boolean getCheckboxChecked();
}

When this page loads, an observer for the client-side property detects two changes:

checkboxChecked changed from 'undefined' to 'false'
checkboxChecked changed from 'false' to 'null'

screen recording 2018-02-14 at 03 25 pm

The server-side value of the checkboxChecked property depends on the signature of the property getter in the template model:

The source code of the demo project is attached: platform18-model-properties.zip

Expected behavior

(or there should be clear documentation explaining the actual behavior)

stefanuebe commented 6 years ago

Similar case here: I have a template with a simple String property, that I want to set initially client side. As soon as I "link" the property in my server side TemplateModel implementation, the client side set value is overriden.

<dom-module id="project-list-accumulate">
    ...
    <h5 id="caption" class="graph-title">[[caption]]</h5>
    ...
    <script>
        class ProjectListAccumulate extends Polymer.Element {
            static get is() {
                return 'project-list-accumulate';
            }

            static get properties() {
                return {
                    caption: String
                }
            }
        }

        customElements.define(ProjectListAccumulate.is, ProjectListAccumulate);
    </script>
</dom-module>

This element is called like for example

<project-list-accumulate id="accumulate-project" caption="Total project"></project-list-accumulate>

The server side Java model is

protected interface ProjectListAccumulateModel extends TemplateModel {
    void setCaption(String caption);
}

When I remove the method setCaption() the client side set value is displayed.