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

The following are Jave code examples for showing how to use getAttributes() 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.
+ Save this method
Example 1
Project: myfaces-trinidad   File: ProgressRenderer.java   View Source Code Vote up 6 votes
@SuppressWarnings("unchecked")
@Override
public void decode(FacesContext context, UIComponent component)
{
  UIXProgress progressComponent = (UIXProgress)component;
  Map<String, Object> attrs = component.getAttributes();

  Object modelValue= attrs.get(UIConstants.VALUE_PARAM);
  if (modelValue instanceof BoundedRangeModel)
  {
    BoundedRangeModel model = (BoundedRangeModel) modelValue;
    if (model != null)
    {
      long value = model.getValue();
      long maximum = model.getMaximum();
      if (maximum <= value)
      //pu: This means the background task is complete.
      {
        (new ActionEvent(progressComponent)).queue();
      }
    }
  }
}
 
Example 2
Project: myfaces-trinidad   File: TrainRenderer.java   View Source Code Vote up 6 votes
@SuppressWarnings("unchecked")
public Station(
    Train       train,
    UIComponent stamp,
    int         index,
    Object      rowKey,
    boolean     active)
{
  Map<String, Object> attributes = stamp.getAttributes();

  _rowIndex    = index;
  _rowKey      = rowKey;
  _active      = active;
  _visited     = _getBooleanAttribute(attributes, "visited", false);
  _disabled    = _getBooleanAttribute(attributes, "disabled", false);
  _parentEnd   = false;
  _parentStart = false;
  _train       = train;
}
 
Example 3
Project: myfaces-trinidad   File: DateFieldAsRenderer.java   View Source Code Vote up 6 votes
@SuppressWarnings("unchecked")
@Override
public void decode(FacesContext context, UIComponent component)
{
  _addChildren(context, component);

  Map<String, Object> attrs = component.getAttributes();
  if (Boolean.TRUE.equals(attrs.get("readOnly")) ||
      Boolean.TRUE.equals(attrs.get("disabled")))
    return;

  // Just clue in component that we have been "submitted" so
  // that it doesn't short-circuit anything
  EditableValueHolder evh = (EditableValueHolder) component;
  evh.setSubmittedValue(Boolean.TRUE);

  // Because these components weren't around during processDecodes(),
  // they didn't get decoded.  So, run that now.
  component.getFacet("month").processDecodes(context);
  component.getFacet("year").processDecodes(context);
  component.getFacet("day").processDecodes(context);
}
 
Example 4
Project: myfaces-trinidad   File: AttributeComponentChange.java   View Source Code Vote up 6 votes
/**
 * {@inheritDoc}
 */
@Override
@SuppressWarnings("deprecation")
public void changeComponent(UIComponent uiComponent)
{
  Map<String, Object> attributeMap = uiComponent.getAttributes();

  // if the attributevalue is a ValueExpression or ValueBinding, use the
  // appropriate setValueExpression/setValueBinding call and remove the
  // current attribute value, if any, so that the ValueExpression/ValueBinding
  // can take precedence
  if (_attributeValue instanceof ValueExpression)
  {
    uiComponent.setValueExpression(_attributeName, (ValueExpression)_attributeValue);
    attributeMap.remove(_attributeName);
  }
  else if (_attributeValue instanceof ValueBinding)
  {
    uiComponent.setValueBinding(_attributeName, (ValueBinding)_attributeValue);
    attributeMap.remove(_attributeName);
  }
  else
  {
    attributeMap.put(_attributeName, _attributeValue);
  }
}
 
Example 5
Project: myfaces-trinidad   File: ProgressRenderer.java   View Source Code Vote up 5 votes
@SuppressWarnings("unchecked")
@Override
public void encodeBegin(FacesContext context, UIComponent component)
  throws IOException
{
  //pu: This seems to be the best place to validate the model for the value
  Map<String, Object> attrs = component.getAttributes();
  Object modelObject = attrs.get(UIConstants.VALUE_PARAM);
  if (modelObject == null || !(modelObject instanceof BoundedRangeModel))
  {
    _LOG.warning("COMPONENT_VALUE_IS_NOT_VALID_BOUNDEDRANGEMODEL_INSTANCE", component.getId());
  }
  super.encodeBegin(context, component);
}
 
