/** * Create a label component for the given <code>UIComponent</code>. Clients may override this * method to create a different type of label component. */ protected UIOutput createLabel( FacesContext context, UIComponent componentNeedingLabel ) { HtmlOutputLabel componentLabel = (HtmlOutputLabel) context.getApplication().createComponent( HtmlOutputLabel.COMPONENT_TYPE ); if ( componentNeedingLabel instanceof UIStub ) { // Not setFor on UIStub, because stubs never render id. However we can take a guess if // there's only one child component if ( componentNeedingLabel.getChildren().size() == 1 ) { componentLabel.setFor( componentNeedingLabel.getChildren().get( 0 ).getId() ); } } else if ( componentNeedingLabel.getId() != null ) { componentLabel.setFor( componentNeedingLabel.getId() ); } // Call .setParent before .setId to avoid 'unable to find component with id' warning and/or // 'duplicate component' error (depending on the JSF implementation) if ( componentLabel.getFor() != null ) { componentLabel.setParent( componentNeedingLabel.getParent() ); componentLabel.setId( componentLabel.getFor() + LABEL_ID_SUFFIX ); } return componentLabel; }
/** * Create a label component for the given <code>UIComponent</code>. Clients may override this * method to create a different type of label component. */ protected UIOutput createLabel( FacesContext context, UIComponent componentNeedingLabel ) { HtmlOutputLabel componentLabel = (HtmlOutputLabel) context.getApplication().createComponent( HtmlOutputLabel.COMPONENT_TYPE ); if ( componentNeedingLabel instanceof UIStub ) { // Not setFor on UIStub, because stubs never render id. However we can take a guess if // there's only one child component if ( componentNeedingLabel.getChildren().size() == 1 ) { componentLabel.setFor( componentNeedingLabel.getChildren().get( 0 ).getId() ); } } else if ( componentNeedingLabel.getId() != null ) { componentLabel.setFor( componentNeedingLabel.getId() ); } // Call .setParent before .setId to avoid 'unable to find component with id' warning and/or // 'duplicate component' error (depending on the JSF implementation) if ( componentLabel.getFor() != null ) { componentLabel.setParent( componentNeedingLabel.getParent() ); componentLabel.setId( componentLabel.getFor() + LABEL_ID_SUFFIX ); } return componentLabel; }