Enum Constant

  • Medasha Govender


    I have a field of type Enum. The constants of the field are "Yes, No and Omit". However, under certain circumstances I would like the constants to be "Yes and No" only. "Omit" should not be displayed in the combo. My field is defined as follows:

    @Column(name="statement", length=1)
    properties={@PropertyValue(name="enumType", value="org.openxava.salary.model.Employee$Statement"),
    @PropertyValue(name="value", value="Yes")

                @Parameter( name="letters", value="YNO"), 
                @Parameter(name="enumType", value="org.openxava.salary.model.Employee$Statement")

    private Statement statement;

    public enum Statement{Yes, No, Omit};

    I am not sure how to do this. Any help will be greatly appreciated.



  • Javier Paniza

    Javier Paniza - 2013-09-02

    Hi Med,

    by default OpenXava displays all the available options of the enum, so we have to think in some trick to solve your case.

    For now, I have 3 ideas:
    1. Create a transient property with another enum and move from this transient property to the persistent one on @PrePersist/@PreUpdate. You can hide/show the corresponding property depending on your condition, or just to have two views.
    2. Create a alternate @Editor that show only YES/NO and use it in other view. You can switch the view programmatically.
    3. Create your own editor for that property.

    Help others in this forum as I help you.
    Need more help? Get OpenXava professional support.

  • Medasha Govender

    Hi Javier,

    Thank u. I will give it a try.




Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.

No, thanks