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

The following are Jave code examples for showing how to use setId() 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: UIXTableTemplate.java   Source Code and License Vote up 6 votes
/**
 * Restores the state for the given stamp.
 * This method avoids changing the state of facets on columns.
 */
@Override
protected final void restoreStampState(FacesContext context, UIComponent stamp, Object stampState)
{
  if (stamp instanceof UIXColumn)
  {
    // if it is a column, we don't want the facets processed.
    // Only the children:
    StampState.restoreChildStampState(context, stamp, this, stampState);
  }
  else
  {
    // If we are done processing our stamps and are moving back to null currency, restore the stamp state to the
    // one saved off before processing our stamps
    if(stamp instanceof UIXIterator && _movingBackToNullCurrency && _iteratorStampMap != null)
    {
      // clear the cached client id of the iterator so that we can get the one without currency
      stamp.setId(stamp.getId());
      stampState = _iteratorStampMap.get(stamp.getClientId(context));        
    }
    super.restoreStampState(context, stamp, stampState);
  }
}
 
Example 2
Project: myfaces-trinidad   File: TrinidadComponentHandler.java   Source Code and License Vote up 5 votes
@Override
public void onComponentPopulated(FaceletContext context,
                                   UIComponent component,
                                   UIComponent parent)
{
  assert (_markInitialState != null);

  if ((component instanceof UIXComponent) &&
      (_markInitialState == Boolean.TRUE))
  {
    if (component.getId() == null)
      component.setId(context.generateUniqueId(UIViewRoot.UNIQUE_ID_PREFIX));
    
    PhaseId phase = context.getFacesContext().getCurrentPhaseId();
    
    // In jsf2 markInitialState will be called by the framework during restore view, 
    // and in fact the framework should always be the one
    // calling markInitialState, but it doesn't always do that in render response, see
    // http://java.net/jira/browse/JAVASERVERFACES-2285
    // Also don't call markInitialState unless initialStateMarked returns false, otherwise
    // any deltas previously saved may get blown away.
    if (PhaseId.RENDER_RESPONSE.equals(phase) && !component.initialStateMarked())
    {
      component.markInitialState();
    }
  }
}
 
Example 3
Project: myfaces-trinidad   File: CoreFormData.java   Source Code and License Vote up 5 votes
/**
 * @todo escape script???
 * @todo get rid of the colorpicker hack!
 */
private void _addOnSubmitConverter(
  FacesContext              context,
  RenderingContext          rc,
  UIComponent               component,
  ClientConverter           submitConverter,
  CoreFormData.ConvertValidate  convertValidate,
  String                    clientId
  ) throws IOException
{

  if (component == null)
  {
    // HACK HACK - this is needed for colorPicker!
    component = new org.apache.myfaces.trinidad.component.UIXInput();
    component.setId(clientId);

  }

  // write out the lib(s) and script
  String libURI = submitConverter.getClientLibrarySource(context);
  String clientScript = submitConverter.getClientScript(context, component);
  Collection<String> libRefs = submitConverter.getClientImportNames();
  _addClientScripts(context, rc, libURI, clientScript, libRefs, "TrConverter()");

  String converter = submitConverter.getClientConversion(context,
                                                         component);

  if (converter != null)
  {

    _addFormConverterInfo( converter, convertValidate, clientId);
    _addValidatedInput(clientId);
  }
}
 
Example 4
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 5
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 6
Project: myfaces-trinidad   File: UIXComponent.java   Source Code and License Vote up 5 votes
/**
 * Default implementation of clearing the cached client ids
 */
private static void _clearCachedClientIds(UIComponent component)
{
  // clear this component
  String id = component.getId();
  component.setId(id);

  // clear the children
  Iterator<UIComponent> allChildren = component.getFacetsAndChildren();

  while (allChildren.hasNext())
  {
    clearCachedClientIds(allChildren.next());
  }
}