This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JSF and the fly likes SelectManyListbox converter problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "SelectManyListbox converter problem" Watch "SelectManyListbox converter problem" New topic
Author

SelectManyListbox converter problem

XiaoPeng
Greenhorn

Joined: May 25, 2007
Posts: 3
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">
<tutputText 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>
-------------------------------------------------------------------------
Bert Bates
author
Sheriff

Joined: Oct 14, 2002
Posts: 8804
    
    5
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


Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: SelectManyListbox converter problem
 
Similar Threads
inputRichText with Hexadecimal formatted data
selectManyListbox - IllegalArgumentException
getAsObject never called
Custom Converter : no action
h:selectOneMenu - setting the correct value