Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
package org.cdlflex.ui.markup.html.form;
A DropDownChoice that gets its choices from an enum type.

Parameters:
<T> The specific enum type.
public class EnumDropDownChoice<T extends Enum<T>> extends DropDownChoice<T> {
    private static final long serialVersionUID = 1L;
    public EnumDropDownChoice(String idClass<T> enumType) {
        this(idnullenumType);
    }
    public EnumDropDownChoice(String idIModel<T> modelClass<T> enumType) {
        this(idmodelenumTypenew DefaultEnumChoiceRenderer<T>());
    }
    public EnumDropDownChoice(String idClass<T> enumTypeIChoiceRenderer<T> choiceRenderer) {
        this(idnullenumTypechoiceRenderer);
    }
    public EnumDropDownChoice(String idIModel<T> modelClass<T> enumTypeIChoiceRenderer<T> choiceRenderer) {
        super(idmodelmodelOf(enumType), choiceRenderer);
    }

    
Creates a new WildcardListModel for all values of the given enum type.

Parameters:
enumType the enum type class
<E> the enum type
Returns:
a new WildcardListModel
    public static <E extends EnumWildcardListModel<E> modelOf(Class<E> enumType) {
        return new WildcardListModel<>(getEnumValues(enumType));
    }

    
Returns a list of all enum constants of the given enum type.

Parameters:
enumType the enum type class
<E> the enum type
Returns:
a list of enum values
    public static <E extends EnumList<E> getEnumValues(Class<E> enumType) {
        return Arrays.asList(enumType.getEnumConstants());
    }

    
A IChoiceRenderer that renders enum values by capitalizing their name and replacing all underscores with whitespaces.

Parameters:
<E> the enum type
    public static class DefaultEnumChoiceRenderer<E extends Enum<E>> extends EnumRenderer<E> implements
            IChoiceRenderer<E> {
        private static final long serialVersionUID = 1L;
        @Override
        public Object getDisplayValue(E object) {
            return convertToString(object);
        }
        @Override
        public String getIdValue(E objectint index) {
            return object.name();
        }
    }
New to GrepCode? Check out our FAQ X