1
votes

I'm using Flex+java(Spring+hibernate)...

Java side...

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;
}

}

hibernate Bean class i'm using..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);
}

And in Flex side ...

        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,";
                }
}

Just i'm Adding values in repeateDays But it is giving 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)

i'm not creating repeatDaysEnumList but Hibernate will do because of Setter and Getter then how this Null value coming...

1

1 Answers

0
votes

Well I guess this problem is occuring as you are sending a string back to the server and this simply doesn't know how to convert this into a list of Enums. First I wouldn't suggest to send a comma-separated string back, but an ArrayCollection of elements, but that still doesn't handle that Strings are still not deserialized to Enum (the other way around does work though). I wrote a tutorial on how to add Enum-Like support to BlazeDS. Even if it does Handle automatic code-generation and Flexmojos, I guess it should also contain the parts of Information you need to get your problem solved: https://dev.c-ware.de/confluence/display/PUBLIC/Flexmojos+generated+AS3+model+with+Enum+support+using+BlazeDS