Custom Facelets tag with multiple child components in h: panelGrid

I wrote a special tag that extends UIComponentBase.
It adds several child components ( UIComponent) during the method encodeBegin.

For layout purposes, I would like to nest these child components in h:panelGrid,
but the tag is in the way here.

ExampleTag.java

private ExampleTag extends UIComponentBase {

    public void encodeBegin(FacesContext context) throws IOException {
        getChildren().add(new HtmlLabel());
        getChildren().add(new HtmlOutputText();
    }
}

ExampleOutput.xhtml

<html>
    <h:panelGrid columns="2">
       <foo:exampleTag />
       <foo:exampleTag />
    </h:panelGrid>
</html>

The generated output will have the components HtmlLabeland HtmlOutputin the same cell ,
but I would like to have them in one line, ie two cells .

+3
source share
1 answer
  • h:panelGrid only controls the layout of its own children (and not the children of its children)
  • <foo:exampleTag /> ( ).

h:panelGrid, .

, h:panelGrid ui:include:

    <h:panelGrid columns="2">
      <ui:include src="gridme.xhtml">
        <ui:param name="foo" value="Hello,"/>
        <ui:param name="bar" value="World!"/>
      </ui:include>
      <ui:include src="gridme.xhtml">
        <ui:param name="foo" value="Hello,"/>
        <ui:param name="bar" value="Nurse!"/>
      </ui:include>
    </h:panelGrid>

composition :

<!-- gridme.xhtml -->
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html">
  <h:outputText value="#{foo}" />
  <h:outputText value="#{bar}" />
</ui:composition>

:

<table>
<tbody>
<tr>
<td>Hello,</td>
<td>World!</td>
</tr>
<tr>
<td>Hello,</td>
<td>Nurse!</td>
</tr>
</tbody>
</table>

- - gridme.xhtml, , , NamespaceContainer, .


.

public void encodeBegin(FacesContext context) throws IOException {
  getChildren().add(new HtmlLabel());
  getChildren().add(new HtmlOutputText();
}

. , , . ; . ; (. ) .

+3

All Articles