tags:

views:

599

answers:

1

I am learning jsf. I get class cast exception in java.lang.String when I use the following code:

<f:facet name="header">
  <f:subview id="header">
    <tiles:insert attribute="header" flush="false"/>
  </f:subview>
</f:facet>

If I replace the subview id with another name other than header the code runs successfully. Eg

<f:facet name="header">
  <f:subview id="header1">
    <tiles:insert attribute="header" flush="false"/>
  </f:subview>
</f:facet>

I am using core java server faces book by David Geary and Cay Horstmann. The example given in the book has same value for facet name and subview id. Please explain why we should give different values for facet name and subview id.

+1  A: 

The component tree uses ids to reference everything. With jsf you should always reference everything with a unique id or you can let jsf do it but if you do explicitly specify the same name in more than one tag you will have problems.

mugafuga
@mugafuga I don't know if you are correct or not because I am not too familiar with JSF but the example at the link I provided in the comment above has the same code (I assume it came from the same source).
martinatime
@mugafuga - A facet name is not the same as a component id. Facets are used to describe named children (such as the header or footer on a table). An id must be unique in a view; a facet name need not be.
McDowell