How do I get selectManyCheckBox to return something other than List?

前端 未结 1 395
独厮守ぢ
独厮守ぢ 2020-12-21 03:51

This is a pattern that I would use over and over again if I get it to work. I have an enum name Log.LogKey that I want to user to pick out instances of. So the facelet has

相关标签:
1条回答
  • 2020-12-21 03:58

    You need to specify a converter. JSF EL is not aware about the generic List type because that's lost during runtime. When you do not explicitly specify a converter, JSF will not convert the submitted String values and plain fill the list with them.

    In your particular case, you can make use of the JSF builtin EnumConverter, you just have to super() the enum type in the constructor:

    package com.example;
    
    import javax.faces.convert.EnumConverter;
    import javax.faces.convert.FacesConverter;
    
    @FacesConverter(value="logKeyConverter")
    public class LogKeyConverter extends EnumConverter {
    
        public LogKeyConverter() {
            super(Log.LogKey.class);
        }
    
    }
    

    To use it, just declare it as follows:

    <h:selectManyCheckbox value="#{test.selectedKeys}" converter="logKeyConverter">
        ...
    </h:selectManyCheckbox>
    

    See also:

    • Use enum in h:selectManyCheckbox
    0 讨论(0)
提交回复
热议问题