1

My composite component (cc) creates an inputText-Field. The important part is, that it is rendered depending on the models property "visible". The model is given to the component via parm "name".

<cc:interface>
  <cc:attribute name="name" required="true"/>
</cc:interface>
<cc:implementation componentType="ch.sbi.pt.components.PMSInputText">
      <h:inputText value="#{cc.attrs.name.value}" rendered="#{cc.attrs.name.visible}"/>
</cc:implementation>

In the view i have a panelGrid with 2 cells/row: the first row has a label and my cc, the second is not important. The label renders itself with the same model-property as my cc does.

<h:panelGrid columns="2">  
   <h:outputText value="Name" rendered="#{person.name.visible}"/>
   <sbic:pmsInputText name="#{person.name}"/> 
   <h:outputText value="Next Label"/>
   <sbic:pmsInputText name="#{something.name}"/>
</h:panelGrid>

The result (and problem) is the following, if "visible"-property returns "false": None of the components are rendered (perfect!) BUT the cc resulting HTML leaves an empty cell (e.g. <td></td>) which results in a ugly layouted HTML-Table (offset one cell):

<table>
<tbody>
<tr>
<td></td>
<td>Next Label</td>
</tr>
....

As far as I understand this has to do with the lifecycle (jstl vs. jsf): my cc renders before the <h:outputText../> but how can i get rid of the empty cell (e.g. <td></td>)? Am i missing something here?

Thanx for your help, experts! Marc

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
MarcG
  • 13
  • 1
  • 3
  • What do you mean with "JSTL vs JSF"? There is no means of any JSTL stuff in this. Aren't you confusing/misunderstanding what JSTL is? Read on: http://stackoverflow.com/tags/jstl/info – BalusC Jul 05 '11 at 09:33
  • Yes I was. My fault. Thank you. – MarcG Jul 05 '11 at 13:04

1 Answers1

2

This is fully expected. The composite component is rendered. Only its children are not. You need to move the rendered attribute to the composite component instead.

<sbic:pmsInputText name="#{person.name}" rendered="#{person.name.visible}" /> 
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • OK, i see the problem. Thank you. My intention with the component was the encapsulation of "rendered"- and "readonly"-attributes to gain efficency and increase readability (only name-attributes in xhtml). I was given the order to make a prototype of a small webapp with jsf and i wanted to impress with clean and easy code to erase doubts about jsf because of complexity. – MarcG Jul 05 '11 at 13:03
  • You may find the example in the composite component wiki page more useful. Put your mouse above the `[composite-component]` tag below the question and wait until a popup shows and then click the *info* link therein: http://stackoverflow.com/tags/composite-component/info For label/input/message groups, you'd rather like to use a simple tag file instead. You can find an example in this answer: http://stackoverflow.com/questions/5713718/how-to-make-a-grid-of-jsf-composite-component/5716633#5716633 – BalusC Jul 05 '11 at 13:08
  • Thank you again, BalusC. I will use the proposed tag file. You saved my day because i was stuck on this... – MarcG Jul 05 '11 at 13:21