I still have problem with selectManyCheckBox..
selectManyCheckBox:
<p:selectManyCheckbox converter="genericEnumConverter" value="#{aView.newObject.aValue}">
<f:selectItems value="#{enumBean.aValueValues}" var="s" itemValue="#{s}" itemLabel = "#{s.name}"/>
</p:selectManyCheckbox>
Converter for this selectManyCheckBox is the same as described here: Use enum in h:selectManyCheckbox
@FacesConverter("genericEnumConverter")
public class GenericEnumConverter implements Converter {
private static final String ATTRIBUTE_ENUM_TYPE = "GenericEnumConverter.enumType";
@Override
public String getAsString(FacesContext context, UIComponent component, Object value) {
System.out.println("getAsString 1: ");
if (value instanceof Enum) {
System.out.println("getAsString 2: ");
component.getAttributes().put(ATTRIBUTE_ENUM_TYPE, value.getClass());
System.out.println("getAsString 3: ");
return ((Enum<?>) value).name();
} else {
System.out.println("getAsString 4: ");
throw new ConverterException(new FacesMessage("Value is not an enum: " + value.getClass()));
}
}
@Override
@SuppressWarnings({"rawtypes", "unchecked"})
public Object getAsObject(FacesContext context, UIComponent component, String value) {
System.out.println("getAsObject 1: ");
Class<Enum> enumType = (Class<Enum>) component.getAttributes().get(ATTRIBUTE_ENUM_TYPE);
System.out.println("getAsObject 2: ");
try {
System.out.println("getAsObject 3: ");
return Enum.valueOf(enumType, value);
} catch (IllegalArgumentException e) {
System.out.println("getAsObject 4: ");
throw new ConverterException(new FacesMessage("Value is not an enum of type: " + enumType));
}
}
The enum is:
public enum aValue {
1Value,
2Value,
3Value,
4Value;
private final String name;
private aValue() {
System.out.println("aValue 1");
this.name = null;
System.out.println("aValue 2");
}
public String getName() {
System.out.println("getName 1 " + name());
return ResourceBundleUtil.getLabelFromRb("aValue." + name());
}
}
public aValue[] getAValueValues() {
return AValue.values();
}
Tomcat Logs are:
aValue 1
aValue 2
aValue 1
aValue 2
aValue 1
aValue 2
aValue 1
aValue 2
aValue 1
aValue 2
aValue 1
aValue 2
aValue 1
aValue 2
aValue 1
aValue 2
aValue 1
aValue 2
getName 1Value
getName 2Value
getName 3Value
getName 4Value
getAsString 1:
getAsString 2:
getAsString 3:
getAsString 1:
getAsString 2:
getAsString 3:
getAsString 1:
getAsString 2:
getAsString 3:
getAsString 1:
getAsString 2:
getAsString 3:
getAsString 1:
getAsString 2:
getAsString 3:
getAsString 1:
getAsString 2:
getAsString 3:
getAsString 1:
getAsString 2:
getAsString 3:
getAsString 1:
getAsString 2:
getAsString 3:
getAsString 1:
getAsString 2:
getAsString 3:
getName 1Value
getName 2Value
getName 3Value
getName 4Value
getAsString 1:
getAsString 2:
getAsString 3:
getAsString 1:
getAsString 2:
getAsString 3:
getAsString 1:
getAsString 2:
getAsString 3:
getAsString 1:
getAsString 2:
getAsString 3:
getAsString 1:
getAsString 2:
getAsString 3:
getAsString 1:
getAsString 2:
getAsString 3:
getAsString 1:
getAsString 2:
getAsString 3:
getAsString 1:
getAsString 2:
getAsString 3:
getAsString 1:
getAsString 2:
getAsString 3:
When I press save button, nothing happens and nothing is saved into database. It looks like it is not going into getAsObject method. I don't know why. When I change the component into a SelectOneMenu there is no problem. But this selectManyCheckBox thing is not working. Does anyone have any idea?