jsf - PrimeFaces Datatable - What is f:facet actually doing? -


looking through primefaces code in app noticed following line:

<f:facet name="header">#{trainsearch.traincount} trains</f:facet> 

it looks overriding header, makes sense, can explain me in little more detail?

what happening line of code?

complete code listed below:

           <p:datatable id = "results" value = "#{trainsearch.trains}" var = "train"     rendered="#{not empty trainsearch.trains}" styleclass = "train-search-table horizontal-border">                 <f:facet name="header">#{trainsearch.traincount} trains</f:facet>                  <p:column headertext = "train id">                     <p:panelgrid columns="1" styleclass = "train-id-grid" layout = "grid">                         <h:outputtext styleclass = "train-id-label" value="#{train.traini}"/>                         <h:outputtext value="#{train.origincitystate} > #{train.destinationcitystate}" />                     </p:panelgrid>                 </p:column>                 <p:column headertext="scheduled departure">                     <h:outputtext value="#{train.formattedscheduleddeparturetext}" />                 </p:column>                 <p:column headertext="scheduled arrival">                     <h:outputtext value="#{train.formattedscheduledarrivaltext}" />                 </p:column>                  <p:column headertext="loco count">                     <h:outputtext value="#{train.lococount}" />                 </p:column>                 <p:column headertext="car count">                     <h:outputtext value="#{train.carcount}" />                 </p:column>             </p:datatable> 

facets in jsf used customize rendering of component, without touching code, header facet in datatable, can put custom code in datatable header, without touching actual primefaces datatable code.

the datatablerenderer (class writes html code of datatable) gets xhtml code put inside facet , renders inside div.

you can see in method encodefacetof datatablerenderer:

protected void encodefacet(facescontext context, datatable table, uicomponent facet, string styleclass) throws ioexception {     if(facet == null)         return;      responsewriter writer = context.getresponsewriter();      writer.startelement("div", null);     writer.writeattribute("class", styleclass, null);      facet.encodeall(context);      writer.endelement("div"); } 

the line facet.encodeall(context); renders code put inside facet html, in render_response jsf phase.


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

http - Safari render HTML as received -