users@glassfish.java.net

JSF h:dataTable element seems to have a bug

From: <forums_at_java.net>
Date: Sat, 30 Jul 2011 13:47:22 -0500 (CDT)

Hello,

I am building a JSF 2.0 web application using Netbeans 7.0.  I think there
is a bug in the JSF h:datatable element.  Following is a complete
application
that illustrates the problem, consisting of an index.xhtml file and a backing
bean called DataTableTestBean.

If you run this application in Netbeans using Glassfish, you will see that
the
message "inside getDataList()" is output 3 times on the Glassfish server log.
This indicates that each time the index.xhtml file is run, the getDataList()
method referenced by "#{dataTableTestBean.dataList}" is executed 3 times,
whereas (I believe) it should only execute once.

This is problematic for me, since my application has some fairly complex bean
methods, so that it is very inefficient to have them executing multiple times
when only one execution is needed.

Would anyone know anything about this and how to deal with it?

Thanks,

--Dan Schwartz
  Florida State University

:::: index.html file ::::

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd [1]">
<html xmlns="http://www.w3.org/1999/xhtml [2]"
      xmlns:h="http://java.sun.com/jsf/html [3]"
      xmlns:f="http://java.sun.com/jsf/core [4]">
    <h:head>
        <title>Data Table Test</title>
    </h:head>
    <h:body>
        <h1> Data List </h1>
        <br/>
        <h:dataTable value="#{dataTableTestBean.dataList}" var="dl">
            <h:column>
                <f:facet name="header">Data</f:facet>
                #{dl}
            </h:column>
        </h:dataTable>
    </h:body>
</html>

:::: DataTableTestBean.java file ::::

package datatabletest;

import javax.faces.bean.ManagedBean;
import java.util.ArrayList;

@ManagedBean(name = "dataTableTestBean")
public class DataTableTestBean {

    public DataTableTestBean() {
    }
    private ArrayList<String> dataList = null;

    public ArrayList<String> getDataList() {
        System.out.println("inside getDataList()");
        dataList = new ArrayList<String>();
        dataList.add("Data item 1");
        dataList.add("Data item 2");
        return dataList;
    }
}
 


[1] http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd
[2] http://www.w3.org/1999/xhtml
[3] http://java.sun.com/jsf/html
[4] http://java.sun.com/jsf/core

--
[Message sent by forum member 'Dan_Schwartz']
View Post: http://forums.java.net/node/828015