cancel
Showing results for 
Search instead for 
Did you mean: 

getChildByName not working

gokceng
Champ in-the-making
Champ in-the-making
public static NodeRef findChildNodeRef(NodeRef parentSpaceNodeRef, String nodeName, ServiceRegistry serviceRegistry)
{
   NodeService nodeService = serviceRegistry.getNodeService();
   NodeRef nodeRef = nodeService.getChildByName(parentSpaceNodeRef, ContentModel.ASSOC_CONTAINS, ISO9075.encode(nodeName));
   return nodeRef;
}

I have a space tree like this:

RootSpace
    -
    |-Space1
    |    -
    |    |-ChildSpace1
    |    |-ChildSpace2
    |
    |
    |-Space2
        -
        |-ChildSpace3
        |-ChildSpace4
And Im calling

NodeRef Space1NodeRef = findChildNodeRef(RootSpaceNodeRef, "Space1", serviceRegistry);
NodeRef childSpace1NodeRef = findChildNodeRef(Space1NodeRef, "ChildSpace1", serviceRegistry);

And Space1NodeRef's value is correct but childSpace1NodeRef is null.

What can be the difference between these two spaces?
5 REPLIES 5

mrogers
Star Contributor
Star Contributor
Check using the Node Browser in Alfresco Explorer for the fully qualified association names of the nodes you are finding.  I suspect you will find a difference that will explain your problem.

gokceng
Champ in-the-making
Champ in-the-making
Thanks for reply.
I checked it. For RootSpace:
There is no entry for "Associations" but it has 1 child which has 'contains' association type.
For Space1:
There is no entry for "Associations" but it has 2 children which have 'contains' association types.

RootSpace's and Space1's types are 'folder'. But one of them is created by admin, the other one is by system.
Is that a problem?

mrogers
Star Contributor
Star Contributor
I don't think it is neccessary to encode the "name".   This is not a Lucene/XPATH search.

gokceng
Champ in-the-making
Champ in-the-making
Let me try that, too.
Thanks.

gokceng
Champ in-the-making
Champ in-the-making
I don't think it is neccessary to encode the "name".   This is not a Lucene/XPATH search.

You are right, I've removed encoding and it worked.
Thanks