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

The following are Jave code examples for showing how to use isRendered() 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: CoreRenderer.java   Source Code and License Vote up 6 votes
/**
 * Returns the total number of children with rendered=="true".
 */
@SuppressWarnings("unchecked")
static public int getRenderedChildCount(
  UIComponent component)
{
  int count = component.getChildCount();
  if (count == 0)
    return 0;

  int total = 0;
  for(UIComponent child : (List<UIComponent>)component.getChildren())
  {
    if (child.isRendered())
    {
      total++;
    }
  }

  return total;
}
 
Example 2
Project: myfaces-trinidad   File: ColumnGroupRenderer.java   Source Code and License Vote up 6 votes
@SuppressWarnings("unchecked")
private void _renderChildren(
  FacesContext context,
  UIComponent  component,
  NodeData     parentNode
  ) throws IOException
{
  int i = 0;
  for(UIComponent child : (List<UIComponent>)component.getChildren())
  {
    if (child.isRendered())
    {
      // Tell the parent node - if there is one - which child we're rendering
      if (parentNode != null)
      {
        parentNode.currentChild = i;
      }

      encodeChild(context, child);
    }

    i++;
  }
}
 
Example 3
Project: myfaces-trinidad   File: StatusIndicatorRenderer.java   Source Code and License Vote up 6 votes
private void _renderFacet(
  FacesContext     context,
  RenderingContext rc,
  UIComponent      facet,
  String           styleClass
  ) throws IOException
{
  if (facet != null && facet.isRendered())
  {
    ResponseWriter rw = context.getResponseWriter();

    rw.startElement(XhtmlConstants.SPAN_ELEMENT, null);
    renderStyleClass(context, rc, styleClass);
    encodeChild(context, facet);
    rw.endElement(XhtmlConstants.SPAN_ELEMENT);
  }
}
 
Example 4
Project: myfaces-trinidad   File: TrainRenderer.java   Source Code and License Vote up 6 votes
private void _createStation(
    UIXProcess  process,
    UIComponent stamp,
    int         index,
    boolean     active)
{
  process.setRowIndex(index);
  if(stamp.isRendered())
  {
    // The station will be visible.
    _stations.add(new Station(this,
                              stamp,
                              index,
                              process.getRowKey(),
                              active));
  }
}
 
Example 5
Project: myfaces-trinidad   File: UIComponentUINode.java   Source Code and License Vote up 6 votes
@SuppressWarnings("unchecked")
private void _renderComponent(FacesContext context, UIComponent component)
  throws IOException
{
  component.encodeBegin(context);
  if (component.getRendersChildren())
  {
    component.encodeChildren(context);
  }
  else
  {
    int count = component.getChildCount();
    if (count > 0)
    {
      List<UIComponent> children = component.getChildren();
      for (int i = 0; i < count; i++)
      {
        UIComponent child = children.get(i);
        if (child.isRendered())
          _renderComponent(context, child);
      }
    }
  }

  component.encodeEnd(context);
}
 
Example 6
Project: myfaces-trinidad   File: CSVBean.java   Source Code and License Vote up 6 votes
private void _exportRow(UIXTable table, Writer out) throws IOException
{
  List children = table.getChildren();
  boolean needsComma = false;
  for (Object o : children)
  {
    UIComponent child = (UIComponent) o;
    if (!child.isRendered())
      continue;

    if (needsComma)
      out.write(',');
    
    if (_exportCell(child, out))
      needsComma = true;
  }
  
  out.write('\n');
}
 
Example 7
Project: myfaces-trinidad   File: ShowOneListRendererBase.java   Source Code and License Vote up 5 votes
/**
 *  Returns first disclosed child's Id.
 *
 * @param context the facesContext object
 * @param component
 * @return String id of the first showDetailItem child that can be rendered
 *                and is disclosed
 * @throws IOException
 */
@SuppressWarnings("unchecked")
private static String _getDisclosedItemId(FacesContext context,
                                          UIComponent component)
  throws IOException
{
  String returnId = null;
  ListIterator<UIComponent> iter = component.getChildren().listIterator();

  if (iter == null)
  {
    return null;
  }

  // This will only render UIXShowDetail children.
  // other children are ignored.
  while ( iter.hasNext())
  {
    UIComponent child = iter.next();
    if (! child.isRendered() )
    {
      continue;
    }

    // only CoreShowDetailItem children are rendered. Rest are ignored.
    if ( (child instanceof UIXShowDetail))
    {
      UIXShowDetail detailChild = (UIXShowDetail) child;
      if (detailChild.isDisclosed())
      {
        returnId = detailChild.getClientId(context);
        break;
      }
    }
  }
  return returnId;
}
 
