0

In my JSF application there are several drop down menus, with an enum for my selectItems in the background.

Currently I am using an ApplcationScoped ManagedBean to pass them to my view:

@ManagedBean(name="applicationUtil")
@ApplicationScoped
public class ApplicationUtil implements Serializable {

    public MyEnum [] getValues() {
        return MyEnum.values();
    }
}

For better reusability I'd like to have something similar to e.g. the FacesValidator-Annotation to make it available in my JSF view. Somehting like

@Enum("com.stackoverflow.MyEnum")
public enum MyEnum {
    //
}

Is there something similar available for enums? I think this is a quite common task, but I didn't find a solution for this. Or maybe are there reasons why this would be a bad idea?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
stg
  • 2,757
  • 2
  • 28
  • 55
  • possible duplicate of [JSF 2.0: use Enum values for selectOneMenu](http://stackoverflow.com/questions/2868778/jsf-2-0-use-enum-values-for-selectonemenu) – Smutje Oct 16 '14 at 11:00
  • @Smutje I do not agree that this is a duplicate of that question, as that linked question is about how to use enums in jsf in general and how to use custom enum converters. All the provided solutions there are using some ManagedBean to pass the enum values to the JSf view and that is what I want to avoid. – stg Oct 16 '14 at 11:14
  • This is technically a duplicate of http://stackoverflow.com/questions/25077803/how-to-display-all-enum-values-as-available-items-of-hselectonemenu-with-enum/25334570#25334570 Do you agree? Here's a more general one: http://stackoverflow.com/questions/3732608/how-to-reference-constants-in-el – BalusC Oct 16 '14 at 12:50
  • @BalusC Thanks for the link. I like the approach with . But this is not completely what I was looking for. What I'd like to achieve finally, is that every neccessary information is provided by the enum-class itself. (like e.g. in FacesConverter) ... that way I would be able just to add the enum-class to my project and do not have to care about any further configuration in xml-files etc and it would have no influece if the package name changes etc.. – stg Oct 16 '14 at 12:59
  • I know. That just doesn't exist. – BalusC Oct 16 '14 at 13:00
  • Ok, I see ... thank you very much. I think I'll choose the omnifaces-approach then, as it seems to be the closest solution to my requirements. – stg Oct 16 '14 at 13:07

0 Answers0