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

The following are Jave code examples for showing how to use setValueBinding() 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: AttributeComponentChange.java   Source Code and License 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 2
Project: myfaces-trinidad   File: RowKeySetAttributeChange.java   Source Code and License 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 3
Project: myfaces-trinidad   File: UIComponentTestCase.java   Source Code and License Vote up 5 votes
/**
 * Tests the update-model-values lifecycle phase.
 */
protected void doTestUpdateModelValues(
  UIViewRoot  root,
  UIComponent component)
{

  Mock mockRenderkit = getMockRenderKitWrapper().getMock();

  Mock mockRenderer = mock(Renderer.class);
  Renderer renderer = (Renderer) mockRenderer.proxy();
  mockRenderkit.stubs().method("getRenderer").will(returnValue(renderer));

  Mock mockBinding = mock(ValueBinding.class);
  ValueBinding binding = (ValueBinding) mockBinding.proxy();

  setCurrentContext(facesContext);

  // if the component is an EditableValueHolder, then the value binding
  // must be updated with the new value before this phase completes.
  if (component instanceof EditableValueHolder)
  {
    EditableValueHolder editable = (EditableValueHolder)component;
    component.setValueBinding("value", binding);
    editable.setValue("newValue");
    mockBinding.expects(atLeastOnce()).method("setValue").with(eq(facesContext), eq("newValue"));

    assertEquals(true, editable.isLocalValueSet());
  }

  doTestUpdateModelValues(facesContext, root, component);

  setCurrentContext(null);

  mockRenderer.verify();
  mockBinding.verify();
}
 
Example 4
Project: myfaces-trinidad   File: TestScript.java   Source Code and License Vote up 4 votes
@SuppressWarnings("unchecked")
@Override
public void apply(FacesContext context, UIComponent component)
{
  Iterator<Test> tests = _delegateTests.iterator();
  
  if (_testComponentId != null)
    component = component.findComponent(_testComponentId); 
  
  while (tests.hasNext())
  {
    Test test = tests.next();
    test.apply(context, component);
  }
  
  Object value = _value;
  
     
  // Hack to test table sort. This is a custom attribute not renderer or component attribute
  if ("tableSortCriteria".equals(_name))
  {
    UIXCollection tableModel = (UIXCollection)  component;
    List<SortCriterion> sortCriteriaList = new ArrayList<SortCriterion>();
    String sortCriterion = (String) _value;
    Boolean isAscending  = 
       new Boolean(sortCriterion.substring(sortCriterion.indexOf(" ")).trim());
    sortCriteriaList.add(new SortCriterion(
          sortCriterion.substring(0,sortCriterion.indexOf(" ")), 
          isAscending.booleanValue()));
    tableModel.setSortCriteria(sortCriteriaList);
  }
  else
  {      
    if ((value instanceof String) &&
        ComponentDefinition.isValueExpression(value.toString()))
    {
      ValueBinding binding = context.getApplication().
        createValueBinding(value.toString());
      component.setValueBinding(_name, binding);
    }
    else
    {
      if (value == null)
        value = "test-" + _name;
  
      component.getAttributes().put(_name, value);
    }
  }
}