我使用以下4行代码成功在vaadin java web应用程序中设置NativeSelect,并且我的enum(ApplicationStatus)创建并填充了NativeSelect菜单。
当我尝试在声明文件中执行相同操作时,NativeSelect菜单显示为空。
class Application extends VerticalLayout
{
public Application()
{
..
//ApplicationStatus is an enum, these exact four lines of code work fine without declarative
private NativeSelect<ApplicationStatus> categorySelect = new NativeSelect<ApplicationStatus>("Application Status");
categorySelect.setItems( ApplicationStatus.values());
categorySelect.setItemCaptionGenerator( ApplicationStatus::getName );
categorySelect.setSelectedItem(ApplicationStatus.ACTIVE);
..
}
这是声明性HTML文件(ATTEMPT1) //菜单显示为空
...
<row>
<column><vaadin-label><strong>Decline Reason</strong></vaadin-label></column>
<column><v-native-select _id="categorySelect"></v-native-select></column>
</row>
...
**Here is the Declarative HTML FILE (ATTEMPT2)** //I tried populating it inline but the result was that the menu now has the word "Duplicate" showing 5 times.
...
<row>
<column><vaadin-label><strong>Change Category</strong></vaadin-label></column>
<column><vaadin-native-select _id="categorySelect">
<option value="D">Decline</option>
<option value="W">Waitlist</option>
<option value="R">Rejected by VCS</option>
<option value="P">Prospect</option>
<option value="C">Duplicate</option>
</vaadin-native-select></column>
</row>
...
答案 0 :(得分:0)
你没有为声明性实现包含Java源代码,所以只是试着去做。
在类对象中声明NativeSelect变量,用于定义它所在的布局。让设计使用您提供的_id将变量绑定到声明。然后使用枚举填充控件并像以前一样指定默认值。
NativeSelect<ApplicationStatus> categorySelect;
public DemoView()
{
Design.read( "DemoView.html", this );
categorySelect.setItems( ApplicationStatus.values() );
categorySelect.setSelectedItem( ApplicationStatus.ACTIVE );
这会产生一个带有所需字幕和枚举映射的选择控件。
我追踪了一些Vaadin代码,我不确定是否有办法用纯粹使用声明性方法的枚举填充控件。