Example 8
Project: myfaces-trinidad   File: ShowOneListRendererBase.java   Source Code and License Vote up 5 votes
/**
 *  Find and encodes recursivly the child specified.
 *
 *  If the specified child can't be found, doesn't do anything.
 *
 *  @param context the facesContext object
 *  @param parent which contains the child to be encoded
 *  @param disclosedChildId id of the child which occurs in parent
 *         and has to be encoded recursively.
 *
 *  @throws IOException when any IO error while writing markup
 */
@SuppressWarnings("unchecked")
private static void _findAndEncodeChild(FacesContext context,
                                        UIComponent parent,
                                        String disclosedChildId)
  throws IOException
{
  UIComponent disclosedChild = _findChild(context,
                                          parent,
                                          disclosedChildId);

  if (disclosedChild == null)
  {
    return;
  }

  // Paint container span for showDetail child
  ResponseWriter out = context.getResponseWriter();
  out.startElement("span", disclosedChild);

  // Render the children of disclosedChild since the child is disclosed.
  if (disclosedChild.isRendered())
  {
    if (disclosedChild.getChildCount() > 0)
    {
      for(UIComponent child : (List<UIComponent>)disclosedChild.getChildren())
      {
        RenderUtils.encodeRecursive(context, child);
      }
    }
  }

  out.endElement("span");
  // end container span for showDetail child
}
 
Example 9
Project: myfaces-trinidad   File: CoreFormTest.java   Source Code and License Vote up 5 votes
@Override
protected boolean willChildrenBeProcessed(UIComponent component)
{
  if (!component.isRendered())
    return false;

  if (component instanceof TestForm)
    return ((TestForm) component).getWillBeSubmitted();
  else
    return ((CoreForm) component).isSubmitted();
}
 
Example 10
Project: myfaces-trinidad   File: UIXComponent.java   Source Code and License Vote up 5 votes
/**
 * default implementation checking the <code>VisitHint.SKIP_TRANSIENT</code> and
 * <code>VisitHint.SKIP_UNRENDERED</code> hints.
 */
private static boolean _isVisitable(VisitContext visitContext, UIComponent component)
{
  Collection<VisitHint> hints = visitContext.getHints();

  if (hints.contains(VisitHint.SKIP_TRANSIENT) && component.isTransient())
    return false;

  if (hints.contains(VisitHint.SKIP_UNRENDERED) && !component.isRendered())
    return false;

  return true;
}
 
Example 11
Project: myfaces-trinidad   File: CoreRenderer.java   Source Code and License Vote up 5 votes
/**
 * Gets a facet, verifying that the facet should be rendered.
 */
static public UIComponent getFacet(
  UIComponent component,
  String      name)
{
  UIComponent facet = component.getFacet(name);
  if ((facet == null) || !facet.isRendered())
    return null;

  return facet;
}
 
Example 12
Project: myfaces-trinidad   File: ColumnRenderer.java   Source Code and License Vote up 5 votes
@SuppressWarnings("unchecked")
protected void renderKids(
  FacesContext          context,
  RenderingContext      rc,
  TableRenderingContext trc,
  UIComponent           column
  ) throws IOException
{
  boolean renderedOne = false;
  for(UIComponent child : (List<UIComponent>)column.getChildren())
  {
    if (child.isRendered())
    {
      // Put each component on a separate line, separated by a div
      if (renderedOne)
      {
        ResponseWriter rw = context.getResponseWriter();
        rw.startElement("div", null);
        rw.endElement("div");
      }
      else
      {
        renderedOne = true;
      }

      encodeChild(context, child);
    }
  }
}
 
Example 13
Project: myfaces-trinidad   File: PartialViewContextImpl.java   Source Code and License Vote up 5 votes
private static void _renderChildren(FacesContext context, UIComponent root) throws IOException
{
  Iterator<UIComponent> iterator = root.getFacetsAndChildren();
  while (iterator.hasNext())
  {
    UIComponent child = iterator.next();
    if (child.isRendered())
      child.encodeAll(context);
  }
}
 
