1
votes

I'm trying to change an JSF 1.1 page to conditionally hide parts of the page. The page is built using intermixed raw HTML and tags. Specifically I have the following:

<table>
  <tr>
    <td>Foo</td>
    <td><h:inputText ... /></td>
  </tr>
  <tr>
    <td>Bar</td>
    <td><h:inputText ... /></td>
  </tr>
  <!-- more stuff, including <h:dataTable>
</table>

I would like to wrap this in a tag that conditionally hides this entire table, but I cannot seem to figure it out. Here's what I've tried:

  • Wrap the markup in a <h:panelGroup rendered="...">. While this correct shows/hides the markup, all raw the HTML is stripped from the generated HTML.
  • Wrap the markup in a <f:verbatim>. This does not work as the verbatim tag does not have a rendered attribute in JSF 1.1
  • Wrap the whole thing in a <h:panelGroup rendered="..."><f:verbatim> combo. This has the same effect as the first attempt.
  • I've also tried <f:view> and <f:subview> to no avail.

I know that it is possible to include JSTL tags in a JSF page and use <c:if> but I would like to avoid this situation. Any ideas?

NOTE: I realize that it is (by some at least) considered bad practice to mix HTML and JSF, however this page was created by someone else, I just have to modify it (its a somewhat large page and the HTML above is just a small snippet from it)..

1

1 Answers

1
votes

Either replace <table> by <h:panelGrid>.

<h:panelGrid columns="2">
  <h:outputText value="Foo" />
  <h:inputText ... />

  <h:outputText value="Bar" />
  <h:inputText ... />

  <!-- more stuff, including <h:dataTable>
</h:panelGrid>

Or make use of CSS display:none/block:

<table style="display: ${some condition ? 'none' : 'block'};">

Or just upgrade to JSF 1.2. Technically, a JSF 1.1 web application can easily be upgraded to JSF 1.2 without any code changes. It's only a matter of updating the JARs and changing the faces-config.xml root declaration to replace the JSF 1.1 DTD by a JSF 1.2 XSD. JSF 1.2 comes with an improved view handler which kills the <f:verbatim> nightmare (i.e. it is not needed anymore). It also comes with many, many bugfixes and performance enhancements you'd be very thankful for.


Unrelated to the concrete problem, as to your statement that mixing HTML and JSF is a bad practice, this isn't necessarily true. At least not since JSF 1.2 anymore. On JSF 1.0/1.1 you'd need to use <f:verbatim> which is in turn indeed a pain to develop/maintain. This caused the wrong myth that mixing JSF/HTML is "bad". See also What are the main disadvantages of Java Server Faces 2.0? for a bit of history on that.