我使用Flex + java的(Spring + Hibernate的)...如何在Java Enum類中存儲Flex文本框的值?
Java端...
public enum WeekdayType {
MONDAY(Calendar.MONDAY), TUESDAY(Calendar.TUESDAY), WEDNESDAY(
Calendar.WEDNESDAY), THURSDAY(Calendar.THURSDAY), FRIDAY(
Calendar.FRIDAY), SATURDAY(Calendar.SATURDAY), SUNDAY(
Calendar.SUNDAY);
private int day;
private WeekdayType(int day) {
this.day = day;
}
}
冬眠我使用Bean類.. TimetableVO.java
@Column(name="REPEAT_DAYS")
private String repeatDays;
@Transient
public List<WeekdayType> getRepeatDaysEnumList(){
List<WeekdayType> list = new ArrayList<WeekdayType>();
for(String str : this.repeatDays.split(",")){
list.add(WeekdayType.valueOf(str));
}
return list;
}
@Transient
public void setRepeatDaysEnumList(List<WeekdayType> repeatDays){
StringBuilder sb = new StringBuilder();
for(WeekdayType weekdayType : repeatDays){
sb.append(weekdayType.name());
sb.append(",");
}
this.repeatDays = sb.substring(0, sb.length()-1);
}
而在Flex端...
private var timetableVO:TimetableVO = new TimetableVO();
timetableVO.repeatDays = selectedDays.substr(0, selectedDays.length-1);
private var selectedDays:String = null;
protected function selectRepeatedDays(event:MouseEvent):void
{
selectedDays = new String();
if(MON.selected==true)
{
selectedDays += "MONDAY,";
}
if(TUE.selected==true)
{
selectedDays += "TUESDAY,";
}
}
只是我在快樂repeateDays增加值,但它給NullPointer Exception
Exception:Property 'repeatDaysEnumList' threw exception; nested exception is java.lang.NullPointerException.......
Caused by: java.lang.NullPointerException
at com.sits.ec.valueObjects.TimetableVO.setRepeatDaysEnumList(TimetableVO.java:64)
我不是創造repeatDaysEnumList但是Hibernate會做,因爲setter和getter的那麼這個空值怎麼來了...