Example 14
Project: myfaces-trinidad   File: ProcessUtils.java   Source Code and License Vote up 5 votes
public static int getBackIndex(
  UIXCollection component,
  UIComponent    stamp,
  int            startIndex
)
{
  int i = startIndex - 1;
  while (i >= 0)
  {
    component.setRowIndex(i);
    boolean disabled = Boolean.TRUE.equals(
      stamp.getAttributes().get("disabled")); 
    boolean readOnly = Boolean.TRUE.equals(
      stamp.getAttributes().get("readOnly")); 
    boolean rendered = stamp.isRendered();

    // if this node is rendered and not disabled and not readOnly
    // then it can be used as the back button node.
    if (!disabled && !readOnly && rendered)    
    {
      component.setRowIndex(startIndex);
      return i;
    }
      
    i--;
  }
  
  component.setRowIndex(startIndex);
  return NO_INDEX;
}
 
Example 15
Project: myfaces-trinidad   File: UIXSwitcherTest.java   Source Code and License Vote up 5 votes
@SuppressWarnings("unchecked")
@Override
protected void doTestApplyRequestValues(
  FacesContext context,
  UIViewRoot   root,
  UIComponent  component)
{

  Mock mockUIComponent = createMockUIComponent();
  UIComponent fooChild = (UIComponent) mockUIComponent.proxy();
  
  // JavaServer Faces 1.0 Specification, section 2.2.2
  // During the apply-request-values phase,
  // only the processDecodes lifecycle method may be called.
  if (component.isRendered()){
    mockUIComponent.stubs().method("processDecodes").with(eq(facesContext));
  }

  // These children will never get called
  Mock mockBarChild = createMockUIComponent();
  UIComponent barChild = (UIComponent) mockBarChild.proxy();
  
  Mock mockOrdinaryChild = createMockUIComponent();
  UIComponent ordinaryChild = (UIComponent) mockOrdinaryChild.proxy();

  // construct the UIComponent tree and
  // execute the apply-request-values lifecycle phase
  root.getChildren().add(component);
  component.getFacets().put("foo", fooChild);
  component.getFacets().put("bar", barChild);
  component.getChildren().add(ordinaryChild);
  root.processDecodes(context);

  mockUIComponent.verify();
  mockBarChild.verify();
  mockOrdinaryChild.verify();
}
 
Example 16
Project: myfaces-trinidad   File: RenderUtils.java   Source Code and License Vote up 5 votes
/**
 * Encodes a component and all of its children.
 */
@SuppressWarnings("unchecked")
static public void encodeRecursive(FacesContext context,
                                   UIComponent component)
  throws IOException
{
  if (component.isRendered())
  {
    component.encodeBegin(context);
    if (component.getRendersChildren())
    {
      component.encodeChildren(context);
    }
    else
    {
      if (component.getChildCount() > 0)
      {
        for(UIComponent child : (List<UIComponent>)component.getChildren())
        {
          encodeRecursive(context, child);
        }
      }
    }

    component.encodeEnd(context);
  }
}
 
Example 17
Project: myfaces-trinidad   File: PanelAccordionRenderer.java   Source Code and License Vote up 4 votes
@SuppressWarnings("unchecked")
@Override
protected void decode(
  FacesContext facesContext,
  UIComponent  component,
  @SuppressWarnings("unused")
  FacesBean    facesBean,
  String       clientId)
{
  Map<String, String> parameters =
    facesContext.getExternalContext().getRequestParameterMap();

  Object event = parameters.get(XhtmlConstants.EVENT_PARAM);
  if (XhtmlConstants.HIDE_EVENT.equals(event) ||
      XhtmlConstants.SHOW_EVENT.equals(event))
  {
    Object source = parameters.get(XhtmlConstants.SOURCE_PARAM);
    String id = clientId == null ? component.getClientId(facesContext) : clientId;

    if (id.equals(source))
    {
      boolean isDisclosed = XhtmlConstants.SHOW_EVENT.equals(event);
      String itemId = parameters.get("targetItem");
      if (itemId != null)
      {
        List<UIComponent> children = component.getChildren();
        for (UIComponent child : children)
        {
          if (!(child instanceof UIXShowDetail))
            continue;

          // Don't even bother with disabled showDetailItems -
          // a malicious user should not be able to force
          // a disabled item open by dummying up an event
          if (!child.isRendered() || _isItemDisabled(child))
            continue;

          if (itemId.equals(child.getClientId(facesContext)))
          {
            (new DisclosureEvent(child, isDisclosed)).queue();
            RequestContext rc = RequestContext.getCurrentInstance();

            // Don't force PPR on for the browsers that do not support Ajax
            Object cap = rc.getAgent().getCapabilities().get(TrinidadAgent.CAP_PARTIAL_RENDERING);
            if ((cap != null) && (Boolean.TRUE.equals(cap)))
            {
              RequestContext.getCurrentInstance().addPartialTarget(component);
              PartialPageUtils.forcePartialRendering(facesContext);
            }

            break;
          }
        }
      }
    }
  }
}
 
