I have a SelectManyListbox with a custom converter for my TestCase class. I can set the SelectItem to properly accept a TestCase object with a label. I know that because the listbox displays properly. This means that the overridden Converter.getAsString method is doing its job. The problem comes when I submit the form. Normally, the setter method of a bean's array/arrayList would be called when the form is submitted. But in my case, it doesn't get invoked. Thus, my backing bean TeseCase array/ArrayList doesn't get populated. What's strange is that there are no errors or exceptions thrown either. Has anyone come across this problem before that can give me some pointers?
Thanks in advance.
Here's the Converter class:
public class TestCaseConverter implements Converter {
public Object getAsObject(FacesContext arg0, UIComponent arg1,
String testCaseString)
throws ConverterException {
if (StringUtils.isEmpty(testCaseString)) {
return null;
}
System.out.println("*********************IN GETASOBJECT: "+ testCaseString + " *****************");
int descriptionIndex = testCaseString.indexOf("description");
int beginDescriptionIndex = testCaseString.indexOf("\"", descriptionIndex);
int endDescriptionIndex = testCaseString.indexOf("\"", beginDescriptionIndex+1);
String testcaseDescription = testCaseString.substring(beginDescriptionIndex+1, endDescriptionIndex);
return new TestCase(testCaseString, testcaseDescription);
}
public String getAsString(FacesContext arg0, UIComponent arg1, Object arg2)
throws ConverterException {
return arg2.toString();
}
}
------------------------------------------------------------------------
Here's the TestCase class:
public class TestCase {
private String description;
private String xmlForm;
public TestCase() {
description = null;
xmlForm = null;
}
public TestCase(String xml, String desc) {
xmlForm = xml;
description = desc;
}
public String getDescription() {
return description;
}
public void setDescription(String desc) {
description = desc;
}
public String getXmlForm() {
return xmlForm;
}
public void setXmlForm(String xml) {
xmlForm = xml;
}
public String toString() {
return xmlForm;
}
}
------------------------------------------------------------------------
Here's the
JSP:
<h:form id="testCaseListForm" rendered="#{InputFileParserBean.testCaseListFilled}">
<h:panelGrid columns="2">
<t:outputText value="Test Cases"/>
<h:selectManyListbox id="testCaseList" value="#{RunTestcaseBean.selectedTestcases}"
converter="TestCaseConverter"
required="true" >
<f:selectItems value="#{InputFileParserBean.testCaseList}"/>
</h:selectManyListbox>
<t:commandButton action="#{RunTestcaseBean.runTestcases}"
value="Run Test"/>
</h:panelGrid>
</h:form>
-------------------------------------------------------------------------