private void fillContext ( final WComponent component , final VelocityContext context , final Map < String , WComponent > componentsByKey ) { // Also make the component available under the "this" key. context . put ( "this" , component ) ; // Make the UIContext available under the "uicontext" key. UIContext uic = UIContextHolder . getCurrent ( ) ; context . put ( "uicontext" , uic ) ; context . put ( "uic" , uic ) ; if ( component instanceof VelocityProperties ) { Map < ? , ? > map = ( ( VelocityProperties ) component ) . getVelocityMap ( ) ; for ( Map . Entry < ? , ? > entry : map . entrySet ( ) ) { String key = ( String ) entry . getKey ( ) ; Object value = entry . getValue ( ) ; context . put ( key , value ) ; } } if ( LOG . isDebugEnabled ( ) ) { LOG . debug ( "Handling children" ) ; } // As well as going into their own named slots, visible children are also // placed into a list called children ArrayList < String > children = new ArrayList <> ( ) ; if ( component instanceof Container ) { Container container = ( Container ) component ; for ( int i = 0 ; i < container . getChildCount ( ) ; i ++ ) { WComponent child = container . getChildAt ( i ) ; String tag = child . getTag ( ) ; if ( tag != null || child . isVisible ( ) ) { // The key needs to be something which would never be output by a Velocity template. String key = "<VelocityLayout" + child . getId ( ) + "/>" ; componentsByKey . put ( key , child ) ; if ( tag != null ) { if ( LOG . isDebugEnabled ( ) ) { LOG . debug ( "Adding child " + tag + " to context" ) ; } addToContext ( context , tag , key ) ; } if ( child . isVisible ( ) ) { children . add ( key ) ; } } } context . put ( "children" , children ) ; } // Put the context in the context context . put ( "context" , context ) ; }
Fills the given velocity context with data from the component which is being rendered . A map of components is also built up in order to support deferred rendering .