1

我正在使用 Flex+java(Spring+hibernate)...

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,但是由于Setter和Getter,Hibernate会这样做,那么这个Null值是如何来的......

4

1 回答 1

0

好吧,我猜这个问题正在发生,因为您正在将字符串发送回服务器,而这根本不知道如何将其转换为枚举列表。首先,我不建议发送一个逗号分隔的字符串,而是一个元素的 ArrayCollection,但这仍然不能处理字符串仍然没有反序列化为 Enum(尽管反过来也可以)。我写了一篇关于如何向 BlazeDS 添加 Enum-Like 支持的教程。即使它确实处理自动代码生成和 Flexmojos,我想它也应该包含解决问题所需的信息部分:https ://dev.c-ware.de/confluence/display/PUBLIC/Flexmojos+生成+AS3+model+with+Enum+support+using+BlazeDS

于 2013-02-18T16:28:15.993 回答