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

The following are Jave code examples for showing how to use getFacet() 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: DateFieldAsRenderer.java   Source Code and License Vote up 6 votes
@Override
public void encodeChildren(FacesContext context,
                           UIComponent component) throws IOException
{
  ResponseWriter out = context.getResponseWriter();

  UIComponent month = component.getFacet("month");
  month.encodeBegin(context);
  month.encodeChildren(context);
  month.encodeEnd(context);

  out.writeText("\u00a0/\u00a0", null);

  UIComponent day = component.getFacet("day");
  day.encodeBegin(context);
  day.encodeChildren(context);
  day.encodeEnd(context);

  out.writeText("\u00a0/\u00a0", null);

  UIComponent year = component.getFacet("year");
  year.encodeBegin(context);
  year.encodeChildren(context);
  year.encodeEnd(context);
}
 
Example 2
Project: myfaces-trinidad   File: UIXComponent.java   Source Code and License Vote up 6 votes
/**
 * Determine if we can flatten a core JSF component.
 * @param component The component
 * @return true if the component is a core JSF component and we can
 * flatten it successfully.
 */
private static boolean isFlattenableCoreComponent(UIComponent component)
{
  // Optimize the cases of UINamingContainer (<f:subview>) and UIPanel -
  // we will treat these components as FlattenedComponents because they do not render
  // any DOM.
  // Also note that as of JSF 2.0, UINamingContainer components are built
  // by f:subview, as well as composite components.
  Class<? extends UIComponent> componentClass = component.getClass();

  if (UINamingContainer.class == componentClass)
  {
    // Check to see if this component was created as a composite
    // component, which we cannot flatten
    return component.getFacet(UIComponent.COMPOSITE_FACET_NAME) == null;
  }

  // Note that JSF 2.0 creates UIPanel wrappers around multiple components
  // inside of <f:facet>
  return UIPanel.class == componentClass;
}
 
Example 3
Project: myfaces-trinidad   File: FacetRefTag.java   Source Code and License Vote up 5 votes
@Override
public int doStartTag() throws JspException
{
  UIComponentClassicTagBase tag = UIComponentClassicTagBase.getParentUIComponentClassicTagBase(pageContext);
  if (tag == null)
  {
    _LOG.warning("FACETREF_MUST_INSIDE_UICOMPONENT");
    return SKIP_BODY;
  }

  UIComponent component = tag.getComponentInstance();
  UIComponent region = _getRegionComponent(component);
  if (region == null)
  {
    _LOG.warning("CANNOT_FIND_PARENT_COMPONENTREF");
    return SKIP_BODY;
  }
  if (_facet != null)
  {
    UIComponent child = region.getFacet(_facet);
    if (child != null)
    {
      _addChild(component, child);
      // alert the region component that we moved one of its facets.
      // This is so that it can restore the facet, during the next request,
      // just in time to prevent the jsf jsp tag framework from
      // getting confused:
      ComponentRefTag.addRelocatedFacet(region, _facet, child);
    }
  }
  else
  {
    _LOG.warning("FACETNAME_REQUIRED");
  }

  return SKIP_BODY;
}
 
