• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

SelectManyListbox converter problem

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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>
-------------------------------------------------------------------------
 
author
Posts: 9050
21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi XiaoPeng,

Welcome to the ranch! We've found that if people use their real first AND last names, things stay friendlier, so I'd ask you to update your display name to match that policy.

Thanks,

Bert
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic