Did jsf <h:datatable> fetch data two times? [duplicate]
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>
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.
精彩评论