private static UIComponent createFacetUIPanel ( FaceletContext ctx , UIComponent parent , String facetName ) { FacesContext facesContext = ctx . getFacesContext ( ) ; UIComponent panel = facesContext . getApplication ( ) . createComponent ( facesContext , UIPanel . COMPONENT_TYPE , null ) ; // The panel created by this method is special. To be restored properly and do not // create duplicate ids or any other unwanted conflicts, it requires an unique id. // This code is usually called when more than one component is added to a facet and // it is necessary to create a shared container. // Use FaceletCompositionContext.generateUniqueComponentId() is not possible, because // <c:if> blocks inside a facet will make component ids unstable. Use UniqueIdVendor // is feasible but also will be affected by <c:if> blocks inside a facet. // The only solution that will generate real unique ids is use the parent id and the // facet name and derive an unique id that cannot be generated by SectionUniqueIdCounter, // doing the same trick as with metadata: use a double __ and add a prefix (f). // Note this id will never be printed into the response, because this is just a container. FaceletCompositionContext mctx = FaceletCompositionContext . getCurrentInstance ( ctx ) ; UniqueIdVendor uniqueIdVendor = mctx . getUniqueIdVendorFromStack ( ) ; if ( uniqueIdVendor == null ) { uniqueIdVendor = ComponentSupport . getViewRoot ( ctx , parent ) ; } if ( uniqueIdVendor != null ) { // UIViewRoot implements UniqueIdVendor, so there is no need to cast to UIViewRoot // and call createUniqueId(). See ComponentTagHandlerDelegate int index = facetName . indexOf ( ' ' ) ; String cleanFacetName = facetName ; if ( index >= 0 ) { cleanFacetName = facetName . replace ( ' ' , ' ' ) ; } panel . setId ( uniqueIdVendor . createUniqueId ( facesContext , mctx . getSharedStringBuilder ( ) . append ( parent . getId ( ) ) . append ( "__f_" ) . append ( cleanFacetName ) . toString ( ) ) ) ; } panel . getAttributes ( ) . put ( FACET_CREATED_UIPANEL_MARKER , Boolean . TRUE ) ; panel . getAttributes ( ) . put ( ComponentSupport . COMPONENT_ADDED_BY_HANDLER_MARKER , Boolean . TRUE ) ; return panel ; }
Create a new UIPanel for the use as a dynamically created container for multiple children in a facet . Duplicate in javax . faces . webapp . UIComponentClassicTagBase .