【问题标题】:GWT Editors - MaterialComboBox is assignable to the raw Editor type, but a type parameterization is requiredGWT 编辑器 - MaterialComboBox 可分配给原始编辑器类型,但需要类型参数化
【发布时间】:2019-06-17 23:50:06
【问题描述】:

我正在尝试使用 gwt 编辑器框架,以便我可以让我的视图 (SingleReplayView) 编辑我的 bean SingleClaimId

这是我的视图类:

public class SingleReplayView extends ViewWithUiHandlers<SingleReplayUiHandlers> implements SingleReplayPresenter.MyView, Editor<ReplayClaimId>  
{
    interface Binder extends UiBinder<Widget, SingleReplayView> {
    }

    public interface SingleReplayDriver extends SimpleBeanEditorDriver<ReplayClaimId, SingleReplayView> {}
    protected static SingleReplayDriver driver = GWT.create(SingleReplayDriver.class);

    @UiField
    MaterialTextBox claimId;

    @UiField
    MaterialComboBox originalEnvironment;

    @UiField
    @Path("replayEnvironment")
    MaterialComboBox replayEnvironment;

    @UiField
    @Path("bmsDisabled")
    MaterialRadioButton bmsDisabled;

    @UiField
    @Path("bmsEnabledWithInjection")
    MaterialRadioButton bmsEnabledWithInjection;

    @UiField
    @Path("bmsEnabledWithNoInjection")
    MaterialRadioButton bmsEnabledWithNoInjection;

    @UiField
    @Path("tariffEnabled")
    MaterialCheckBox tariffEnabled;

    @UiField
    @Path("humDisabled")
    MaterialCheckBox humDisable;

    @Inject
    SingleReplayView(Binder uiBinder) {
        initWidget(uiBinder.createAndBindUi(this));
        driver.initialize(this);
    }

    @UiHandler("singleSubmitButton")
    public void submit(ClickEvent event) {
        ReplayClaimId replayClaimId = driver.flush();
        MaterialToast.fireToast(replayClaimId.getClaimId());
    }
}

还有我的豆类

public class ReplayClaimId implements IsSerializable {

    private String claimId;
    private String originalEnvironment;
    private String replayEnvironment;

    private Boolean bmsDisabled;
    private Boolean bmsEnabledWithInjection;
    private Boolean bmsEnabledWithNoInjection;

    private Boolean tariffEnabled;
    private Boolean humDisabled;

    //with setters and getters
}

当我尝试编译代码时出现错误

The type gwt.material.design.addins.client.combobox.MaterialComboBox is assignable to the raw Editor type, but a type parameterization is required.
[INFO]    [ERROR] Errors in 'SingleReplayView.java'

可以帮忙吗?

【问题讨论】:

  • 对不起,我不知道我的第一行发生了什么,就像这样:public class SingleReplayView extends ViewWithUiHandlers implements SingleReplayPresenter.MyView, Editor {

标签: gwt gwt-material-design


【解决方案1】:

类型 gwt.material.design.addins.client.combobox.MaterialComboBox 可分配给原始编辑器类型,但需要类型参数化。

错误是在谈论这个(和其他类似的领域):

    @UiField
    MaterialComboBox originalEnvironment;

但是字段MaterialComboBox&lt;T&gt; 的泛型表明它必须是它正在编辑的类型T 的泛型。 https://gwtmaterialdesign.github.io/gwt-material-demo/apidocs-addins/gwt/material/design/addins/client/combobox/MaterialComboBox.html

在这种情况下,您希望 T 与您的 bean 类型中的相同:

    private String originalEnvironment;

所以你的@UiField 应该是

    @UiField
    MaterialComboBox<String> originalEnvironment;

replayEnvironment 编辑器也需要相同的参数化。

【讨论】:

  • 非常感谢科林
  • 我已经解决了我的问题,事实证明 MaterialComboBox 对 T 来说是通用的,正如 Colin 上面提到的那样,它将通用转换为 List 所以如果你把 MaterialComboBox 你的 bean 属性应该是 List 即使该值将是具有选择值的大小为 1 的列表
  • 在这种情况下,您可以编写一个适配器编辑器来包装 MaterialComboBox,并自动将单个 String 包装在 List 中,并在写回 bean 时再次解包。只需实现 LeafValueEditor>` (或为简单起见将其设为 List&lt;String&gt;),您就可以在每次需要时将它包裹起来。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-11-09
  • 2018-12-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多