I am in the process of learning JSF and have been working on this for some number of days with no success. I have an Enum and want to display its values on a page as checkboxes and have those populate a bean when submitted. It never seems to even try to populate the bean as i never see setFeatures get called. The only message i get back is
Validation Error "Features": Value is not a valid option.
Despite many hours, I cannot get it to work. Please let me know if you see what I am doing wrong.
JSP
-----------------------
<h:outputText value="#{pageMsgs.features
Label}"/>
<h:selectManyCheckbox value="#{pWizard.features}
" layout="pageDirection" id="Features">
<f:selectItems value="#{pWizard.featureTy
pes}" />
</h:selectManyCheckbox>
-----------------------
Java File
-----------------------
//Feature methods
public List<SelectItem> getFeatureTypes(){
List<SelectItem> types = new LinkedList<SelectItem>();
for( FeatureTypes type : FeatureTypes.values() ){
types.add(new SelectItem( type, type.toString() ) );
}
return types;
}
public List<FeatureTypes> getFeatures(){
FProduct t=getTemplate();
if (features==null){
features = new LinkedList<FeatureTypes>()
;
ListIterator<FFeature> i = t.getFeatures().listIterat
or();
while( i.hasNext() ){
features.add( i.next().getType() );
}
}
return features;
}
public void setFeatures(List<FeatureTy
pes> featList){
FProduct t=getTemplate();
ListIterator<FeatureTypes>
li = featList.listIterator();
LinkedList<FFeature> ffList = new LinkedList<FFeature>();
while( li.hasNext() ){
FeatureTypes ftype = li.next();
ffList.add( new FFeature(ftype) );
}
features=featList;
t.setFeatures(ffList);
}
private FProduct template=null;
List<FeatureTypes> features;
-----------------------
And I found this Enum converter while wandering around on Google, doesnt seem to help with much, I dont ever see the getAsObject method called, although JSF loves the getAsString method.
Enum Converter
-----------------------
public class EnumTypeConverter implements Converter {
public Object getAsObject(FacesContext context, UIComponent comp, String value) throws ConverterException {
Class enumType = comp.getValueBinding("valu
e").getTyp
e(context)
;
return Enum.valueOf(enumType,valu
e);
}
public String getAsString(FacesContext context, UIComponent comp, Object object) throws ConverterException {
if (object == null) {
return null;
}
Enum type = (Enum) object;
return type.toString();
}
}
------------------------
faces-config.xml
------------------------
<converter>
<converter-for-class>java.
lang.Enum<
/converter
-for-class
>
<converter-class>util.face
s.EnumType
Converter<
/converter
-class>
</converter>
-------------------------
Help.... any ideas?