public static String getAttributeAsString ( UIComponent component , String attributeName ) { try { Object attribute = getAttribute ( component , attributeName ) ; if ( null != attribute ) { if ( attribute instanceof ValueExpression ) { return ( String ) ( ( ValueExpression ) attribute ) . getValue ( FacesContext . getCurrentInstance ( ) . getELContext ( ) ) ; } else if ( attribute instanceof String ) { return ( String ) attribute ; } else { LOGGER . severe ( "unexpected data type of label: " + attributeName + " type:" + attribute . getClass ( ) . getName ( ) ) ; return "unexpected data type of label: " + attributeName + " type:" + attribute . getClass ( ) . getName ( ) ; } } if ( null == attribute ) { ValueExpression vex = component . getValueExpression ( attributeName ) ; if ( null != vex ) { return ( String ) vex . getValue ( FacesContext . getCurrentInstance ( ) . getELContext ( ) ) ; } } } catch ( ClassCastException error ) { LOGGER . fine ( "Attribute is not a String: " + attributeName ) ; } return null ; }
Apache MyFaces sometimes returns a ValueExpression when you read an attribute . Mojarra does not but requires a second call . The method treats both frameworks in a uniform way and evaluates the expression if needed returning a String value .