Java Code Examples for javax.faces.component.UIComponent.setParent()

The following are Jave code examples for showing how to use setParent() of the javax.faces.component.UIComponent class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: myfaces-trinidad   File: ChildArrayList.java   Source Code and License Vote up 6 votes
@Override
public void add(int index, UIComponent element)
{
  if (element == null)
    throw new NullPointerException();

  if ((index < 0) || (index > size()))
    throw new IndexOutOfBoundsException(_LOG.getMessage(
      "INDEX_SIZE", new Object[]{index, size()}));

  UIComponent oldParent = element.getParent();
  if (oldParent != null)
  {
    int adjustedIndex = __removeFromParent(element, index);
    // Only adjust the index when the child is re-added to the same parent
    if (oldParent == _parent)
    {
      index = adjustedIndex; 
    }
  }
  
  // do not change the order of these calls, see TRINIDAD-1674 for more info
  super.add(index, element);
  element.setParent(_parent);
}
 
Example 2
Project: myfaces-trinidad   File: ChildArrayList.java   Source Code and License Vote up 6 votes
@Override
public boolean remove(Object element)
{
  if (element == null)
    throw new NullPointerException();
  
  if (!(element instanceof UIComponent))
    return false;

  if (super.remove(element))
  {
    UIComponent child = (UIComponent) element;
    child.setParent(null);
    return true;
  }

  return false;
}
 
Example 3
Project: myfaces-trinidad   File: ChildArrayList.java   Source Code and License Vote up 6 votes
@Override
public UIComponent set(int index, UIComponent element)
{
  if (element == null)
    throw new NullPointerException();
  
  if ((index < 0) || (index >= size()))
    throw new IndexOutOfBoundsException();

  UIComponent child = element;
  UIComponent previous = get(index);

  previous.setParent(null);
  
  child.setParent(_parent);
  super.set(index, element);
  
  return previous;
}
 
Example 4
Project: myfaces-trinidad   File: FacetHashMap.java   Source Code and License Vote up 6 votes
@Override
public UIComponent put(String key, UIComponent value)
{
  if ((key == null) || (value == null))
  {
    throw new NullPointerException();
  }

  UIComponent previous = super.get(key);
  if (previous != null)
  {
    previous.setParent(null);
  }
  
  if (value.getParent() != null)
  {
    ChildArrayList.__removeFromParent(value, -1);
  }
  
  // calling setParent triggers an addEvent, which might have listeners, 
  // so first put the component in the map, then set the parent
  UIComponent comp = super.put(key, value);
  value.setParent(_parent);
  return comp;
}
 
Example 5
Project: myfaces-trinidad   File: ChildArrayList.java   Source Code and License Vote up 5 votes
@Override
public UIComponent remove(int index)
{
  UIComponent child = super.remove(index);
  child.setParent(null);

  return child;
}
 
Example 6
Project: myfaces-trinidad   File: FacetHashMap.java   Source Code and License Vote up 5 votes
@Override
public void clear()
{
  for(UIComponent value : values())
  {
    value.setParent(null);
  }

  super.clear();
}
 
Example 7
Project: myfaces-trinidad   File: FacetHashMap.java   Source Code and License Vote up 5 votes
@Override
public UIComponent remove(Object key)
{
  UIComponent previous = super.remove(key);
  if (previous != null)
  {
    previous.setParent(null);
  }
  
  return (previous);
}