You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Henry Zhou <zh...@sznjusoft.com> on 2006/03/30 03:27:15 UTC

about h:selectOneMenu works not well

hello everyne, I am in trouble with one problem about h:selectOneMenu,
in the jsp page I can get the dropdownlist from the f:selectItems tag, but
the label display in the default selected item is not the label I should
display in jsp.

there are two tables in this code and one is Employee table,the other is
Department table, and depId is a column in Employee and also a primary key
of Department.

the jsp code :
<h:selectOneMenu id="depId" value="#{loginInfoBean.employee.depId)">
                <f:selectItems value="#{loginInfoBean.departmentList}"/>
            </h:selectOneMenu>

the departmentList generated by below java code then transfer to
LoginInfoBean.java:
while(rs.next()){
            departmentList.add(new
SelectItem(String.valueOf(rs.getInt("depId")),
                    rs.getString("depName")));
        }

and all departmentList get from database is 
depId(int)       depName(varchar)
1            'Administrator'
2            'Network'
3            'Sales'
4             'Engineering'

and in the EmployeeBean.java,I defined a get/set method to convert between
int and String type like below:
private int depId;
 public String getDepId() {
        return String.valueOf(depId);
    }

    public void setDepId(String depId) {
        this.depId = Integer.valueOf(depId).intValue();
    }

now the problem is that:
I get all the departmentList from the database and display in jsp dropdown
list,
the default item in the dropdown list should be 'Sales' which's depId is
from the Employee table, but in fact the default item is always remain
'Administrator' no matter what the department id is in Employee table.

I have boring with this for some days.who can tell me why?

many thanks indeed.
--
View this message in context: http://www.nabble.com/about-h%3AselectOneMenu-works-not-well-t1365967.html#a3662533
Sent from the MyFaces - Users forum at Nabble.com.