2

I'm trying to use TemplateRenderer where I want to propagate models to front-end.

userGrid.addColumn(TemplateRenderer.<UserProjection>of(
        "<user-card"
                + " userDetail='[[item.userDetail]]'"
                + " licenses='[[item.licenses]]' "
                + " test='[[item.test]]'"
                + " id='[[item.id]]'"
                + ">"
                + "</user-card>")
        .withProperty("userDetail", user -> user)
        .withProperty("licenses",
                user -> userService.findAllUserLicenses(user.getId()).stream().map(License::new).collect(Collectors.toList()))
        .withProperty("test", UserProjection::getEmail)
        .withProperty("id", UserProjection::getId)
);

this is my template:

<link rel="import" href="../../bower_components/polymer/polymer-element.html">

<link rel="import" href="../../styles/shared-styles.html">


    <dom-module id="user-card">
        <template>

            <div class="content" on-click="_onClick">
                <div>[[test]] [[id]] [[userDetail.id]] </div>
                <div class="user-details">

                    <h1>[[userDetail.firstName]] [[userDetail.lastName]]</h1>
                    <h3>[[userDetail.email]]</h3>
                </div>
                <dom-repeat items="[[licenses]]">
                    <div class="license">
                        {{item.validTo}}
                    </div>
                </dom-repeat>
            </div>

        </template>
        <script>
            class UserCard extends Polymer.Element {
                static get is() {
                    return "user-card";
                }

                _onClick() {
                    this.dispatchEvent(new CustomEvent('card-click'));
                }
            }

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

and user-card template is also included in template where I'm using the grid. I can successfully display properties test and id however I'm unable to work with userDetail and licenses. Can somebody tell me what am I doing wrong? I'm using vaadin 13.0.5.

bilak
  • 4,526
  • 3
  • 35
  • 75
  • Could you try to add ` – anasmi May 02 '19 at 05:27
  • (Could you try to rename the `userDetail` to something else for testing purposes? Does it work this way?) – anasmi May 02 '19 at 05:37
  • Hi, I used `template` for `dom-repeat` and also renamed `userDetail` to `superDetail` and changed that in parameter and also in template but nothing works. – bilak May 02 '19 at 06:09
  • Alrigth, then it's something else. But thanks for checking – anasmi May 02 '19 at 06:21
  • 1
    I just resolved that...it's about weird naming in template. Instead of `userDetail='[[item.userDetail]]'` I renamed html attribute to `user-detail='[[item.userDetail]]'` and now it works. I have overlooked that, or maybe that just could be mentioned somewhere in vaadin documentation. – bilak May 02 '19 at 07:07
  • It's nice you have found it! But, indeed, I haven't seen/found myself any mention that `-` should be used – anasmi May 02 '19 at 07:18

0 Answers0