c:choose not working in JSF

前端 未结 2 1845
花落未央
花落未央 2020-12-20 15:25

I have three values and I want one component to be rendered in the case of first two values and another component for the third value

Below, I have my page :

2条回答
  •  我在风中等你
    2020-12-20 15:47

    Just to add to Mindwin's answer, you need to understand that is a tag handler, when is a UI component. The former is evaluated while component tree is being built, and the latter - while the view is being rendered, i.e. at a later time. In this light, depenence upon var of is what is wrong with your code, as it hasn't been evaluated when comes into play.

    There are two things to be remembered here.

    Use an iterative tag handler, , with your contents:

    
        
            
                
            
            
                Correct!
            
        
    
    

    With this approach both tags run at the same time (view is being built), so the conflicts won't occur. Just remember that in case your bean is view scoped it will be recreated upon every request.

    Use UI component with rendered attribute:

    
        
        
            

    Correct

    In this case everything runs as well at the same time (view is being rendered). Note that you can render a whole bunch of HTML with, for example, , as well as some certain JSF tags like , by using a rendered attribute.


    Ultimately, go ahead with the classic post: JSTL in JSF2 Facelets… makes sense?, to get a full understanding of relationship between tag handlers and UI components.

提交回复
热议问题