我有一个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的特定选项?
谢谢和问候。
注意:DateTime是Joda时间
答案 0 :(得分:1)
您需要Select / SelectOption而不是DropDownChoice才能更复杂地使用元素。
答案 1 :(得分:-1)
查看Wicket中的行为包。 例如,您可以使用AttributeAppender - 类。