示例#1
0
  @Override
  protected void setProperties(UIComponent component) {

    super.setProperties(component);

    UIStub componentStub = (UIStub) component;
    Application application = getFacesContext().getApplication();

    // Action

    if (mAction != null) {
      if (!isValueReference(mAction)) {
        throw MetawidgetException.newException("Action '" + mAction + "' must be an EL expression");
      }

      componentStub.setAction(application.createMethodBinding(mAction, null));
    }

    // Value

    if (mValue != null) {
      if (!isValueReference(mValue)) {
        throw MetawidgetException.newException("Value '" + mValue + "' must be an EL expression");
      }

      componentStub.setValueBinding("value", application.createValueBinding(mValue));
    }

    // Attributes

    if (mStubAttributes != null) {
      if (isValueReference(mStubAttributes)) {
        componentStub.setValueBinding(
            "stubAttributes", application.createValueBinding(mStubAttributes));
      } else {
        componentStub.setStubAttributes(mStubAttributes);
      }
    }
  }
  /**
   * Overridden to process <code>int</code>s using <code>Resources.getIdentifier</code>
   *
   * <p>Resource strings should be of the form <code>@style/section</code>.
   */
  @Override
  protected Object createNative(String name, Class<?> namespace, String recordedText)
      throws Exception {

    if ("int".equals(name) && recordedText.startsWith("@")) {
      Resources resources = mContext.getResources();
      int id = resources.getIdentifier(recordedText, null, null);

      if (id == 0) {
        throw MetawidgetException.newException(
            "Resource.getIdentifier returns 0 for " + recordedText);
      }

      return id;
    }

    return super.createNative(name, namespace, recordedText);
  }