Example 4
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 5
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 6
Project: myfaces-trinidad   File: StatusIndicatorRenderer.java   Source Code and License Vote up 4 votes
@Override
protected void encodeAll(
  FacesContext     context,
  RenderingContext rc,
  UIComponent      comp,
  FacesBean        bean
  ) throws IOException
{
  UIComponent busyFacet = comp.getFacet(CoreStatusIndicator.BUSY_FACET);
  UIComponent readyFacet = comp.getFacet(CoreStatusIndicator.READY_FACET);

  boolean iconMode = false;
  Icon busyIcon = null;
  Icon readyIcon = null;
  if (busyFacet == null && readyFacet == null)
  {
    // Render icons only if no facet was specified.
    busyIcon = rc.getIcon(SkinSelectors.AF_STATUS_INDICATOR_BUSY_ICON);
    readyIcon = rc.getIcon(SkinSelectors.AF_STATUS_INDICATOR_READY_ICON);
    if (busyIcon == null || readyIcon == null)
    {
      // Missing an icon and no faet was specified, log.
      _LOG.warning("STATUS_INDICATOR_MISSING_ICONS");
      return;
    }

    iconMode = true;
  }

  ResponseWriter rw = context.getResponseWriter();

  String clientId = getClientId(context, comp);

  // Renders root DOM
  rw.startElement(XhtmlConstants.SPAN_ELEMENT, comp);
  renderId(context, comp);
  renderAllAttributes(context, rc, comp, bean);

  // Renders ready DOM
  rw.startElement(XhtmlConstants.SPAN_ELEMENT, null);
  rw.writeAttribute(XhtmlConstants.ID_ATTRIBUTE, clientId + "::ready", null);

  if (iconMode)
  {
    _renderIcon(context, rc, readyIcon, "af_statusIndicator.READY");
  }
  else
  {
    _renderFacet(context, rc, readyFacet,
                 SkinSelectors.AF_STATUS_INDICATOR_READY_STYLE);
  }

  rw.endElement(XhtmlConstants.SPAN_ELEMENT);

  // Renders busy DOM
  rw.startElement(XhtmlConstants.SPAN_ELEMENT, null);
  rw.writeAttribute(XhtmlConstants.ID_ATTRIBUTE, clientId + "::busy", null);
  rw.writeAttribute(XhtmlConstants.STYLE_ATTRIBUTE, "display:none", null);

  if (iconMode)
  {
    _renderIcon(context, rc, busyIcon, "af_statusIndicator.BUSY");
  }
  else
  {
    _renderFacet(context, rc, busyFacet,
                 SkinSelectors.AF_STATUS_INDICATOR_BUSY_STYLE);
  }

  rw.endElement(XhtmlConstants.SPAN_ELEMENT);

  rw.startElement(XhtmlConstants.SCRIPT_ELEMENT, null);
  renderScriptTypeAttribute(context, rc);
  rw.writeText("TrStatusIndicator._register(\"" + clientId + "\");", null);
  rw.endElement(XhtmlConstants.SCRIPT_ELEMENT);

  rw.endElement(XhtmlConstants.SPAN_ELEMENT);
}
 
Example 7
Project: myfaces-trinidad   File: DateFieldAsRenderer.java   Source Code and License Vote up 4 votes
@Override
public Object getConvertedValue(
  FacesContext context,
  UIComponent  component,
  Object       submittedValue)
{
  EditableValueHolder monthComp = (EditableValueHolder) component.getFacet("month");
  EditableValueHolder yearComp = (EditableValueHolder) component.getFacet("year");
  EditableValueHolder dayComp = (EditableValueHolder) component.getFacet("day");

  if (!monthComp.isValid() ||
      !yearComp.isValid() ||
      !dayComp.isValid())
  {
    // =-=AEW What to do????????
    //setValid(false);
    return null;
  }

  int year = ((Number) yearComp.getValue()).intValue();
  // We'll be 1970 - 2069.  Good enough for a demo.
  if (year < 70)
    year += 100;

  int month = ((Number) monthComp.getValue()).intValue() - 1;
  int day = ((Number) dayComp.getValue()).intValue();

  Date oldValue = (Date) ((EditableValueHolder) component).getValue();
  //Date newValue = (Date) oldValue.clone();
  Calendar calendar = Calendar.getInstance();
  calendar.setLenient(true);
  calendar.setTime(oldValue);
  calendar.set(Calendar.YEAR, year);
  calendar.set(Calendar.MONTH, month);
  calendar.set(Calendar.DAY_OF_MONTH, day);
  
  // Invalid day given the month
  if (day != calendar.get(Calendar.DAY_OF_MONTH))
  {
    int numberOfDaysInMonth = day - calendar.get(Calendar.DAY_OF_MONTH);
    FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR,
                  "Invalid date.",
                  "This month only has " + numberOfDaysInMonth + " days!");
    throw new ConverterException(message);
  }

  return calendar.getTime();
}