- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在使用具有如下下拉选项的 Java Wicket 表单时遇到问题:
public class SomePage extends WebPage {
public SomePage () {
CompoundPropertyModel<SomeBean> properties = new CompoundPropertyModel<SomeBean>(new SomeBean());
Form<SomeBean> form = new Form<SomeBean>("SomeBeanForm", properties) {
//override on submit
};
form.add(new DropDownChoice<MyEnum>("myEnum", Lists.newArrayList(MyEnum.values()));
add(form);
}
}
SomeBean 很简单,如下所示:
public class SomeBean {
private MyEnum myEnum;
// Getter, Setter
public SomeBean(){
}
}
MyEnum 是:
public enum MyEnum {
CHOICE1("1"),
CHOICE2("2");
private String id;
public MyEnum(String id) {
this.id=id;
}
//some methods to get/set/display id
}
我的问题是如何使用CompoundPropertyModel 在bean 中设置枚举?我收到一个异常,例如:
Could not convert value: CHOICE1 to type: MyEnum Could not find compatible converter.
这是由于它不知道如何将任何内容转换为 MyEnum 对象,它需要一个易于创建的转换器,但是如何为由CompoundPropertyModel创建的PropertyModel设置转换器?
感谢您的帮助!
--编辑--
这是一个错误的枚举导入,bean 和下拉选项使用了具有相同名称的不同枚举。这段代码有效。
最佳答案
您的代码不包含实体名称作为组件ID,这就是使用CompoundPropertyModel的原因。
查看 https://repo.twinstone.org/projects/WISTF/repos/wicket-examples-6.x/browse 上的完整代码示例
HTML 片段:
<form wicket:id="form">
<label>Text</label>: <input type="text" wicket:id="text" /> <br/>
<select wicket:id="choice"></select>
<input wicket:id="submit" type="submit" value="Send" />
</form>
代码片段:
final IChoiceRenderer<ChoiceEnum> CHOICE_RENDERER = new ChoiceRenderer<ChoiceEnum>("description");
inal List<ChoiceEnum> ALL_CHOICES = Arrays.asList(ChoiceEnum.values());
final IModel<TextAndEnumBean> model = Model.of(new TextAndEnumBean());
final IModel<TextAndEnumBean> compoundModel = CompoundPropertyModel.of(model);
Form<TextAndEnumBean> form = new Form<>("form", compoundModel);
add(form);
form.add(new TextField<String>("text"));
form.add(new DropDownChoice<ChoiceEnum>("choice", ALL_CHOICES, CHOICE_RENDERER).setNullValid(true));
form.add(new Button("submit"));
实体Bean代码:
public class TextAndEnumBean implements Serializable {
private static final long serialVersionUID = 1L;
private String text;
private ChoiceEnum choice;
public TextAndEnumBean() {
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
public ChoiceEnum getChoice() {
return choice;
}
public void setChoice(ChoiceEnum choice) {
this.choice = choice;
}
}
枚举定义代码:
public enum ChoiceEnum {
CHOICE1("choice no. 1"),
CHOICE2("choice no. 2"),
MY_CHOICE("example of my choice"),
ANTOHER_CHOICE("another choice");
private final String description;
private ChoiceEnum(String description) {
this.description = description;
}
public String getDescription() {
return description;
}
}
关于java - 带有 DropDownChoice 的 Wicket 表单,带有枚举和CompoundPropertyModel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21599478/
Wicket 中有什么东西可以做两个 下拉选项,以便第一个 doprdownchoice 的第一个选择更改第二个的所有选项吗? 最佳答案 您应该使用第一个选择的值来确定第二个的值。 在这个例子中,我选
我在使用 DropDownChoice 时遇到问题。我必须预先选择一个项目,但我找到的每个教程和示例都只考虑原始类型列表。 我有一个对象列表。 class myObject { private
您好,我创建了 web 应用程序,并且有 DropDownChoice (默认值“A”),但是当我从 DropDownChoice 中选择了某些项目(“B”),然后我执行了一些操作(例如提交),然后在
我有带字段的表单: public VyjimkyForm(final Parametry parametry) { super("vyjimkyForm", new Compo
我有一个 DropDownChoice : DropDownChoice timePeriod = new DropDownChoice("timePeriod", Arrays.asL
在我的项目中,我有 50 多个表单,它们大多彼此相似并使用相同的 DropDownChoice成分。我可以创建单独的 Panel ,在这里我定义了我的 DropDownChoice ,然后我将使用该
所以我在 Wicket 中有我的 DropDownChoice: final DropDownChoice drop_down_status = new DropDownChoice("status"
我在 DropDownChoice (wicket 1.6) 中显示选项时遇到问题。 DropDownChoice choice = new DropDownChoice("enabled", Arr
我的 web 应用程序上的一个 DropDownChoice 列表需要很长时间才能创建,因为通过 LDAP 连接和 SQL 连接的某些操作获取选项。因此,整个页面的加载时间远远超过了几秒钟 - 我想说
我试图在 wicket 框架中获取 dropdownchoice 的选定值,但我无法获取它。如何在 dropdownchoice 的更改事件上获取 DropDownChoice 的选定值???谢谢。我
我有一个 DropDownChoice: DropDownChoice dateSpanChoice = new DropDownChoice("dateSpan", new Prop
我正在使用 Wicket 口向导让用户执行多个步骤进行注册。 但不知怎的,我得到了这个错误: Last cause: Attempt to set model object on null model
我试图在 DropDownChoice 上获取我所选选项的 ID,但出现错误。我知道,当我选择一个值时,我只是更新模型而不是对象(反射)。我希望通过 getModelObject() 获取对象“Use
我正在使用 Wicket 口 DropDownChoice我的列表很长,有没有一种方法可以让当我单击下拉列表然后单击一个字符时,列表将跳转到以相同字符开头的第一个选择 最佳答案 我知道这不是您问题的确
我有 3 个 DropDownChoice COuntry>State>Cities 及其更新可以使用 Ajax onchage 方法使用 ajax 行为。 如果我想通过 JAVA 而不是 AJAX
是否有一些明显的方法可以将分隔符添加到 Wicket DropDownChoice 中的选项列表?在我的例子中,我使用来 self 的数据源的两种类型的域对象来填充选择。我想我可以手动将某种虚拟域对象
我正在尝试访问用户在 apache wicket 的 DropDownChoices 中选择的值。我将 AjaxFormComponentUpdatingBehavior 添加到 DropDownCh
我需要在选择后立即更新模型或对象DropDownChoice 项。 贝娄是我正在工作的代码: add(new ListView[Company]("listCompanies", listData)
我需要创建一个 wicket dropdownchoice 组件,我可以通过设置将默认的“选择一个”文本替换为“全部” nullValid=All null=All 在其属性文件中。我也想将“All”
有没有办法让 Wicket 中的 DropDownChoice 将工具提示(例如标题属性)分配给各个选项元素? 我有以下形式的选择框项目: public class SelectBoxItem {
我是一名优秀的程序员,十分优秀!