f:selectItems seems not correctly

Splash Forums PrettyFaces Users f:selectItems seems not correctly

This topic contains 2 replies, has 2 voices, and was last updated by  xuzhike 11 years, 1 month ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • #17832


    Hi, guys, would you please help on the following question about f:selectItems?


    <h:selectOneMenu id=”province” value=”#{userView.provinceId}”>

    <f:selectItems value=”${userView.provinces}” var=”province”

    itemLabel=”# {province.provinceName}” itemValue=”#{province.provinceId}”/>


    userView – @Scope(“session”), has a getProvinces method:

    public List<Province> getProvinces() {


    //return this.supportService.getAllProvince();

    return buildProvinces();


    private List<Province> buildProvinces(){

    List<Province> provinces = new ArrayList<Province>();

    for(int i=0;i<3;i++){

    Province p = new Province();

    p.setProvinceName(“province – “+i);




    return provinces;


    test result:

    the list.xhtml shown correctly, dropdwon list has three options.

    but per checking the log, found the result:

    23:38:56,140 INFO UserView:94 – userView.getProvinces

    23:38:56,171 INFO UserView:94 – userView.getProvinces

    twice!!!!! why? ( I think it should be once)

    I changed the userView scope, but test same.

    is it JSF implementation defect?

    I use Sun’s implementation.

    thx a lot




    Thats not necessarily a bug in the JSF implementation. Its typical for JSF that getters are called multiple times in the request lifecycle.

    Therefore you should NEVER do expensive stuff (like database queries) in your getters. Instead make sure that the data is initialized correctly by either using something like PrettyFaces page actions or use some kind of lazy initialization like this:

    public class ProvinceBean {

    private List<Province> provinceList = null;

    public List<Province> getProvinces() {

    if(provinceList == null) {
    provinceList = ....; // build list here

    return provinceList;



    thanks you, Christian. I got it.

Viewing 3 posts - 1 through 3 (of 3 total)

The forum ‘PrettyFaces Users’ is closed to new topics and replies.

Comments are closed.