seems to always evaluate true in JSF2 Facelets

前端 未结 2 1025
时光取名叫无心
时光取名叫无心 2020-12-28 09:51

I am using JSF2 on Facelets.

I define an in a page:



        
相关标签:
2条回答
  • 2020-12-28 10:22

    Well,

    I used rendered instead, like this:

    <h:panelGroup rendered="#{title!=null}">
    
                    <h1>#{title}</h1>
    
            </h:panelGroup>
    
    0 讨论(0)
  • 2020-12-28 10:27

    The XML namespace is invalid. It should be

    xmlns:c="http://java.sun.com/jsp/jstl/core"
    

    Yes, astonishingly with the /jsp part in the URI! The one without /jsp works only in Facelets 1.x for JSF 1.x. If you have checked the generated HTML output in the webbrowser, you should have noticed as well that the <c:if> is left unparsed in the HTML output.


    That said, you should prefer JSF components over JSTL tags, unless technically impossible (i.e. when you actually want to control the building of the view, not rendering of the view). The h:panelGroup as you found out yourself is a good candidate, however the ui:fragment is a nicer choice since it has less overhead.

    <ui:fragment rendered="#{not empty title}">
        <h1>#{title}</h1>
    </ui:fragment>
    

    Note that due to a mistake of the JSF guys in the <ui:fragment> tag definition file of the initial JSF 2.0 version, Netbeans will jerk that the tag doesn't support the rendered attribute, but this is untrue. It certainly supports it. It has been fixed in JSF 2.1 tag definition.

    See also:

    • JSTL in JSF2 Facelets... makes sense?
    • Alternative to ui:fragment in JSF
    • Conditional rendering of non-JSF components (plain vanilla HTML and template text)
    0 讨论(0)
提交回复
热议问题