Conditional rendering of non-JSF components (plain vanilla HTML and template text)

淺唱寂寞╮ 提交于 2019-11-26 11:27:48

问题


I\'m trying to conditionally render a <tr> therefore I cannot use <h:panelGroup> as it will render to <span> or <div>

My current (working) approach is the following:

<h:outputFormat rendered=\"#{negotiator.maySend}\">
    <tr> my tr stuff </tr>
</h:outputFormat>

This works, but I\'m not sure if that\'s the way to abuse <h:outputFormat> - before that I used <h:outputLabel> but this was rendered to <label> in IE.

I have also read the answers to this question, but as mentioned above, they won\'t work for me because of the <tr>: How to not render whole block in JSF?


回答1:


I cannot use <h:panelGroup> as it will render to <span> or <div>

Apparently you didn't test it carefully. The <h:panelGroup> won't render anything if you don't specify attributes which should end up in the client side, like layout, id, styleClass, etc.

Thus, this should technically perfectly work fine.

<h:panelGroup rendered="#{negotiator.maySend}">
    <tr> my tr stuff </tr>
</h:panelGroup>

However, better for the main purpose would be to use <ui:fragment>.

<ui:fragment rendered="#{negotiator.maySend}">
    <tr> my tr stuff </tr>
</ui:fragment>

This is by the way also possible with <f:verbatim>, but this is deprecated since JSF 2.0 as it's designed specifically for usage in JSP.

See also:

  • Alternative to ui:fragment in JSF
  • Conditionally displaying JSF components
  • How to find out client ID of component for ajax update/render? Cannot find component with expression "foo" referenced from "bar"
  • Ajax update/render does not work on a component which has rendered attribute


来源:https://stackoverflow.com/questions/15946985/conditional-rendering-of-non-jsf-components-plain-vanilla-html-and-template-tex

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!