java - 使用 Vaadin Designer 时 Vaadin 8 绑定到 Pojo
问题描述
我正在开发一个从 Vaadin 设计器生成 UI 的项目。我有生成的 html 和相应的 .java 文件。
我扩展了 java 文件并将我的数据绑定到设计视图。显示我的数据的基本代码正在工作,因为表单上的每个字段都有一个相应的 pojo 变量。现在我想在表单上同时显示两个字段,就像您将名字和姓氏结合起来显示全名一样。
我的 pojo 有一个 toString 方法,它返回组合的两个值,但我不知道如何将标签 propertyNoName 设置为 aPropertyProfile.toString() 的值
public class PropertyProfileDesign extends VerticalLayout
{
private VerticalLayout propertyProfileHeader;
private Label propertyNoName;
private TextField propertyMgr;
private TextField propertyMgrPhone;
private TextField propertyMgrCellular;
private TextField propertyMgrHome;
private TextField regionalMgr;
private TextField regionalMgrPhone;
private TextField regionalMgrCellular;
private TextField regionalMgrHome;
private VerticalLayout propertyProfileBodyFooter;
public PropertyProfileDesign()
{
Design.read( this );
}
public VerticalLayout getPropertyProfileHeader()
{
return propertyProfileHeader;
}
public Label getPropertyNoName()
{
return propertyNoName;
}
public TextField getPropertyMgr()
{
return propertyMgr;
}
public TextField getPropertyMgrPhone()
{
return propertyMgrPhone;
}
public TextField getPropertyMgrCellular()
{
return propertyMgrCellular;
}
public TextField getPropertyMgrHome()
{
return propertyMgrHome;
}
public TextField getRegionalMgr()
{
return regionalMgr;
}
public TextField getRegionalMgrPhone()
{
return regionalMgrPhone;
}
public TextField getRegionalMgrCellular()
{
return regionalMgrCellular;
}
public TextField getRegionalMgrHome()
{
return regionalMgrHome;
}
public VerticalLayout getPropertyProfileBodyFooter()
{
return propertyProfileBodyFooter;
}
}
public class PropertyProfileView extends PropertyProfileDesign
{
private static final long serialVersionUID = 7454308982717559970L;
private Binder<PropertyProfile> binder = new Binder<>( PropertyProfile.class );
public PropertyProfileView()
{
}
public PropertyProfileView( final PropertyProfile aPropertyProfile )
{
this();
binder.bindInstanceFields( this );
binder.readBean( aPropertyProfile );
// How to update the label field propertyNoName with aPropertyProfile.toString()?
}
}
解决方案
只需使用 Label 的 setValue(..) 方法:
propertyNoName.setValue(aPropertyProfile.toString());
推荐阅读
- ruby-on-rails - 在 simple_form 中间输出
- java - 如何访问json中的数组?
- python - 对python 2中允许但在python 3中不允许的混合变量类型进行排序?
- angular7 - Angular 7 SSR 窗口未定义
- javascript - 来自不同 npm 版本的不同包锁定结果
- python - 如何遍历行并根据同一行中其他字段的内容查询特定字段?
- ios - 从 Apple VPP api 获取“需要登录”
- animation - Stack 中的动画 FloatingActionButton 不会触发 onPressed 事件
- javascript - 如果我不嵌套 if/else 语句,则代码不起作用。为什么我必须筑巢?
- drupal-7 - 多个地方的Drupal 7事件-多对多关系