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

The following are Jave code examples for showing how to use findComponent() 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: ChangeBean.java   Source Code and License Vote up 6 votes
/**
 * Modifies the sortable property of the column.
 */
@SuppressWarnings("unchecked")
public void modifyColumn(ActionEvent event)
{
  //=-=pu: 'uic1' gets null, while 'uic' gets valid component, maybe a bug ?.
  //UIComponent uic1 = event.getComponent().findComponent("c1");
  UIComponent uic2 = event.getComponent().findComponent("t1");
  UIComponent uic = uic2.findComponent("c1");
  
  Object sortableAttrib = uic.getAttributes().get("sortable");
  Boolean isSortable = 
    (sortableAttrib == null)? Boolean.TRUE:(Boolean)sortableAttrib;
  Boolean newSortableValue = 
    Boolean.TRUE.equals(isSortable)? Boolean.FALSE:Boolean.TRUE;
  uic.getAttributes().put("sortable", newSortableValue);
  _addAttributeChange(uic, "sortable", newSortableValue);
}
 
Example 2
Project: myfaces-trinidad   File: ChangeBean.java   Source Code and License Vote up 6 votes
/**
 * Appends an image child to the panelGroup in the underlying JSP document
 */
public void appendChildToDocument(ActionEvent event)
{
  UIComponent eventSource = event.getComponent();
  UIComponent uic = eventSource.findComponent("pg1");
  
  // only allow the image to be added once
  if (_findChildById(uic,"oi3") != null)
    return;
    
  FacesContext fc = FacesContext.getCurrentInstance();

  DocumentFragment imageFragment = _createDocumentFragment(_IMAGE_MARK_UP);
  
  if (imageFragment != null)
  {
    DocumentChange change = new AddChildDocumentChange(imageFragment);
    
    ChangeManager apm = RequestContext.getCurrentInstance().getChangeManager();
    
    apm.addDocumentChange(fc, uic, change);
  }
}
 
Example 3
Project: myfaces-trinidad   File: ChangeBean.java   Source Code and License Vote up 6 votes
/**
 * Appends an image child to the panelGroup.
 */
@SuppressWarnings("unchecked")
public void appendChild(ActionEvent event)
{
  UIComponent eventSource = event.getComponent();
  UIComponent uic = eventSource.findComponent("pg1");
  if (_findChildById(uic,"oi2") != null)
    return;
  FacesContext fc = FacesContext.getCurrentInstance();
  
  CoreImage newChild = 
    (CoreImage) fc.getApplication().createComponent(
      "org.apache.myfaces.trinidad.CoreImage");
  newChild.setId("oi2");
  newChild.setInlineStyle("height: 100px, width: 120px");
  newChild.setSource(
    "http://homepage.mac.com/awiner/.Pictures/WindyHill/PaleSwallowtail.jpg");  
  uic.getChildren().add(newChild);

  ComponentChange aca = new AddChildComponentChange(newChild);

  ChangeManager apm = RequestContext.getCurrentInstance().getChangeManager();
  apm.addComponentChange(fc, uic, aca);
}
 
Example 4
Project: myfaces-trinidad   File: ChangeBean.java   Source Code and License Vote up 6 votes
/**
 * Adds a 'brandingAppContextual' facet  to the panelGroup.
 */
@SuppressWarnings("unchecked")
public void addFacet(ActionEvent event)
{
  UIComponent eventSource = event.getComponent();
  UIComponent uic = eventSource.findComponent("pp1");
  FacesContext fc = FacesContext.getCurrentInstance();
  CoreOutputFormatted newFacetComponent = 
    (CoreOutputFormatted) fc.getApplication().createComponent(
      "org.apache.myfaces.trinidad.CoreOutputFormatted");
  newFacetComponent.setStyleUsage("inContextBranding" );
  newFacetComponent.setValue(
    "Customer Company - Menlo Park");
  uic.getFacets().put("brandingAppContextual", newFacetComponent);

  ComponentChange afa = new SetFacetChildComponentChange("brandingAppContextual", newFacetComponent);

  ChangeManager apm = RequestContext.getCurrentInstance().getChangeManager();
  apm.addComponentChange(fc, uic, afa);
}
 
