public static void addDatatablesResourceIfNecessary ( String defaultFilename , String type ) { boolean loadDatatables = shouldLibraryBeLoaded ( P_GET_DATATABLE_FROM_CDN , true ) ; // Do we have to add datatables.min.{css|js}, or are the resources already there? FacesContext context = FacesContext . getCurrentInstance ( ) ; UIViewRoot root = context . getViewRoot ( ) ; String [ ] positions = { "head" , "body" , "form" } ; for ( String position : positions ) { if ( loadDatatables ) { List < UIComponent > availableResources = root . getComponentResources ( context , position ) ; for ( UIComponent ava : availableResources ) { if ( ava . isRendered ( ) ) { String name = ( String ) ava . getAttributes ( ) . get ( "name" ) ; if ( null != name ) { name = name . toLowerCase ( ) ; if ( name . contains ( "datatables" ) && name . endsWith ( "." + type ) ) { loadDatatables = false ; break ; } } } } } } if ( loadDatatables ) { addResourceIfNecessary ( defaultFilename ) ; } }
Add the default datatables . net resource if and only if the user doesn t bring their own copy and if they didn t disallow it in the web . xml by setting the context paramter net . bootsfaces . get_datatable_from_cdn to true .