Question

i am createing header for <h:panelgrid> from bean. now this is jsf required code(if i written code in jsf page).

<f:facet name="header">
                        <h:outputText value="Search Template ">
                        </h:outputText>
                    </f:facet>

My Problem is how to add this in bean file with below code.

HtmlPanelGrid mainPanel = new HtmlPanelGrid();
mainPanel.setColumns(1);
mainPanel.setStyleClass("searchtabtemplate");

HtmlOutputLabel htmlOutputLabelObj = new HtmlOutputLabel();
htmlOutputLabelObj.setValue(ApplicationConstants.NO_RECORD_FOUND);

mainPanel.getChildren().add(htmlOutputLabelObj);

I have tried with this code but where i have to use facetTag i dont get idea .

FacetTag facetTag = new FacetTag();
facetTag.setName("header");
HtmlOutputLabel htmlOutputLabel = new HtmlOutputLabel();
htmlOutputLabel.setValue("Search Template");
Was it helpful?

Solution

The UIComponent superclass has a getFacets() method. Guess what it does :)

mainPanel.getFacets().put("header", htmlOutputLabel);

Unrelated to the concrete problem, the HtmlOutputLabel represents the <h:outputLabel> which is the wrong tool for the purpose. Use HtmlOutputText instead which represents <h:outputText>.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top