Example 5
Project: myfaces-trinidad   File: ChangeBean.java   Source Code and License Vote up 6 votes
/**
 * Removes a pair of children, based on some characteristic of the
 *  event source.
 */
public void removeChildren(ActionEvent event)
{
  UIComponent eventSource = event.getComponent();
  UIComponent uic = eventSource.findComponent("pg1");
  int numChildren = uic.getChildCount();
  if (numChildren == 0)
    return;
  String eventSourceId = eventSource.getId();    
  if (eventSourceId.equals("cb2"))
  {
    _removeChild(uic, "sic1");
    _removeChild(uic, "cc1");
  }
  else if (eventSourceId.equals("cb3"))
  {
    _removeChild(uic, "cd1");
    _removeChild(uic, "sid1");
  }
}
 
Example 6
Project: myfaces-trinidad   File: ComponentRefTag.java   Source Code and License Vote up 5 votes
@SuppressWarnings("unchecked")
public void restoreFacet(UIComponent region, String facet)
{
  UIComponent relocatedFacet = _facet;
  if (relocatedFacet == null)
  {
    relocatedFacet = region.findComponent(_findId);
  }
  region.getFacets().put(facet, relocatedFacet);
}
 
Example 7
Project: myfaces-trinidad   File: TestStateSavingBean.java   Source Code and License Vote up 5 votes
public void temporaryMoveComponent(ActionEvent ae)
{
  System.out.println("Temporarily moving a component");
  UIComponent button = ae.getComponent();
  UIComponent moveme = button.findComponent("moveme");
  UIComponent moveto = button.findComponent("moveto");
  UIComponent parent = moveme.getParent();
  
  parent.getChildren().remove(moveme);
  moveto.getChildren().add(moveme);
  moveto.getChildren().remove(moveme);
  parent.getChildren().add(moveme);
}
 
Example 8
Project: myfaces-trinidad   File: FormRenderer.java   Source Code and License Vote up 4 votes
protected String getFullOnkeypress(
  FacesContext context,
  UIComponent  component,
  FacesBean    bean,
  String       clientId)
{
  String onKeypress = super.getOnkeypress(component, bean);

  String defaultCommand = getDefaultCommand(component, bean);

  String submitFunc = null;

  UIComponent defaultCommandComponent = null;
  if (defaultCommand != null && !"".equals(defaultCommand))
  {
    defaultCommandComponent
      = component.findComponent(defaultCommand);
  }

  if (defaultCommandComponent != null && (defaultCommandComponent instanceof ActionSource))
  {
    // Get the true clientId
    String defaultCommandId =
      defaultCommandComponent.getClientId(context);
    int immediate = 1;

    if(((ActionSource) defaultCommandComponent).isImmediate())
    {
      immediate = 0;
    }

    //PPR
    Boolean ppr = (Boolean) defaultCommandComponent.getAttributes().get("partialSubmit");
    if(ppr != null && ppr)
    {
      submitFunc = "return _submitOnEnter"
          + "(event,'"  + clientId
          + "'," + "'" + defaultCommandId
          + "'," + immediate
          + "," + true +");";
    }
    //no PPR
    else
    {
      submitFunc = "return _submitOnEnter"
          + "(event,'"  + clientId
          + "'," + "'" + defaultCommandId
          + "'," + immediate
          + "," + false +");";
    }
  }
  else
  {
    submitFunc = "return _submitOnEnter(event,'" +
                           clientId +
                           "');";
  }

  onKeypress = XhtmlUtils.getChainedJS(onKeypress, submitFunc, true);

  return onKeypress;
}
 
