我正在使用 vaadin select 来显示带有状态的选择菜单。
private Select<States> states = new Select<>();
Run Code Online (Sandbox Code Playgroud)
states.setLabel("State");
states.setItems(facade.stateService().findAllStates());
states.setItemLabelGenerator(States::getName);
Run Code Online (Sandbox Code Playgroud)
Optional<States> state = facade.stateService().findByCode(location.getLocationState());
if (state.isPresent()) {
states.setValue(state.get()); // this is not working
}
Run Code Online (Sandbox Code Playgroud)
我正在获取状态值并使用它进行设置,states.setValue()但选择不显示更新的状态。该方法正在被调用。如何使选择的菜单被选中?谢谢。
根据您共享的代码无法判断。很可能States返回的对象location.getLocationState().get()与返回的值不共享相同的对象标识facade.stateService().findAllStates()。即使对象的属性(例如“名称”)相同,也会发生这种情况。通常,答案是在类中实现hashCode和equals方法,其身份仅取决于实体的 id。
| 归档时间: |
|
| 查看次数: |
101 次 |
| 最近记录: |