Example 6
Project: myfaces-trinidad   File: CommandRenderer.java   View Source Code Vote up 5 votes
@SuppressWarnings("unchecked")
@Override
public void decode(FacesContext context, UIComponent component)
{
  RequestContext afContext = RequestContext.getCurrentInstance();
  ReturnEvent returnEvent =
    afContext.getDialogService().getReturnEvent(component);
  if (returnEvent != null)
  {
    returnEvent.queue();
  }
  else
  {
    Map<String, String> parameterMap = 
      context.getExternalContext().getRequestParameterMap();
    
    Object source = parameterMap.get("source");
    String clientId = component.getClientId(context);

    if ((source != null) && source.equals(clientId))
    {
      (new ActionEvent(component)).queue();
      Map<String, Object> attrs = component.getAttributes();
      if (Boolean.TRUE.equals(attrs.get("partialSubmit")))
      {
        PartialPageUtils.forcePartialRendering(context);
      }
    }
  }
}
 
Example 7
Project: myfaces-trinidad   File: BandingData.java   View Source Code Vote up 5 votes
/**
 * @param context gets the appropriate banding data from this context.
 */
@SuppressWarnings("unchecked")
public static BandingData create(TableRenderingContext context)
{
  // using the variable name "hgrid" so that we don't forget that
  // the table instance might infact be an hgrid:
  UIComponent hgrid = context.getTable();
  Map<String, Object> attrs = hgrid.getAttributes();
  int row = _getInterval(attrs, CoreTable.ROW_BANDING_INTERVAL_KEY);
  int col = _getInterval(attrs, CoreTable.COLUMN_BANDING_INTERVAL_KEY);
  return new BandingData(col, row);
}
 
Example 8
Project: myfaces-trinidad   File: RowKeySetAttributeChange.java   View Source Code Vote up 5 votes
@Override
@SuppressWarnings("deprecation")
public void changeComponent(UIComponent component)
{
  Map<String, Object> attributeMap = component.getAttributes();

  Object newAttributeValue = getAttributeValue();
  String attrName  = getAttributeName();
  
  if ((newAttributeValue instanceof RowKeySet) || (newAttributeValue == null))
  {
    // Specially handle RowKeySet case by replacing the contents of the RowKeySet in-place
    // rather than replacing the entire object.  This keeps the mutable object instance from
    // changing
    _updateRowKeySetInPlace(component, attrName, (RowKeySet)newAttributeValue);
  }
  else if (newAttributeValue instanceof ValueExpression)
  {
    // if the new attribute value is a ValueExpession, set it and remove the old value
    // so that the ValueExpression takes precedence
    component.setValueExpression(attrName, (ValueExpression)newAttributeValue);
    attributeMap.remove(attrName);
  }
  else if (newAttributeValue instanceof ValueBinding)
  {
    // if the new attribute value is a ValueBinding, set it and remove the old value
    // so that the ValueBinding takes precedence
    component.setValueBinding(attrName, (ValueBinding)newAttributeValue);
    attributeMap.remove(attrName);
  }
  else
  {
    // perform the default behavior
    attributeMap.put(attrName, newAttributeValue);
  }
}
 
