gpt4 book ai didi

java - 将属性设置为 DropDownChoice 的选项

转载 作者:行者123 更新时间:2023-12-01 05:45:46 25 4
gpt4 key购买 nike

我有一个 DropDownChoice:

        DropDownChoice dateSpanChoice = new DropDownChoice("dateSpan", new PropertyModel(getModel(), "dateSpan"), dateSpans, new IChoiceRenderer() {

private static final long serialVersionUID = 10105L;

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

@Override
public Object getDisplayValue(Object object) {
DateTime today = new DateTime();
DateTime currentDate = new DateTime(today.getYear(), today.getMonthOfYear(), today.getDayOfMonth(), 0, 0, 0, 0);
DateSpan dateSpan = (DateSpan) object;
DateTime fromDate = dateSpan.getFromDate();
DateTime toDate = dateSpan.getToDate();
boolean currentDateIsEqualOrAfterFromDate = currentDate.isEqual(fromDate) | currentDate.isAfter(fromDate);
boolean currentDateIsEqualOrBeforeToDate = currentDate.isEqual(toDate) | currentDate.isBefore(toDate);
boolean currentDateBelongsToCurrentRange = currentDateIsEqualOrAfterFromDate & currentDateIsEqualOrBeforeToDate;
if (currentDateBelongsToCurrentRange) {
return ((DateSpan) object).getDisplayValue() + " *";
} else {
return ((DateSpan) object).getDisplayValue();
}
}
}) {

private static final long serialVersionUID = 10106L;

protected CharSequence getDefaultChoice(final Object selected) {
CharSequence charSequence = super.getDefaultChoice(selected);
System.out.println("=============================================================");
//System.out.println(charSequence);
//THIS CHARSEQUENCE IS RENRING EMPTY STRING
if(StringUtils.isBlank(charSequence.toString())) {
System.out.println("CHARSEQUENCE IS BLANK");
} else {
System.out.println("CHARSEQUENCE IS NOT BLANK");
}
return charSequence;
}
};
dateSpanChoice.setNullValid(false);

我正在尝试将 style="background-color: red"添加到所选选项。所以我重写了 getDefaultChoice() 但正如你所看到的,它在代码中被注释,CharSequence 是空的。

有没有办法为 DropDownChoice 的特定选项设置属性?

感谢和问候。

注意:日期时间是 Joda 时间

最佳答案

为了更复杂地使用元素,您需要 Select/SelectOption 而不是 DropDownChoice。

关于java - 将属性设置为 DropDownChoice 的选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5947078/

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