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

The following are Jave code examples for showing how to use getFacets() 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: Structure.java   Source Code and License Vote up 5 votes
/**
 * Re-create a component from a structure object
 */
@SuppressWarnings("unchecked")
public UIComponent createComponent()
  throws ClassNotFoundException, InstantiationException,
         IllegalAccessException
{
  Class<?> clazz = ClassLoaderUtils.loadClass(_class);
  UIComponent component = (UIComponent) clazz.newInstance();
  if (_id != null)
    component.setId(_id);
  // Create any facets
  if (_facets != null)
  {
    Map<String, UIComponent> facets = component.getFacets();
    for (int i = 0 ; i < _facets.size(); i += 2)
    {
      UIComponent facet = ((Structure) _facets.get(i + 1)).
                               createComponent();
      facets.put((String)_facets.get(i), facet);
    }
  }

  // Create any children
  if (_children != null)
  {
    List<UIComponent> children = component.getChildren();
    for (int i = 0 ; i < _children.size(); i++)
    {
      UIComponent child = _children.get(i).createComponent();
      children.add(child);
    }
  }

  return component;
}
 
Example 2
Project: myfaces-trinidad   File: Structure.java   Source Code and License Vote up 5 votes
/**
 * Store the structure of all the facets.
 */
@SuppressWarnings("unchecked")
private List<Object> _getFacets(UIComponent component)
{
  Iterator<String> facetNames;
  if (component instanceof UIXComponentBase)
  {
    facetNames = ((UIXComponentBase) component).getFacetNames();
  }
  else
  {
    facetNames = component.getFacets().keySet().iterator();
  }

  if (!facetNames.hasNext())
    return null;

  Map<String, UIComponent> facets = component.getFacets();
  ArrayList<Object> list = new ArrayList<Object>(facets.size() * 2);
  while (facetNames.hasNext())
  {
    String name = facetNames.next();
    UIComponent facet = facets.get(name);
    if ((facet != null) && !facet.isTransient())
    {
      list.add(name);
      list.add(new Structure(facet));
    }
  }

  if (list.isEmpty())
    return null;

  return list;
}
 
Example 3
Project: myfaces-trinidad   File: DateFieldAsRenderer.java   Source Code and License Vote up 5 votes
@SuppressWarnings("unchecked")
private void _addChildren(FacesContext context, UIComponent component)
{
  // If the components are already there, bail.
  if (component.getFacet("month") != null)
    return;

  String id = component.getId();
  if (id == null)
  {
    id = context.getViewRoot().createUniqueId();
    component.setId(id);
  }

  Map<String, UIComponent> facets = component.getFacets();
  facets.clear();

  Date value = (Date) ((EditableValueHolder) component).getValue();
  Calendar calendar = null;
  if(value != null)
  {
    calendar = Calendar.getInstance();
    calendar.setLenient(true);
    calendar.setTime(value);
  }

  CoreInputText month = _createTwoDigitInput(context);
  month.setShortDesc("Month");
  month.setId(id + "_month");

  LongRangeValidator monthRange = _createLongRangeValidator(context);
  monthRange.setMinimum(1);
  monthRange.setMaximum(12);
  month.addValidator(monthRange);
  if (value != null)
    month.setValue(new Integer(calendar.get(Calendar.MONTH) + 1));
  facets.put("month", month);

  CoreInputText day = _createTwoDigitInput(context);
  day.setShortDesc("Day");
  day.setId(id + "_day");
  LongRangeValidator dayRange = _createLongRangeValidator(context);
  dayRange.setMinimum(1);
  dayRange.setMaximum(31);
  day.addValidator(dayRange);
  if (value != null)
    day.setValue(new Integer(calendar.get(Calendar.DAY_OF_MONTH)));
  facets.put("day", day);

  CoreInputText year = _createTwoDigitInput(context);
  year.setShortDesc("Year");
  year.setId(id + "_year");
  if (value != null)
  {
    int yearValue = calendar.get(Calendar.YEAR) - 1900;
    if (yearValue >= 100)
      yearValue -= 100;
    year.setValue(new Integer(yearValue));
  }

  facets.put("year", year);
}
 
Example 4
Project: myfaces-trinidad   File: ChangeBean.java   Source Code and License Vote up 5 votes
/**
 * Removes one or more facets, based on some characteristic of the
 *  event source.
 */
@SuppressWarnings("unchecked")
public void removeFacets(ActionEvent event)
{
  CoreCommandButton eventSource = (CoreCommandButton) event.getComponent();
  //pu: Anything until ":" in the button text represents the facet name/s
  String facetNameFromButtonText = (eventSource.getText().split(":"))[0];
  //pu: In case of the button that removes multiple facets, this is again 
  //  delimited by "_"
  String removableFacetNames[] = facetNameFromButtonText.split("_");
  
  //pu: Get the CorePanelPage components that has all the removable facets
  UIComponent uic = eventSource.findComponent("pp1");
  Map<String, UIComponent> facets = uic.getFacets();
  if (facets.keySet().size() == 0)
    return;

  for (int i=0; i<removableFacetNames.length; i++)
  {
    if (facets.get(removableFacetNames[i]) != null)
    {
      facets.remove(removableFacetNames[i]);
      ComponentChange rfa = new RemoveFacetComponentChange(removableFacetNames[i]);
      FacesContext fc = FacesContext.getCurrentInstance();
      ChangeManager apm = RequestContext.getCurrentInstance().getChangeManager();
      apm.addComponentChange(fc, uic, rfa);
    }
  }
}
 
Example 5
Project: myfaces-trinidad   File: RemoveFacetComponentChange.java   Source Code and License Vote up 5 votes
/**
 * {@inheritDoc}
 */
@SuppressWarnings("unchecked")
@Override
public void changeComponent(UIComponent uiComponent)
{
  Map<String, UIComponent> facets = uiComponent.getFacets();
  facets.remove(_facetName);
}
 
Example 6
Project: myfaces-trinidad   File: ChildArrayList.java   Source Code and License Vote up 4 votes
@SuppressWarnings("unchecked")
static int __removeFromParent(
  UIComponent component,
  int index)
{
  UIComponent parent = component.getParent();
  assert(parent != null);

  if (parent.getChildCount() > 0)
  {
    List<UIComponent> children = parent.getChildren();
    int size = children.size();
    for  (int i = 0; i < size; i++)
    {
      if  (children.get(i) == component)
      {
        children.remove(i);
        if (index > i)
          index--;
        return index;
      }
    }
  }
  
  // TRINIDAD-2369: Until TRINIDAD-2368 is fixed, we have to call remove() on the map
  // returned by getFacets() rather than calling remove() on getFacets().values()
  // Note that the old code used to call getFacets().values().contains(), which would iterate on the entry set.
  // The new code performs the same iteration, so it should not be any slower.
  
  Map<String, UIComponent> facets = parent.getFacets();
  for (Map.Entry<String, UIComponent> entry: facets.entrySet())
  {
    if (entry.getValue() == component)
    {
      facets.remove(entry.getKey());
      return index;
    }
  }

  // Not good - the child thought it was in a parent,
  // but it wasn't.
  assert(false);
  return index;
}