Hi,
No need to implement this yourself, there is an EnumConverter in
myfaces-converters:
http://myfaces.apache.org/commons/index.html
Regards,
Volker
2010/5/1 Anton Gavazuk <[email protected]>:
> Hi Jozef,
>
> see it:
>
> public class EnumConverter implements Converter {
> public Object getAsObject(FacesContext context, UIComponent comp, String
> value) throws ConverterException {
> Class enumType = comp.getValueBinding("value").getType(context);
> return Enum.valueOf(enumType, value);
> }
>
> public String getAsString(FacesContext context, UIComponent component,
> Object object) throws ConverterException {
> if (object == null) {
> return null;
> }
>
> if (object instanceof String) {
> return (String) object;
> }
>
> //ADD localization ability
> Enum type = (Enum) object;
> return type.name();
> }
> }
>
>
> 2010/5/1 Jozef Dropco <[email protected]>
>
>> Hi all,
>> I have a little bit stupid question. I got this message: End of weekend:
>> 'Tuesday' must be convertible to an enum from the enum that contains the
>> constant 'Tuesday'. Do I have to write my own converter or what should I do.
>>
>> public enum DayOfWeek {
>>
>> MONDAY("Monday"),
>> TUESDAY("Tuesday"),
>> WEDNESDAY("Wednesday"),
>> THURSDAY("Thursday"),
>> FRIDAY("Friday"),
>> SATURDAY("Saturday"),
>> SUNDAY("Sunday");
>> private String name;
>> }
>>
>> ***BEAN***
>> for (DayOfWeek day :DayOfWeek.values()){
>> days.add(new SelectItem(day, day.getName()));
>> }
>> ***XHTML***
>> <tr:selectOneChoice required="true" label="End of weekend"
>> value="#{addWeekendDiscount.weekend.endWeekend}">
>> <f:selectItems value="#{addWeekendDiscount.days}"/>
>> </tr:selectOneChoice>
>>
>>
>> Thanks Jozef.
>>
>
--
inexso - information exchange solutions GmbH
Bismarckstraße 13 | 26122 Oldenburg
Tel.: +49 441 4082 356 |
FAX: +49 441 4082 355 | www.inexso.de