You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Ivan <xh...@gmail.com> on 2011/06/13 04:58:44 UTC

Both child and facet list should be checked while moving an existing child ?

Hi,
    Per the Java doc of
http://javaserverfaces.java.net/nonav/docs/2.0/javadocs/javax/faces/component/UIComponent.html#getChildren(),
if I set an existing child in the returned children list, the target child
should be removed from its previous parent in both children and facet list.
While currently MyFaces seems only remove from the children list. And for
the facet map, now it only remove from the facet map. Is it a bug for
MyFaces ?
    --->
getChildren

public abstract List<UIComponent> getChildren()

Return a mutable List representing the child UIComponents associated with
this component. The returned implementation must support all of the standard
and optional List methods, plus support the following additional
requirements:

The List implementation must implement the java.io.Serializable interface.
Any attempt to add a null must throw a NullPointerException
Any attempt to add an object that does not implement UIComponent must throw
a ClassCastException.
*Whenever a new child component is added, the parent property of the child
must be set to this component instance. If the parent property of the child
was already non-null, the child must first be removed from its previous
parent (where it may have been either a child or a facet).*
Whenever an existing child component is removed, the parent property of the
child must be set to null.

After the child component has been added to the view, if the following
condition is not met:

FacesContext.isPostback() returns true and
FacesContext.getCurrentPhaseId() returns PhaseId.RESTORE_VIEW

Application.publishEvent(javax.faces.context.FacesContext, java.lang.Class,
java.lang.Object) must be called, passing PostAddToViewEvent.class as the
first argument and the newly added component as the second argument.

--
Ivan

Re: Both child and facet list should be checked while moving an existing child ?

Posted by Leonardo Uribe <lu...@gmail.com>.
Hi

Checking the code I see that
_ComponentChildrenList.removeChildrenFromParent do this:

    private void removeChildrenFromParent(UIComponent child)
    {
        UIComponent oldParent = child.getParent();
        if (oldParent != null)
        {
            oldParent.getChildren().remove(child);
        }
    }

so, when set is called:

    @Override
    public UIComponent set(int index, UIComponent value)
    {
        checkValue(value);
        removeChildrenFromParent(value);
        UIComponent child = _list.set(index, value);
        if (child != value)
        {
            updateParent(value);
            if (child != null)
            {
                child.setParent(null);
            }
        }

        return child;
    }

if the component is on a facet, it will not be removed. Sounds like a
bug, but note that code is not very common so it could be good to know
the intention behind this. Please create a bug on myfaces issue
tracker.

https://issues.apache.org/jira/browse/MYFACES

regards,

Leonardo Uribe

2011/6/14 Ivan <xh...@gmail.com>:
> Any thought for this, thanks !
>
> 2011/6/13 Ivan <xh...@gmail.com>
>
>> Hi,
>>     Per the Java doc of
>> http://javaserverfaces.java.net/nonav/docs/2.0/javadocs/javax/faces/component/UIComponent.html#getChildren(),
>> if I set an existing child in the returned children list, the target child
>> should be removed from its previous parent in both children and facet list.
>> While currently MyFaces seems only remove from the children list. And for
>> the facet map, now it only remove from the facet map. Is it a bug for
>> MyFaces ?
>>     --->
>> getChildren
>>
>> public abstract List<UIComponent> getChildren()
>>
>> Return a mutable List representing the child UIComponents associated with
>> this component. The returned implementation must support all of the standard
>> and optional List methods, plus support the following additional
>> requirements:
>>
>> The List implementation must implement the java.io.Serializable interface.
>> Any attempt to add a null must throw a NullPointerException
>> Any attempt to add an object that does not implement UIComponent must throw
>> a ClassCastException.
>> *Whenever a new child component is added, the parent property of the child
>> must be set to this component instance. If the parent property of the child
>> was already non-null, the child must first be removed from its previous
>> parent (where it may have been either a child or a facet).*
>> Whenever an existing child component is removed, the parent property of the
>> child must be set to null.
>>
>> After the child component has been added to the view, if the following
>> condition is not met:
>>
>>
>> FacesContext.isPostback() returns true and FacesContext.getCurrentPhaseId() returns PhaseId.RESTORE_VIEW
>>
>> Application.publishEvent(javax.faces.context.FacesContext, java.lang.Class,
>> java.lang.Object) must be called, passing PostAddToViewEvent.class as the
>> first argument and the newly added component as the second argument.
>>
>> --
>> Ivan
>>
>
>
>
> --
> Ivan
>

Re: Both child and facet list should be checked while moving an existing child ?

Posted by Ivan <xh...@gmail.com>.
Any thought for this, thanks !

2011/6/13 Ivan <xh...@gmail.com>

> Hi,
>     Per the Java doc of
> http://javaserverfaces.java.net/nonav/docs/2.0/javadocs/javax/faces/component/UIComponent.html#getChildren(),
> if I set an existing child in the returned children list, the target child
> should be removed from its previous parent in both children and facet list.
> While currently MyFaces seems only remove from the children list. And for
> the facet map, now it only remove from the facet map. Is it a bug for
> MyFaces ?
>     --->
> getChildren
>
> public abstract List<UIComponent> getChildren()
>
> Return a mutable List representing the child UIComponents associated with
> this component. The returned implementation must support all of the standard
> and optional List methods, plus support the following additional
> requirements:
>
> The List implementation must implement the java.io.Serializable interface.
> Any attempt to add a null must throw a NullPointerException
> Any attempt to add an object that does not implement UIComponent must throw
> a ClassCastException.
> *Whenever a new child component is added, the parent property of the child
> must be set to this component instance. If the parent property of the child
> was already non-null, the child must first be removed from its previous
> parent (where it may have been either a child or a facet).*
> Whenever an existing child component is removed, the parent property of the
> child must be set to null.
>
> After the child component has been added to the view, if the following
> condition is not met:
>
>
> FacesContext.isPostback() returns true and FacesContext.getCurrentPhaseId() returns PhaseId.RESTORE_VIEW
>
> Application.publishEvent(javax.faces.context.FacesContext, java.lang.Class,
> java.lang.Object) must be called, passing PostAddToViewEvent.class as the
> first argument and the newly added component as the second argument.
>
> --
> Ivan
>



-- 
Ivan