Test if ui:insert has been defined in the template client

前端 未结 1 1278
梦毁少年i
梦毁少年i 2020-12-17 18:01

I am wondering if it is possible to know if ui:insert was defined in the ui:composition. I know that I can do it using separate ui:param

1条回答
  •  余生分开走
    2020-12-17 18:38

    ui:param is for me the best way to go. It's just a matter of using it the right way. As a simple example, I define a param here to specify wether there's a sidebar or not. Keep in mind you can define a default insertion definition in the template, so just declare it inside:

    template.xhtml

    
    
        
            
            
        
    
        

    Then couple of views here, one using the sidebar and the other with no sidebar. You can test it and see how the style changes in the browser. You'll notice there's no value for #{noSideBar} in the second one, which will evaluate to false in any EL conditional statement.

    page1.xhtml

    
        
            No sidebar defined? #{noSideBar}
        
    
    

    page2.xhtml

    
        
        
            No sidebar defined? #{noSideBar}
        
    
    

    This way you only need to worry about including the sidebar or not in the client view.

    0 讨论(0)
提交回复
热议问题