Vaadin网格在使用CheckboxRenderer时变为空。

huangapple go评论74阅读模式
英文:

Vaadin grid becomes empty, when using CheckboxRenderer

问题

Vaadin版本是8.10.1

添加插件:

<dependency>
    <groupId>com.vaadin</groupId>
    <artifactId>grid-renderers-collection-addon</artifactId>
    <version>2.7.0</version>
</dependency>

在表格中定义渲染器如下:

CheckboxRenderer renderer = new CheckboxRenderer<>(Payment::setSelectedToMultiAction);
paymentGrid.addColumn(Payment::getSelectedToMultiAction)
        .setRenderer(renderer)
        .setCaption("Selection");

但是表格显示为空。在Chrome的js控制台中没有错误:

Vaadin网格在使用CheckboxRenderer时变为空。

如果我们移除渲染器,一切都会显示出来。

CheckboxRenderer renderer = new CheckboxRenderer<>(Payment::setSelectedToMultiAction);
paymentGrid.addColumn(Payment::getSelectedToMultiAction)
//        .setRenderer(renderer)
        .setCaption("Selection");

控件在vaadin-maven-plugin运行期间处理:

<plugin>
    <groupId>com.vaadin</groupId>
    <artifactId>vaadin-maven-plugin</artifactId>
    <version>${vaadin.version}</version>
    <configuration>
        <webappDirectory>${basedir}/resources/VAADIN/widgetsets</webappDirectory>
        <hostedWebapp>${basedir}/resources/VAADIN/widgetsets</hostedWebapp>
    </configuration>
    <executions>
        <execution>
            <goals>
                <!--<goal>clean</goal>
                <goal>resources</goal>-->
                <goal>update-theme</goal>
                <goal>update-widgetset</goal>
                <goal>compile-theme</goal>
                <goal>compile</goal>
            </goals>
        </execution>
    </executions>
</plugin>
英文:

Vaadin version is 8.10.1

Adding the addon:

    &lt;dependency&gt;
        &lt;groupId&gt;com.vaadin&lt;/groupId&gt;
        &lt;artifactId&gt;grid-renderers-collection-addon&lt;/artifactId&gt;
        &lt;version&gt;2.7.0&lt;/version&gt;
    &lt;/dependency&gt;

and in the grid defining the renderer like that:

    CheckboxRenderer renderer = new CheckboxRenderer&lt;&gt;(Payment::setSelectedToMultiAction);
    paymentGrid.addColumn(Payment::getSelectedToMultiAction)
            .setRenderer(renderer)
            .setCaption(&quot;Selection&quot;);

But the grid shown empty. With no error in Chrome's js console:

Vaadin网格在使用CheckboxRenderer时变为空。

If we remove the renderere, everything is displayed.

    CheckboxRenderer renderer = new CheckboxRenderer&lt;&gt;(Payment::setSelectedToMultiAction);
    paymentGrid.addColumn(Payment::getSelectedToMultiAction)
    //        .setRenderer(renderer)
            .setCaption(&quot;Selection&quot;);

The widget is handled during the vaadin-maven-plugin run:

&lt;plugin&gt;
                &lt;groupId&gt;com.vaadin&lt;/groupId&gt;
                &lt;artifactId&gt;vaadin-maven-plugin&lt;/artifactId&gt;
                &lt;version&gt;${vaadin.version}&lt;/version&gt;
                &lt;configuration&gt;
                    &lt;webappDirectory&gt;${basedir}/resources/VAADIN/widgetsets&lt;/webappDirectory&gt;
                    &lt;hostedWebapp&gt;${basedir}/resources/VAADIN/widgetsets&lt;/hostedWebapp&gt;
                &lt;/configuration&gt;
                &lt;executions&gt;
                    &lt;execution&gt;
                        &lt;goals&gt;
                            &lt;!--&lt;goal&gt;clean&lt;/goal&gt;
                            &lt;goal&gt;resources&lt;/goal&gt;--&gt;
                            &lt;goal&gt;update-theme&lt;/goal&gt;
                            &lt;goal&gt;update-widgetset&lt;/goal&gt;
                            &lt;goal&gt;compile-theme&lt;/goal&gt;
                            &lt;goal&gt;compile&lt;/goal&gt;
                        &lt;/goals&gt;
                    &lt;/execution&gt;
                &lt;/executions&gt;
            &lt;/plugin&gt;

答案1

得分: 1

我成功使用 Vaadin 8.1 中的 ComponentRenderer,而不是 grid-renderers-collection-addon 中的 CheckboxRenderer

paymentGrid.addComponentColumn(payment -> {
    CheckBox multiselected = new CheckBox();
    multiselected.addValueChangeListener(event -> {
        payment.setSelectedToMultiAction(event.getValue());
        if (event.getValue()) {
            selectedPayments.add(payment);
        } else {
            selectedPayments.remove(payment);
        }
        showButtons();
    });
    return multiselected;
});
英文:

I succeed with using ComponentRenderer from Vaadin 8.1, not the CheckboxRenderer from grid-renderers-collection-addon

   paymentGrid.addComponentColumn(payment -&gt; {
        CheckBox multiselected = new CheckBox();
        multiselected.addValueChangeListener(event -&gt; {
            payment.setSelectedToMultiAction(event.getValue());
            if (event.getValue()) {
                selectedPayments.add(payment);
            } else {
                selectedPayments.remove(payment);
            }
            showButtons();
        });
        return multiselected;
    });

huangapple
  • 本文由 发表于 2023年6月5日 01:43:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/76401678.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定