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

The following are Jave code examples for showing how to use getValueExpression() 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: oscm   File: EnumConverter.java   Source Code and License Vote up 6 votes
public Object getAsObject(FacesContext context, UIComponent component,
        String value) {

    if (value == null || component.getValueExpression("value") == null) {
        return null;
    }
    @SuppressWarnings("unchecked")
    Class<? extends Enum<?>> enumType = (Class<? extends Enum<?>>) component
            .getValueExpression("value").getType(context.getELContext());
    for (Enum<?> e : enumType.getEnumConstants()) {
        if (e.toString().equals(value)) {
            return e;
        }
    }
    return null;
}
 
Example 2
Project: myfaces-trinidad   File: SSNConverter.java   Source Code and License Vote up 6 votes
private LabeledFacesMessage _getMessage(
 UIComponent component,
 String text)
{
  // Using the LabeledFacesMessage allows the <tr:messages> component to
  // properly prepend the label as a link.
  LabeledFacesMessage lfm =
    new LabeledFacesMessage(FacesMessage.SEVERITY_ERROR,
                            "Conversion Error", text);
  if (component != null)
  {
    Object label = null;
    label = component.getAttributes().get("label");
    if (label == null)
      label = component.getValueExpression("label");
    if (label != null)
      lfm.setLabel(label);
  }
  return lfm;
}
 
Example 3
Project: myfaces-trinidad   File: DialogServiceImpl.java   Source Code and License Vote up 5 votes
/**
 * Execute any "binding" attributes so that a popped view
 * is properly set up
 */
@SuppressWarnings("unchecked")
private void _executeBindings(FacesContext context, UIComponent component)
{
  ValueExpression expression = component.getValueExpression("binding");
  if (expression != null)
    expression.setValue(context.getELContext(), component);

  Iterator<UIComponent> kids = component.getFacetsAndChildren();
  while (kids.hasNext())
    _executeBindings(context, kids.next());
}
 
Example 4
Project: myfaces-trinidad   File: PasswordValidator.java   Source Code and License Vote up 5 votes
private static Object _getLabel(UIComponent component)
{
  Object o = null;
  if (component != null)
  {
    o = component.getAttributes().get("label");
    if (o == null)
      o = component.getValueExpression("label");
  }
  return o;
}
 
Example 5
Project: myfaces-trinidad   File: MessageFactory.java   Source Code and License Vote up 5 votes
private static Object _getLabel(UIComponent component)
{
  Object o = null;
  if (component != null)
  {
    o = component.getAttributes().get("label");
    if (o == null)
      o = component.getValueExpression ("label");
  }
  return o;
}
 
Example 6
Project: myfaces-trinidad   File: RowKeySetAttributeChange.java   Source Code and License Vote up 5 votes
private void _updateRowKeySetInPlace(UIComponent component, String attrName, RowKeySet newValue)
{
  ValueExpression oldExpression = component.getValueExpression(attrName);
  
  // due to bug in how the trinidad table and tree handle their RowKeySets, always use
  // invoke on component and get the old value in context all of the time for now rather
  // than trying to get the value directly if we don't have an expression
  //use EL to get the oldValue and then determine whether we need to update in place
  final FacesContext context = FacesContext.getCurrentInstance();
              
  context.getViewRoot().invokeOnComponent(
    context,
    _clientId,
    new GetOldValueAndUpdate(oldExpression, attrName, newValue));
}
 
Example 7
Project: ctsms   File: SketchPadRenderer.java   Source Code and License Vote up 5 votes
private Converter getConverter(FacesContext context, UIComponent component) {
	Converter converter = ((UIInput) component).getConverter();
	if (converter != null) {
		return converter;
	}
	ValueExpression exp = component.getValueExpression("value");
	if (exp == null) {
		return null;
	}
	Class valueType = exp.getType(context.getELContext());
	if (valueType == null) {
		return null;
	}
	return context.getApplication().createConverter(valueType);
}
 
Example 8
Project: myfaces-trinidad   File: SelectItemSupport.java   Source Code and License Vote up 4 votes
static public Converter getConverter(
  UIComponent component)
{  
  FacesContext fContext = FacesContext.getCurrentInstance();

  Converter converter = null;
  Class<?> modelClass = null;
  
  ValueExpression expression = component.getValueExpression("value");
  if (expression != null)
  {
    modelClass = expression.getType(fContext.getELContext());
    if (modelClass == null)
    {
      Object o = expression.getValue(fContext.getELContext());
      if (o != null)
      {
        modelClass = o.getClass();
      }
    }
  }

  if ((modelClass != null) && 
      ( modelClass.isArray() ||  modelClass.isAssignableFrom(List.class)))
  {
      // get the itemClass in the case where modelClass is an array or List
      // for instance, in the case of selectManyListbox
      Class<?> itemClass = modelClass.getComponentType();
      if (itemClass != null)
      {
         converter = ConverterUtils.createConverter(fContext, itemClass);           
      }      
  }
  else
  {
    converter = ConverterUtils.createConverter(fContext, modelClass);
  }


  return converter;
}
 
Example 9
Project: myfaces-trinidad   File: ComponentRefTag.java   Source Code and License 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;
}