TCM
TCM

Reputation: 16900

expression not working in f:facet? JSF

This expression is not working :-

  <f:facet name="header">
      Search Results for #{SearchResultsBean.searchPhrase}
  </f:facet>

But if i just remove that line from outside f:facet, it works. Why is this happening? Is this the intended behavior? Thanks in advance :)

Upvotes: 1

Views: 3169

Answers (1)

BalusC
BalusC

Reputation: 1108762

I am not sure, but this might be related to the fact that the f:facet can contain only one child. Try this instead:

<f:facet name="header">
    <h:outputText value="Search Results for #{SearchResultsBean.searchPhrase}" />
</f:facet>

or maybe

<f:facet name="header">
    <h:panelGroup>Search Results for #{SearchResultsBean.searchPhrase}</h:panelGroup>
</f:facet>

Update:

I just did a local test and actually, your initial approach works just here.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html 
    xmlns="http://www.w3.org/1999/xhtml" 
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html">
    <h:head>
        <title>test</title>
    </h:head>
    <h:body>
        <h:dataTable value="#{bean.list}" var="item">
            <h:column>
                <f:facet name="header">
                    foo #{bean.text} bar
                </f:facet>
                #{item}
            </h:column>
        </h:dataTable>
    </h:body>
</html>

with

package mypackage;

import java.util.Arrays;
import java.util.List;

import javax.faces.bean.ManagedBean;

@ManagedBean
public class Bean {

    public List<String> getList() {
        return Arrays.asList("foo", "bar");
    }

    public String getText() { 
        return "text";
    }

}

yields

foo text bar
foo
bar

That was using Mojarra 2.0.2 on Tomcat 6.0.20. Which versions was you using? Was your approach similar?

Upvotes: 2

Related Questions