I know this is not supported in UIData and I understand why, but this should be a common issue for people using JPA and JSF since Sets are the superior collection when mappi
Something easier, support for Set
(actually, the entire Collection
interface) in DataModel
is available in JSF 2.2. It's currently already available as snapshot so that you can just start developing. It will be released around Q2.
Update: as per the comments, it didn't seem to quite work seamlessly together with Spring Web Flow. It turns out that it's not JSF 2.2 compatible (and initially also not JSF 2.1 compatible). Well, a custom ELResolver
should be your best bet.
Easiest is to let it extend ListELResolver
as follows:
public class SetToListELResolver extends ListELResolver {
public static final String KEY_PROPERTY = "setToList";
@Override
public Object getValue(ELContext context, Object base, Object property) {
if (base instanceof Set<?> && KEY_PROPERTY.equals(property)) {
context.setPropertyResolved(true);
return new ArrayList<Object>((Set<?>) base);
}
return super.getValue(context, base, property);
}
}
If you register it as follows in faces-config.xml
<application>
<el-resolver>com.example.SetToListELResolver</el-resolver>
</application>
then you'll be able to use it in the syntax of #{bean.set.setToList}
wherein the .setToList
is a special property which will trigger the conversion:
<h:dataTable value="#{bean.set.setToList}" ...>
It will effectively end up in a fictive
<h:dataTable value="#{new ArrayList(bean.set)}" ...>