Example 9
Project: myfaces-trinidad   File: TestScript.java   Source Code and License Vote up 4 votes
@SuppressWarnings("unchecked")
@Override
public void apply(FacesContext context, UIComponent component)
{
  Iterator<Test> tests = _delegateTests.iterator();
  
  if (_testComponentId != null)
    component = component.findComponent(_testComponentId); 
  
  while (tests.hasNext())
  {
    Test test = tests.next();
    test.apply(context, component);
  }
  
  Object value = _value;
  
     
  // Hack to test table sort. This is a custom attribute not renderer or component attribute
  if ("tableSortCriteria".equals(_name))
  {
    UIXCollection tableModel = (UIXCollection)  component;
    List<SortCriterion> sortCriteriaList = new ArrayList<SortCriterion>();
    String sortCriterion = (String) _value;
    Boolean isAscending  = 
       new Boolean(sortCriterion.substring(sortCriterion.indexOf(" ")).trim());
    sortCriteriaList.add(new SortCriterion(
          sortCriterion.substring(0,sortCriterion.indexOf(" ")), 
          isAscending.booleanValue()));
    tableModel.setSortCriteria(sortCriteriaList);
  }
  else
  {      
    if ((value instanceof String) &&
        ComponentDefinition.isValueExpression(value.toString()))
    {
      ValueBinding binding = context.getApplication().
        createValueBinding(value.toString());
      component.setValueBinding(_name, binding);
    }
    else
    {
      if (value == null)
        value = "test-" + _name;
  
      component.getAttributes().put(_name, value);
    }
  }
}
 
Example 10
Project: myfaces-trinidad   File: ComponentUtils.java   Source Code and License Vote up 4 votes
/**
 * Find a component relative to another.
 * <p>
 * The relative ID must account for NamingContainers. If the component is already inside
 * of a naming container, you can use a single colon to start the search from the root, 
 * or multiple colons to move up through the NamingContainers - "::" will 
 * pop out of the current naming container, ":::" will pop out of two
 * naming containers, etc.
 * </p>
 * 
 * @param from the component to search relative to
 * @param scopedId the relative id path from the 'from' component to the
 *                 component to find
 * @return the component if found, null otherwise
 * @see org.apache.myfaces.trinidad.render.RenderUtils#getRelativeId
 * @see javax.faces.component.UIComponent#findComponent
 */
public static UIComponent findRelativeComponent(
  UIComponent from,
  String      scopedId)
{
  if (from == null)
      return null;
  UIComponent originalFrom = from;
  String originalRelativeId = scopedId;
  
  int idLength = scopedId.length();
  // Figure out how many colons
  int colonCount = 0;
  while (colonCount < idLength)
  {
    if (scopedId.charAt(colonCount) != NamingContainer.SEPARATOR_CHAR)
      break;
    colonCount++;
  }

  // colonCount == 0: fully relative
  // colonCount == 1: absolute (still normal findComponent syntax)
  // colonCount > 1: for each extra colon after 1, pop out of
  // the naming container (to the view root, if naming containers run out)
  if (colonCount > 1)
  {
    scopedId = scopedId.substring(colonCount);
    
    // if the component is not a NamingContainer, then we need to 
    // get the component's naming container and set this as the 'from'.
    // this way we'll pop out of the component's 
    // naming container if there is are multiple colons.
    if (!(from instanceof NamingContainer))
    {
      from = _getParentNamingContainerOrViewRoot(from);
    }
    
    // pop out of the naming containers if there are multiple colons
    for (int j = 1; j < colonCount; j++)
    {
      from = _getParentNamingContainerOrViewRoot(from);
    }
  }

  UIComponent found = from.findComponent(scopedId);
  if (found != null)
    return found;
  else
  {
    // try the old way for backward compatability as far as it differed,
    // which is only if the 'from' was not a NamingContainer.
    if (!(originalFrom instanceof NamingContainer))
      return _findRelativeComponentDeprecated(originalFrom, originalRelativeId);
    else
      return null;
  }
  
}
 
