1 Reply Latest reply on Oct 16, 2006 8:03 AM by Gavin King

    FacesMessages with components in dataList

    ngeadah Newbie

      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.