0

I'm using JSF 2.0. I wanted to use h:dataTable and I realized that the function from value in dataTable is invoked 2 times when I open view in browser.

I'm confused with that and I don't know what I'm doing wrong. Maybe it's normal behaviour(?). Please help.

It will go to System.out.println("getList"); 2 times. It is right?

Here is my code.

Bean class:

package com.sonicwall.es.bean;

import java.util.ArrayList;
import java.util.List;

import javax.faces.bean.ManagedBean;

@ManagedBean
public class UserBean {

private List<String> list=new ArrayList<String>();

public UserBean() {
    list.add("Tom");
    list.add("Andy");
}

public List<String> getList() {
    System.out.println("getList");
    return list;
}

public String getString() {
    System.out.println("getString");
    return "String";
}

}

View

string:

 <h:outputText value="#{userBean.string}" />    

list:

<h:dataTable cellpadding="10" cellspacing="0" border="5"
    value="#{userBean.list}" var="item">
  <h:column>        
    <h:outputText value="#{item}">
    </h:outputText>         
  </h:column>   
</h:dataTable>      
Cœur
  • 37,241
  • 25
  • 195
  • 267
Allen
  • 181
  • 1
  • 2
  • 10

1 Answers1

2

Getters can be called several times during JSF lifecycle. I think these answers to a similar question can help you. This comprehensive tutorial about jsf lifecycle is also useful.

Community
  • 1
  • 1
Matt Handy
  • 29,855
  • 2
  • 89
  • 112