7 Mar 2011

Nested Page Templates

We are provided by quite powerful ADF feature "Page templates". The feature allows us to get common "Look and Feel" of our application, to reuse components, page fragments as well as application logic.
Let's say all pages in my application should have some image header on the top and two buttons (Ok, Cancel) on the bottom. In order to match the requirement I'm going to create page template MaintemplateDef.jspx with the following code:


    
      
        
          
                    
          
          
        
      
      
        
                
      
      
        
        
      
    
    
      
        MaintemplateDef
        
          
            centerFacet
          
        
      
    
  

And it looks like this:

Every page built on this template should provide its specific content within facet "centerFacet".
Ok, let's implement additional requirement - some pages should have space for menu on the left (except header on the top and buttons on the bottom).  We have to complicate our template to match new requirement:

    
      
        
          
          
          
          
        
      
      
        
        
        
          
            
            
          
          
                      
            
          
        
        
        
          
          
                     
        
      
      
        
        
      
    
    
      
        MaintemplateDef
        
          
            centerFacet
          
        
        
          
            menuFacet
          
        
        
          
            centermenuFacet
          
        
        
          
            menuVisible
          
          
            java.lang.Boolean
          
          
            false
          
        
      
    
  
I've added boolean attribute menuVisible and switcher showing panelSplitter with facet for menu. Pages with menu should set attribute menuVisible to true and use facets menuFacet and centermenuFacet. Let's imagine we have one more requirement - some pages should have panelTabbed component instead of left menu. Our page template is going to get more complicated, and it's going to keep complicating with every new requirement. Is it cool? No, it isn't! Some more requirements and our page template will be like a mess. It'll be much more difficult to make any changes and support this template. To resolve the problem I wish I had a possibility to create templates of templates or "nested templates".  And actually we have got it!

This is impossible to create nested page template declaratively with JDeveloper. But we can do it manually! And it works! So, let's go back to the first implementation of our template and create new page template in usual way. Let's call it LeftMenutemplateDef.jspx. We will get the following simple code:

    
      
        LeftMenutemplateDef
      
    
  

The trick is to add reference to MaintemplateDef.jspx manually:


    
    
    
  

    
      
        LeftMenutemplateDef
      
    
  

Now, our LeftMenutemplateDef.jspx template is page template built on MaintemplateDef.jspx. It is nested page template. In order to match the requirement with menu on the left we have to add some code:
  
    
        
          
            
            
          
          
            
            
          
        
      
  
    
      
        LeftMenutemplateDef
        
          
            menuFacet
          
        
        
          
            centerFacet
          
        
      
    
  

And now it looks like this:

Every page with menu on the left has to be built on LeftMenutemplateDef template, every page without menu should be built on MaintemplateDef template.

4 comments:

  1. Too bad that nested templates are not supported. Everyone following your idea needs to be aware that he/she is on unsupported grounds and on their own.

    Instead try and implement template changes using dynamic declarative regions that you can switch using an af:switch statement

    ReplyDelete
  2. Yes, the post describes unsupported feature. That's why it could be interesting. It allows followers to use non-standard approach, off-course on their own risk.
    It's possible to use dynamic regions and switcher, and it is widely used, but solution with nested page templates seems to be more elegant.

    By the way, according to the New Features list, nested page templates are supported now in JDev 11g R2.

    ReplyDelete
  3. Thanks for the post.

    I'm curious to know why nested templates aren't supported in earlier versions of JDev than 11.1.2. What specifically doesn't work? Any idea?

    CM.

    ReplyDelete
  4. Hi Fedor,

    Any updated on Chris' question as to why nested templates are not supported prior to JDev 11.1.2?

    Thanks,
    Candace

    ReplyDelete

Post Comment