/**
   * Algorithm works as follows; - If it's an input component, submitted value is checked first
   * since it'd be the value to be used in case validation errors terminates jsf lifecycle - Finally
   * the value of the component is retrieved from backing bean and if there's a converter, converted
   * value is returned
   *
   * <p>- If the component is not a value holder, toString of component is used to support Facelets
   * UIInstructions.
   *
   * @param facesContext FacesContext instance
   * @param component UIComponent instance whose value will be returned
   * @return End text
   */
  public static String getStringValueToRender(FacesContext facesContext, UIComponent component) {
    if (component instanceof ValueHolder) {

      if (component instanceof EditableValueHolder) {
        Object submittedValue = ((EditableValueHolder) component).getSubmittedValue();
        if (submittedValue != null) {
          return submittedValue.toString();
        }
      }

      ValueHolder valueHolder = (ValueHolder) component;
      Object value = valueHolder.getValue();
      if (value == null) return "";

      // first ask the converter
      if (valueHolder.getConverter() != null) {
        return valueHolder.getConverter().getAsString(facesContext, component, value);
      }
      // Try to guess
      else {
        ValueExpression expr = component.getValueExpression("value");
        if (expr != null) {
          Class<?> valueType = expr.getType(facesContext.getELContext());
          if (valueType != null) {
            Converter converterForType = facesContext.getApplication().createConverter(valueType);

            if (converterForType != null)
              return converterForType.getAsString(facesContext, component, value);
          }
        }
      }

      // No converter found just return the value as string
      return value.toString();
    } else {
      // This would get the plain texts on UIInstructions when using Facelets
      String value = component.toString();

      if (value != null) return value.trim();
      else return "";
    }
  }
  protected void setProperties(UIComponent component) {
    super.setProperties(component);
    javax.faces.component.UISelectOne selectone = null;
    try {
      selectone = (javax.faces.component.UISelectOne) component;
    } catch (ClassCastException cce) {
      throw new IllegalStateException(
          "Component "
              + component.toString()
              + " not expected type.  Expected: javax.faces.component.UISelectOne.  Perhaps you're missing a tag?");
    }

    if (converter != null) {
      if (!converter.isLiteralText()) {
        selectone.setValueExpression("converter", converter);
      } else {
        Converter conv =
            FacesContext.getCurrentInstance()
                .getApplication()
                .createConverter(converter.getExpressionString());
        selectone.setConverter(conv);
      }
    }

    if (converterMessage != null) {
      selectone.setValueExpression("converterMessage", converterMessage);
    }

    if (immediate != null) {
      selectone.setValueExpression("immediate", immediate);
    }

    if (required != null) {
      selectone.setValueExpression("required", required);
    }

    if (requiredMessage != null) {
      selectone.setValueExpression("requiredMessage", requiredMessage);
    }

    if (validator != null) {
      selectone.addValidator(new MethodExpressionValidator(validator));
    }
    if (validatorMessage != null) {
      selectone.setValueExpression("validatorMessage", validatorMessage);
    }

    if (value != null) {
      selectone.setValueExpression("value", value);
    }

    if (valueChangeListener != null) {
      selectone.addValueChangeListener(
          new MethodExpressionValueChangeListener(valueChangeListener));
    }
    if (accesskey != null) {
      selectone.setValueExpression("accesskey", accesskey);
    }
    if (dir != null) {
      selectone.setValueExpression("dir", dir);
    }
    if (disabled != null) {
      selectone.setValueExpression("disabled", disabled);
    }
    if (disabledClass != null) {
      selectone.setValueExpression("disabledClass", disabledClass);
    }
    if (enabledClass != null) {
      selectone.setValueExpression("enabledClass", enabledClass);
    }
    if (label != null) {
      selectone.setValueExpression("label", label);
    }
    if (lang != null) {
      selectone.setValueExpression("lang", lang);
    }
    if (onblur != null) {
      selectone.setValueExpression("onblur", onblur);
    }
    if (onchange != null) {
      selectone.setValueExpression("onchange", onchange);
    }
    if (onclick != null) {
      selectone.setValueExpression("onclick", onclick);
    }
    if (ondblclick != null) {
      selectone.setValueExpression("ondblclick", ondblclick);
    }
    if (onfocus != null) {
      selectone.setValueExpression("onfocus", onfocus);
    }
    if (onkeydown != null) {
      selectone.setValueExpression("onkeydown", onkeydown);
    }
    if (onkeypress != null) {
      selectone.setValueExpression("onkeypress", onkeypress);
    }
    if (onkeyup != null) {
      selectone.setValueExpression("onkeyup", onkeyup);
    }
    if (onmousedown != null) {
      selectone.setValueExpression("onmousedown", onmousedown);
    }
    if (onmousemove != null) {
      selectone.setValueExpression("onmousemove", onmousemove);
    }
    if (onmouseout != null) {
      selectone.setValueExpression("onmouseout", onmouseout);
    }
    if (onmouseover != null) {
      selectone.setValueExpression("onmouseover", onmouseover);
    }
    if (onmouseup != null) {
      selectone.setValueExpression("onmouseup", onmouseup);
    }
    if (onselect != null) {
      selectone.setValueExpression("onselect", onselect);
    }
    if (readonly != null) {
      selectone.setValueExpression("readonly", readonly);
    }
    if (style != null) {
      selectone.setValueExpression("style", style);
    }
    if (styleClass != null) {
      selectone.setValueExpression("styleClass", styleClass);
    }
    if (tabindex != null) {
      selectone.setValueExpression("tabindex", tabindex);
    }
    if (title != null) {
      selectone.setValueExpression("title", title);
    }
  }