Example 18
Project: myfaces-trinidad   File: UIComponentTestCase.java   Source Code and License Vote up 4 votes
protected boolean willChildrenBeProcessed(UIComponent component)
{
  return (component.isRendered());
}
 
Example 19
Project: myfaces-trinidad   File: PdaTableRenderer.java   Source Code and License Vote up 4 votes
@SuppressWarnings("unchecked")
private void _renderColumnFooter(
  FacesContext          context,
  RenderingContext      rc,
  TableRenderingContext tContext,
  UIComponent           component
  ) throws IOException
{
  tContext.getRenderStage().setStage(RenderStage.COLUMN_FOOTER_STAGE);
  final ColumnData colData = tContext.getColumnData();
  UIComponent footer = getFacet(component, CoreTable.FOOTER_FACET);
  if (footer != null)
  {
    ResponseWriter writer = context.getResponseWriter();
    writer.startElement(XhtmlConstants.TABLE_ROW_ELEMENT, null);
    /*  boolean useScroll = (getHeight(getFacesBean(component)) != null) && isIE(arc);
   if (useScroll)
   {
     writer.writeAttribute("style", "position:relative;"+
                                    "bottom:expression("+
                                     "this.offsetParent.scrollHeight-this.offsetParent.scrollTop-"+
                                     "this.offsetParent.clientHeight+1);" +
                                    "left:-1px", null);
   }
*/
    writer.startElement(XhtmlConstants.TABLE_HEADER_ELEMENT, null);
    // total rows may need an ID. see bug 3211593:
    /* Need new scheme for generateUniqueId()?
   String rowID = XhtmlLafUtils.generateUniqueID(tContext);
   writer.writeAttribute(XhtmlLafConstants.ID_ATTRIBUTE, rowID, null);
   tContext.getRowData().setCurrentRowHeaderID(rowID);
   */
    final int firstFooterPhysicalIndex =
      colData.getPhysicalIndexOfFirstFooter();
    final int colSpan =
      (firstFooterPhysicalIndex > 0)? firstFooterPhysicalIndex:
      tContext.getActualColumnCount();
    writer.writeAttribute(XhtmlConstants.COLSPAN_ATTRIBUTE,
        IntegerUtils.getString(colSpan), null);
    renderStyleClass(context, rc,
        SkinSelectors.AF_TABLE_COLUMN_FOOTER_STYLE);
    encodeChild(context, footer);
    writer.endElement(XhtmlConstants.TABLE_HEADER_ELEMENT);
    if (firstFooterPhysicalIndex > 0)
    {
      colData.setColumnIndex(tContext.getSpecialColumnCount(),
          0) /*logicalColumnIndex*/;

      for (UIComponent child:
        (List<UIComponent>) component.getChildren())
      {
        if (child.isRendered())
        {
          encodeChild(context, child);
        }
      }
    }
    writer.endElement(XhtmlConstants.TABLE_ROW_ELEMENT);
  }
}
 
Example 20
Project: myfaces-trinidad   File: CSVBean.java   Source Code and License Vote up 4 votes
private boolean _exportCell(UIComponent cell, Writer out) throws IOException
{
  boolean foundValue = false;
  if (cell instanceof ValueHolder)
  {
    foundValue = true;
    Object value = ((ValueHolder)cell).getValue();
    if (value != null)
    {
      String valueStr;
      Converter converter = ((ValueHolder) cell).getConverter();

      // TODO: add default by-type converter support
      if (converter != null)
      {
        try
        {
          valueStr = converter.getAsString(FacesContext.getCurrentInstance(),
                                           cell,
                                           value);
        }
        catch (ConverterException ce)
        {
          valueStr = value.toString();
        }
      }
      else
      {
        valueStr = value.toString();
      }

      if (valueStr != null)
      {
        out.write('"');
        out.write(_csvEscape(valueStr));
        out.write('"');
      }
    }
  }


  if (cell.getChildCount() > 0)
  {
    List children = cell.getChildren();
    for (Object o : children)
    {
      UIComponent child = (UIComponent) o;
      if (!child.isRendered())
        continue;
      
      if (_exportCell(child, out))
        foundValue = true;
    }
  }

  return foundValue;
}