How to make a grid of JSF composite component?

后端 未结 2 1251
感动是毒
感动是毒 2020-11-22 15:27

I have lot\'s of outputLabel and inputText pairs in panelGrids


  
          


        
2条回答
  •  广开言路
    2020-11-22 15:43

    A composite component gets indeed rendered as a single component. You want to use a Facelet tag file instead. It gets rendered exactly as whatever its output renders. Here's a kickoff example assuming that you want a 3-column form with a message field in the third column.

    Create tag file in /WEB-INF/tags/input.xhtml (or in /META-INF when you want to provide tags in a JAR file which is to be included in /WEB-INF/lib).

    
    
        
        
    
        
            
                
            
            
                
            
        
    
        
            
                
                    
                
                
            
            
                
                    
                
                
            
            
                
                    
                    
                
                
            
            
                
                
            
            
                
                
                        
        
    
    

    Define it in /WEB-INF/example.taglib.xml (or in /META-INF when you want to provide tags in a JAR file which is to be included in /WEB-INF/lib):

    
    
        http://example.com/jsf/facelets
        
            input
            tags/input.xhtml
        
    
    

    Declare the taglib usage in /WEB-INF/web.xml (this is not needed when the tags are provided by a JAR file which is included in /WEB-INF/lib! JSF will auto-load all *.taglib.xml files from /META-INF).

    
        javax.faces.FACELETS_LIBRARIES
        /WEB-INF/example.taglib.xml
    
    

    (multiple taglib files can be separated by semicolon ;)

    Finally just declare it in your main page templates.

    
    
        
            Facelet tag file demo
        
        
            
                
                    
                    
                    
                    
                
            
        
    
    

    (the #{bean.countries} should return a Map with country codes as keys and country names as values)

    Screenshot:

    enter image description here

    Hope this helps.

提交回复
热议问题