Example 11
Project: myfaces-trinidad   File: ComponentUtils.java   Source Code and License Vote up 4 votes
/**
  * Find a component relative to another.
  * This method is the same as the 'old' public findRelativeComponent.
 * This method is around so that the
 * new findRelativeComponent method is backward compatibility.
  * <p>
  * The relative ID must account for NamingContainers. If the component is already inside
  * of a naming container, you can use a single colon to start the search from the root, 
  * or multiple colons to move up through the NamingContainers - "::" will search from 
  * the parent naming container, ":::" will search from the grandparent 
  * naming container, etc.
  * </p>
  * 
  * @param from the component to search relative to
  * @param relativeId the relative path to the component to find
  * @return the component if found, null otherwise
  */
private static UIComponent _findRelativeComponentDeprecated(
  UIComponent from,
  String      relativeId)
{  
  UIComponent originalFrom = from;
  String originalRelativeId = relativeId;

  int idLength = relativeId.length();
  // Figure out how many colons
  int colonCount = 0;
  while (colonCount < idLength)
  {
    if (relativeId.charAt(colonCount) != NamingContainer.SEPARATOR_CHAR)
      break;
    colonCount++;
  }

  // colonCount == 0: fully relative
  // colonCount == 1: absolute (still normal findComponent syntax)
  // colonCount > 1: for each extra colon after 1, go up a naming container
  // (to the view root, if naming containers run out)
  if (colonCount > 1)
  {
    relativeId = relativeId.substring(colonCount);
    for (int j = 1; j < colonCount; j++)
    {
      while (from.getParent() != null)
      {
        from = from.getParent();
        if (from instanceof NamingContainer)
          break;
      }
    }
  }

  UIComponent found = from.findComponent(relativeId);
  if (found != null)
  {
    _LOG.warning("DEPRECATED_RELATIVE_ID_SYNTAX", 
      new Object[] {originalRelativeId, originalFrom});
  }
  return found;
}
 
Example 12
Project: myfaces-trinidad   File: UIXComponentBase.java   Source Code and License Vote up 4 votes
@Override
public UIComponent findComponent(String id)
{
  if (id == null)
    throw new NullPointerException();

  if ("".equals(id))
    throw new IllegalArgumentException();

  UIComponent from = this;
  // If it starts with the separator character, it's
  // an absolute path: start at the top
  if (id.charAt(0) == NamingContainer.SEPARATOR_CHAR)
  {
    id = id.substring(1);
    while (from.getParent() != null)
      from = from.getParent();
  }
  // If it's a NamingContainer, start right here
  else if (this instanceof NamingContainer)
  {
    ;
  }
  // Otherwise, go up to look for NamingContainer (or the top)
  else
  {
    while (from.getParent() != null)
    {
      from = from.getParent();
      if (from instanceof NamingContainer)
        break;
    }
  }

  // Evaluate each part of the expression
  String searchId;
  int separatorIndex = id.indexOf(NamingContainer.SEPARATOR_CHAR);
  if (separatorIndex < 0)
    searchId = id;
  else
    searchId = id.substring(0, separatorIndex);

  if (searchId.equals(from.getId()))
  {
    // Don't need to look inside if we're already there
    ;
  }
  else
  {
    from = _findInsideOf(from, searchId);
  }

  // Final ID:  break, and return whatever we've found
  if (separatorIndex < 0)
  {
    return from;
  }
  // Just an intermediate step.  Make sure we're at a NamingContainer,
  // and then ask it to find the rest of the expression.
  else
  {
    if (from == null)
      return null;

    if (!(from instanceof NamingContainer))
      throw new IllegalArgumentException();
    return from.findComponent(id.substring(separatorIndex + 1));
  }
}