I noticed that a replacement for the old EnumPropertySelectionModel is on the to-do list for Tapestry 4 at some point. I'm happy to contribute the one I cooked up as a starting point. It does the trick for me:

import java.util.ArrayList;
import java.util.EnumSet;

import org.apache.tapestry.form.IPropertySelectionModel;

public class EnumSelectionModel<E extends Enum<E>>
    implements IPropertySelectionModel {

    private Class<E> _type;
    private ArrayList<E> _options;

    public EnumSelectionModel (Class<E> type) {
        _type = type;
        _options = new ArrayList<E>();
        for (E e : EnumSet.allOf(type)) {
            _options.add(e);
        }
    }

    public int getOptionCount () {
        return _options.size();
    }

    public E getOption (int index) {
        return _options.get(index);
    }

    public String getLabel (int index) {
        return getOption(index).toString();
    }

    public String getValue (int index) {
        return getOption(index).name();
    }

    public Object translateValue (String value) {
        return Enum.valueOf(_type, value);
    }
}

Dustin


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to