4 Replies Latest reply on Mar 19, 2008 6:47 AM by Fab Mars

    Is it a bug?

    chen liang Newbie

      I use Seam2.0.1GA . My code is very simple like this:

      <rich:dataTable var="ro" value="#{selectedGroup.roles}"
       rendered="#{not empty selectedGroup.roles}">
       <h:column>
       <f:facet name="header">Description</f:facet>
       #{ro.roleDesc}
       </h:column>
       <h:column>
       <f:facet name="header">Name</f:facet>
       #{ro.roleName}
       </h:column>
       <h:column>
       <f:facet name="header">actionœ</f:facet>
       <a4j:commandButton action="#{assignRoleToGroup.dropRole(ro)}"
       value="Delete" reRender="rlForm">
       </a4j:commandButton>
       </h:column>
       </rich:dataTable>

      selectedGroup.roles is a Set object, It dosnt work, tells ro is a Set, after I change selectedGroup.roles to be a List Object, it's ok.
      Is it possible to set a Set object to value of dataTable?

        • 1. Re: Is it a bug?
          Sergey Smirnov Master

          rich:dataTable as well as any other dataTable in JSF does not support Set directly as soon as Set does not guaranty the order of the elements.
          You need to write you own dataModel

          • 3. Re: Is it a bug?
            Fab Mars Novice

            Common issue in the JSF world. Here is some resolver I made (it's based on some JSF 1.1 code I found using Google, but here uses EL / JSF 1.2 compliant code)

            package what.you.want;
            
            import java.beans.FeatureDescriptor;
            import java.util.ArrayList;
            import java.util.Collection;
            import java.util.Iterator;
            import java.util.List;
            
            import javax.el.ELContext;
            import javax.el.ELResolver;
            import javax.el.PropertyNotWritableException;
            
            
            public class ToListResolver extends ELResolver {
            
             private static String resolverWord = "toList";
            
            
             @Override
             public Class<?> getCommonPropertyType(ELContext context, Object base) {
             if (base != null && base instanceof Collection) {
             return Collection.class;
             }
             return null;
             }
            
             @Override
             public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context, Object base) {
             return null;
             }
            
             @Override
             public Class<?> getType(ELContext context, Object base, Object property) {
             if (base != null && base instanceof Collection) {
             if(resolverWord.equals(property)) {
             context.setPropertyResolved(true);
             return List.class;
             }
             }
             return null;
             }
            
             @Override
             public Object getValue(ELContext context, Object base, Object property) {
             if (base != null && base instanceof Collection) {
             if(resolverWord.equals(property)) {
             context.setPropertyResolved(true);
             return new ArrayList<Object>((Collection<?>)base);
             }
             }
             return null;
             }
            
             @Override
             public boolean isReadOnly(ELContext context, Object base, Object property) {
             if (base != null && base instanceof Collection) {
             if(resolverWord.equals(property)) {
             context.setPropertyResolved(true);
             return true;
             }
             }
             return true;
             }
            
             @Override
             public void setValue(ELContext context, Object base, Object property, Object value) {
             if (base != null && base instanceof Collection) {
             if(resolverWord.equals(property)) {
             context.setPropertyResolved(true);
             throw new PropertyNotWritableException();
             }
             }
             }
            
            }
            


            Register it in your faces-config with:
            <application>
             <el-resolver>what.you.want.ToListResolver</el-resolver>
             </application>
            


            • 4. Re: Is it a bug?
              Fab Mars Novice

              ...and you can write in your jsf pages:

              <rich:dataTable var="ro" value="#{selectedGroup.roles.toList}">