web.xml setup for facelets template and client

后端 未结 2 1646
暗喜
暗喜 2020-12-22 07:50

I\'ve looked at a few resources for JSF and facelets, but don\'t understand a few configuration points. What\'s the distinction between:

         


        
2条回答
  •  一整个雨季
    2020-12-22 08:17

    The desired output (to an extent), in that "bar" is output, from the Hello bean, below:

    thufir@dur:~$ 
    thufir@dur:~$ lynx http://localhost:8080/Birds/falcon.xhtml -dump
                               The Happy Birds Directory
    
    Contents table
         __________________________________________________________________
    
       [1]Home
       [2]Parrot
       [3]Eagle
       [4]Falcon
    
                                         Falcon
    
       The Happy Birds Directory contains birds. bean says bar
    
    References
    
       1. http://localhost:8080/Birds/falcon.xhtml
       2. http://localhost:8080/Birds/falcon.xhtml
       3. http://localhost:8080/Birds/falcon.xhtml
       4. http://localhost:8080/Birds/falcon.xhtml
    thufir@dur:~$ 
    

    index.xhtml:

    
    
    
        
            This and everything before will be ignored
            
                
                    
                
            
            This and everything after will be ignored
        
    
    

    menu:

    
    
        
            This and everything before will be ignored
            
                

    Contents table


    This and everything after will be ignored

    parrot:

    
    
        
            This and everything before will be ignored
            
                
                    
                
                
                    

    Parrot

    Parrots are interesting birds...

    This and everything after will be ignored

    the falcon, speaks, to an extent:

    
    
        
            This and everything before will be ignored
            
                
                    
                
                
                    

    Falcon

    The Happy Birds Directory contains #{directoryBean.totalCount} birds. bean says #{hello.foo()}

    This and everything after will be ignored

    however, output from the directoryBean doesn't get put into the web page.

    the template:

     
    
    
        
            The Happy Birds Directory
            
        
        
            
                

    The Happy Birds Directory

    Welcome to the nest!

    directory bean:

    package dur;
    
    import javax.faces.bean.SessionScoped;
    import javax.inject.Named;
    
    @Named
    @SessionScoped
    public class DirectoryBean {
    
        private int totalCount = 99;
    
        public DirectoryBean() {
        }
    
        public int getTotalCount() {
            System.out.println(totalCount);
            return totalCount;
        }
    
    }
    

    hello bean (note that it's @ManagedBean):

    package dur;
    
    import javax.faces.bean.ManagedBean;
    import javax.faces.bean.SessionScoped;
    import javax.inject.Named;
    
    @Named
    @SessionScoped
    @ManagedBean(name = "hello")
    public class Hello {
    
        public Hello() {
        }
    
        public String foo() {
            return "bar";
        }
    
        public String hi(String name) {
            return "hi " + name;
        }
    
    }
    

    the web.xml:

    
    
        
            javax.faces.DEFAULT_SUFFIX
            .xhtml
        
        
            Faces Servlet
            javax.faces.webapp.FacesServlet
            1
        
        
            Faces Servlet
            *.xhtml
        
        
            
                30
            
        
        
            index.xhtml
        
    
    

提交回复
热议问题