I write solutions to the problems I can't find much about elsewhere on the Web, also some code/script snippets that are absolutely awesome and make my life easier. Will be glad if someone finds these posts interesting and helpful!

Monday, May 3, 2010

“javax.faces.convert.ConverterException: Unsupported Model Type” in ADF 10g for selectManyCheckbox

There’s a mess with the selectManyCheckbox bindings: for both initial list items and selected items. ADF itself doesn’t support direct binding to a ViewObject, and that’s why, as Frank Nimphius said,
…you would need to use a managed bean to dispatch between the ADF binding layer and the multi select component.
Maybe it’s just me, but it took me a while to figure out how exactly to do it.


First off, the managed bean. It should contain fields with accessors for two lists: the initial options and the selected items.
ArrayList<javax.faces.model.SelectItem> initialListItems;
public ArrayList getInitialListItems() {
if(initialListItems == null) {
initialListItems = new ArrayList();
JUIteratorBinding paramIter =
(JUIteratorBinding)JSFUtils.resolveExpression("#{bindings.ParamView1Iterator}");
for(int i = 0; i < paramIter.getEstimatedRowCount(); i++) {
ParamViewRowImpl paramRow = (ParamViewRowImpl)paramIter.getRowAtRangeIndex(i);
SelectItem si = new SelectItem();
si.setValue(paramRow.getParamkey());
si.setLabel(paramRow.getParamvalue());
initialListItems.add(si);
}
}
return initialListItems;
}
java.util.List selectedItems;
public void setSelectedItems(List selectedItems) {
this.selectedItems = selectedItems;
}
public List getSelectedItems() {
return selectedItems;
}
view raw gistfile1.java hosted with ❤ by GitHub

The initialListItems will be bound to the multi-selection items element. Whilst the selectedItems list will contain the selected items from the initial list. The important thing is the datatype for the latter – a java.util.List! In fact it’s what provokes the “Unsupported Model Type” exception. This datatype hassle was actually the part that took me a real while to get it, I tried primitive array, ArrayList of String’s, Object’s and what not!
Now the only thing left is to bind both lists to the multi-selection component.
<af:selectManyCheckbox value="#{ManagedBean.selectedItems}">
<f:selectItems value="#{ManagedBean.initialListItems}"/>
</af:selectManyCheckbox>
view raw gistfile1.xml hosted with ❤ by GitHub

No more exceptions. That's it, hope it helps!

No comments:

Post a Comment