1 Reply Latest reply on Oct 16, 2006 8:03 AM by gavin.king

    FacesMessages with components in dataList

      There is a problem with the FacesMessages implementation for JSF components within in a dataList. The problem is really caused by the poor implementation of dataList component ID's in MyFaces and how a component in a dataList cannot be instantiated by recursively searching through the JSF tree, as is done in FacesMessages getClientId method:

       private static String getClientId(UIComponent component, String id, FacesContext facesContext)
       {
       String componentId = component.getId();
       if (componentId!=null && componentId.equals(id))
       {
       return component.getClientId(facesContext);
       }
       else
       {
       Iterator iter = component.getFacetsAndChildren();
       while ( iter.hasNext() )
       {
       UIComponent child = (UIComponent) iter.next();
       String clientId = getClientId(child, id, facesContext);
       if (clientId!=null) return clientId;
       }
       return null;
       }
       }
      
      


      This method will return null every time FacesMessages is used to "add" an error message for a component within a dataList as no component will ever match the "id" parameter if that component is in a dataList.

      Gavin - I think it would be better for getClientId to at least accomodate this MyFaces flaw by returning the "id" parameter instead of null when no component is found. That way, messages can be added through FacesMessages using the full component's client ID if that component is within a dataList (e.g. myForm:myList:0:myComponent). It's not as nice as being able to pass in "myComponent" as the ID directly, but at least it doesn't return null which prevents adding messages altogether.

        • 1. Re: FacesMessages with components in dataList
          gavin.king

          I think this problem can't be properly solved without JSF 1.2, which provides a findByClientId() method on UIComponent.

          For once, this is not actually MyFaces fault, this is a JSF 1.1 spec limitation. (Well, it is MyFaces fault that they *still* don't support JSF 1.2.)