Manually create result provider for dropdown selection list

The CAF object “dropdown - single-select dropdown” requires an Option or Option Group of type “SelectItem”, which are usually generated automatically using a Content Provider of type “com.webmethods.caf.faces.data.object.BoundPropertiesSelectItemGroupProvider”, associated with a service result set.

I need to create a set of selections manually in CAF, but so far have not been able to create a result provider and manipulate its contents, such as:

private com.webmethods.caf.faces.data.object.BoundPropertiesSelectItemGroupProvider resultProvider = null;
this.getResultProvider().getList().clear();
javax.faces.model.SelectItem item = new javax.faces.model.SelectItem();
item.setLabel(“SOME LABEL”);
item.setValue(“SOME VALUE”);
this.getResultProvider().getList().add(item);

The above does not work. Is there a better way to do this?
Thanks!

Ok, so I found a way to make it work, based on the SAG documentation for “BoundPropertiesSelectItemGroupProvider”:

I declared a bean managed property to store the provider:

private com.webmethods.caf.faces.data.object.BoundPropertiesSelectItemGroupProvider resultProvider = null;

Then, I created a class of my very own to store the items:

public class MyItem {
public String value;
public String label;
public MyItem() {}
public String getValue() {
return this.value;
}
public String getLabel() {
return this.label;
}
public void setLabel(String label) {
this.label=label;
}
public void setValue(String value) {
this.value=value;
}
}

Then in the view class I had to use my class to populate a List:

	    java.util.List list = new java.util.ArrayList();
	    MyItem item = new MyItem();
	    item.setLabel("label text");
	    item.setValue("value text");
	    list.add(item);

Then I added the list to the Provider:

	    this.resultProvider = new BoundPropertiesSelectItemGroupProvider(list, "item", "#{item.value}", "#{item.label}");

Finally I could bind the Option Group of the dropdown to the provider, and it works!

1 Like

Hi Paul -
Thanks for posting your resolution. I need to do something similar!

Hi

Thanks for this explanation - brilliant. Just a note to future generations: when you bind to this in your Option Group value, it (at least version 8.2) will show a warning saying:

Ignore this. A BoundPropertiesSelectItemGroupProvider falls into this category; it’s just a bug in the Designer warnings code.