Search code examples
jsf-2richfacesfacelets

Richfaces4.2 conditional rendering issue


We are in process of migrating from JSP VDL to Facelets VDL. We have conditional rendering tag need to be ported to Facelets. Because of && symbol in condition rendering, .xhtml failing in compilation. Any thoughts on how to handle this?

<a4j:outputPanel styleClass="myclass" layout="block"
                         rendered="#{myBean.iscorrect && anotherBean.isCorrect}">
render something here ...

</a4j:outputPanel>

Thanks for your time.


Solution

  • Use and instead of &&. It's also immediately more self-documenting.

    <a4j:outputPanel styleClass="myclass" layout="block"
        rendered="#{myBean.iscorrect and anotherBean.isCorrect}">
    

    The reason is because Facelets is a XML based view technology and that & is a special character in XML representing the start of an entity. The exact Facelets compilation error message which you have gotten should also have hinted something about that. Other special characters to be careful for are < and > which should in EL be replaced by lt and gt respectively.

    This problem is unrelated to RichFaces. You would have exactly the same problem when doing so in standard JSF tags.

    By the way, do you really have a isIscorrect() getter method? It would make more sense to me if you had a private boolean correct; with public boolean isCorrect() method and are evaluating as rendered="#{myBean.correct and anotherBean.correct}".