gpt4 book ai didi

java - DropDownChoice 设置选定的特定索引

转载 作者:行者123 更新时间:2023-11-30 05:57:19 26 4
gpt4 key购买 nike

我有一个 DropDownChoice :

       DropDownChoice timePeriod = new DropDownChoice("timePeriod", Arrays.asList(new TimePeriod(1, "Weekly"), new TimePeriod(2, "Bi-Weekly"), new TimePeriod(3, "Semi-Monthly"), new TimePeriod(4, "Monthly"), new TimePeriod(5, "Yearly")), new IChoiceRenderer() {

private static final long serialVersionUID = 10102L;

@Override
public String getIdValue(Object object, int index) {
return ((TimePeriod) object).getId() + "";
}

@Override
public Object getDisplayValue(Object object) {
return ((TimePeriod) object).getPeriodType();
}
});
timePeriod.setNullValid(false);

我的问题是:

  1. 如何将所选索引设置为 2 或任何其他索引?
  2. 如何删除第一个默认空白选项?

谢谢。

最佳答案

您应该能够使用 PropertyModel 设置所选索引,而不是对下拉列表的值进行硬编码。我现在无法测试,但它会是这样的

String timePeriodValue = "Bi-Weekly";

DropDownChoice timePeriod = new DropDownChoice("timePeriod",
new PropertyModel(this, "timePeriodValue"),
Arrays.asList(/* your options */),
new IChoiceRenderer() {
// ...
// Again, this is pseudocode only

作为奖励,设置默认值的行为应该可以消除空白选项问题。

关于java - DropDownChoice 设置选定的特定索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5858098/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com