关闭绑定器

时间:2018-02-18 19:16:59

标签: vaadin8

我在binder中有一些组件:

binder.bind(cbClientRating, Client::getRating, Client::setRating);
binder.bind(tfFirstName, Client::getFirstName, Client::setFirstName);
binder.bind(tfLastName, Client::getLastName, Client::setLastName);
binder.bind(dfBirthDate, Client::getBirthDate, Client::setBirthDate);

根据我的业务逻辑,我不需要更改绑定器中一个组件的 readonly 状态,例如当我调用时,Combobox - cbClientRating binder.setReadOnly(false)。它应该保持只读模式等于真。

现在我打电话 致电cbClientRating.setReadOnly(true)

binder.setReadOnly(false)

binder.setReadOnly(false); cbClientRating.setReadoOnly(true);

还有其他解决方案吗?

1 个答案:

答案 0 :(得分:0)

Binder#setReadOnly(boolean)的源代码:

/**
 * Sets the read only state to the given value for all currently bound
 * fields.
 * <p>
 * This is just a shorthand for calling setReadOnly for all currently bound
 * fields. It means that fields bound after this method call won't be set
 * read-only.
 *
 * @param fieldsReadOnly
 *            true to set the fields to read only, false to set them to read
 *            write
 */
public void setReadOnly(boolean fieldsReadOnly) {
    getBindings().stream().map(BindingImpl::getField)
            .forEach(field -> field.setReadOnly(fieldsReadOnly));
}

所以这只是一种方便的方法。我建议您根据自己的业务逻辑自己完全处理字段只读状态。

相关问题