Hello all.
I have an odd problem with Tomahawk and a converter.

I have created a converter that accepts a ; separated value.
However, when i try to use it, the following happens:

/protected/richtest.xhtml @87,69 value="#{answerBean.alternative}": Exception setting property alternative of base with class org.evatest.web.beans.AnswerBean, Bean: org.evatest.web.beans.AnswerBean, property: alternative, newValue: null ,newValue class: null method parameter class: org.evatest.xml.Alternative, null, null


My converter class.

public class AlternativeConverter implements Converter {
   private Log log = LogFactory.getLog(getClass());

public Object getAsObject(FacesContext facesContext, UIComponent uiComponent, String string) throws ConverterException {
       if (string == null) return null;
       Alternative a = new Alternative();
       log.debug(string);
       String[] splitted = string.split(";");
       a.setId(Integer.parseInt(splitted[0]));         // id
       a.setText(splitted[1]);                         // text
       a.setWeight(Integer.parseInt(splitted[2]));     // weight
       a.setCertainty(Integer.parseInt(splitted[3]));  // certainty
log.debug(a.getId() + " " + a.getText() + " " + a.getWeight()); // resource ?
       // points ??
       return a;
   }

public String getAsString(FacesContext facesContext, UIComponent uiComponent, Object object) throws ConverterException {
       if (object == null || !(object instanceof Alternative)) return null;
       Alternative a = (Alternative) object;
return a.getId() + ";" + a.getText() + ";" + a.getWeight() + ";" + a.getCertainty();
   }
}

Its configured in faces-config.xml as this:

   <converter>
       <converter-id>evatest.EnumConverter</converter-id>
<converter-class>org.evatest.web.converter.EnumConverter</converter-class>
   </converter>


Is there anything immediate wrong that you can see?


example snippet for use:

<t:selectManyCheckbox id="checkboxlist" rendered="#{visit.answer.question.multipleChoice}"
                                     layout="pageDirection"
converter="evatest.AlternativeConverter"
                                     value="#{answerBean.alternatives}">

                   <f:selectItems value="#{questionBean.alternatives}"/>
</t:selectManyCheckbox>

The selectitems are created like this:

public List<SelectItem> getAlternatives() {
       List<SelectItem> list = new ArrayList<SelectItem>();
for (Alternative a : JSFUtil.getVisit().getAnswer().getQuestion().getAlternatives()) {
           list.add(new SelectItem(a, a.getText()));
       }
       return list;
   }



Thank you in advance.

Regards

Erlend Hamnaberg

Reply via email to