Example 9
Project: myfaces-trinidad   File: CoreRenderKit.java   View Source Code Vote up 4 votes
@SuppressWarnings("unchecked")
public boolean launchDialog(
  FacesContext       context,
  UIViewRoot         targetRoot,
  UIComponent        source,
  Map<String,Object> processParameters,
  boolean            useWindow,
  Map<String,Object> windowProperties)
{
  // If we're not being asked to use a separate window,
  // just fallback on the default launchDialog() code
  if (!useWindow)
    return false;

  // And if we don't support separate windows at all, then bail
  // there too
  if (!_supportsSeparateWindow(context))
    return false;

  String sourceId = (source == null) ? null : source.getClientId(context);
  String formId = RenderUtils.getFormId(context, source);

  if (windowProperties == null)
    windowProperties = new HashMap<String,Object>();

  // Copy properties from the source component to the dialog properties
  if (source != null)
  {
    Map<String, Object> sourceAttrs = source.getAttributes();
    _copyProperty(windowProperties, "width", sourceAttrs, "windowWidth");
    _copyProperty(windowProperties, "height", sourceAttrs, "windowHeight");
  }

  Map<String, Object> pageFlowScope = 
    RequestContext.getCurrentInstance().getPageFlowScope();
  
  if (processParameters != null)
    pageFlowScope.putAll(processParameters);

  RequestContext rc = RequestContext.getCurrentInstance();
  DialogRequest request = new DialogRequest(targetRoot,
                                            sourceId,
                                            formId,
                                            windowProperties,
                                            usePopupForDialog(context, rc));
  _getDialogList(context, true).add(request);
  return true;
}
 
Example 10
Project: myfaces-trinidad   File: ComponentRefTag.java   View Source Code Vote up 4 votes
@SuppressWarnings("unchecked")
private boolean _typeConvertAndDefaultAttrs(
  String regionType,
  ComponentMetaData cmd)
{
  boolean hasErrors = false;
  UIComponent region = getComponentInstance();
  Map<String, Object> compAttrs = region.getAttributes();
  List<AttributeMetaData> attrs = cmd.getAttributes();
  int sz = attrs.size();
  for(int i=0; i<sz; i++)
  {
    AttributeMetaData attr = attrs.get(i);
    String name = attr.getAttrName();
    Class<?> klass = attr.getAttrClass();
    if (region.getValueExpression(name) != null)
      continue;

    Object compValue = compAttrs.get(name);
    if (compValue == null)
    {
      // if attribute value was not specified then try to default it:
      String defaultValue = attr.getDefaultValue();
      if (defaultValue != null)
      {
        hasErrors |= _typeConvert(compAttrs, name, defaultValue, klass);
      }
      // if no default value was found then make sure the attribute was not
      // required:
      else if (attr.isRequired())
      {
        _LOG.severe("COMPONENTTYPE_MISSING_ATTRIBUTE", new Object[] {name, regionType});
        hasErrors = true;
      }
    }
    // if a value was specified see if it needs to be type converted:
    else if (compValue instanceof String)
    {
      hasErrors |= _typeConvert(compAttrs, name, (String) compValue, klass);
    }
  }
  return hasErrors;
}
 
Example 11
Project: myfaces-trinidad   File: CommandItemRenderer.java   View Source Code Vote up 4 votes
@SuppressWarnings("unchecked")
@Override
  protected void renderValue(
    UIXRenderingContext context,
    UINode           node,
    Object           value
  )throws IOException
  {         
  

    boolean agentSupportsDisabledOptions = Boolean.TRUE
        .equals(getAgentCapability(context,
            TrinidadAgent.CAP_SUPPORTS_DISABLED_OPTIONS));
    if (!(agentSupportsDisabledOptions))
    {
      
      boolean isReadOnly = BaseLafUtils.getLocalBooleanAttribute(context, 
                                                  node, 
                                                  READ_ONLY_ATTR, 
                                                  false);
      boolean isDisabled = BaseLafUtils.getLocalBooleanAttribute(context, 
                                                  node, 
                                                  DISABLED_ATTR, 
                                                  false);

      if (isReadOnly || isDisabled)
        return;
    }    
  
    UIComponent component = node.getUIComponent() ;
    Map<String, Object> attributes = component.getAttributes();
    Object destination = node.getAttributeValue(context, DESTINATION_ATTR);  
    
    if ( destination != null)
    {
      value = '#' + encodeActionURL(context, destination);
    }
    else if ( value != null)
    {
      boolean immediate = Boolean.TRUE.equals(
                                  attributes.get("immediate")); 
      String validate = immediate?"0":"1";
      value = value.toString() + '[' + validate + ']';
    }
    
    renderAttribute(context, VALUE_ATTRIBUTE, value);
  }