tags:

views:

79

answers:

1

Hello,

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 :)

+2  A: 

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"&gt;
<html 
    xmlns="http://www.w3.org/1999/xhtml" 
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"&gt;
    <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?

BalusC
Great! as always.
Ankit Rathod
Hi BalusC, fortunately/unfortunately, i am yet again using Primefaces :p. With h:dataTable it works fine, but with p:dataTable it doesn't. I am using Mojarra 2.0.2, Glassfish V3.
Ankit Rathod
Ah, good to know. I was about to use Primefaces in an upcoming project. In future questions, it's good to mention name/version of JSF impl and libraries used. They might have their own inconsitenties.
BalusC
Great BalusC, Primefaces is very good except it has many bugs and it is still evolving. I wanted a favor from you for all beginners like me using JSF. You have posted several articles about JSF. If you can just create a simple tutorial for building a simple component like Primefaces using JQUery or Yahoo Yui, it would be great. I inquired on Primefaces and they told me spinner, panel etc are very easy to design. If you can have the time to write such an article, i would be very grateful to you :). May be if you are busy now then after 1 month? If i am asking too much from you then sorry.
Ankit Rathod
I've this in mind. I only wait for Eclipse Helios and Tomcat 7 to be released to have decent Java EE 6 / Servlet 3.0 / JSF 2.0 support in the tutorial. That might be around July/August.
BalusC
Great! Wow, i am waiting for it eagerly :). Please let me know whenever you create it.
Ankit Rathod
Yes, it will be great :) I also had an update of "using datatables" in mind with the -on paper- great `@ViewScope`, but unfortunately it has some serious bugs which make it less intuitive, as you know. I'd also like to wait for the JSF guys to fix them.
BalusC