myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Giri Prasad <>
Subject Re: Jsf Hibernate problem in SelectOneList event
Date Thu, 31 Jan 2013 15:05:39 GMT

I recently had a problem with jsf+hibernate, with another control from the selectOneXXX family
(see and later)

My problem was that I was comparing "real" objects and "hibernate proxy" objects. The standard
java equals function just fails in this case. I do not see how you fetch your objects, but
this might be the case.

Your problem might also be simplier. I am also a bit surprised that you return a list of SelectItem
as value for your f:selectItems.

Let say that you have a Student type.
You will then have a

    List<Student> getStudentList()

method and a custom Converter to propertly manage the String <-> Object mapping.

Your selectedItem property should in this case also be of Student type.


Thanks for sharing your thoughts.

I tried the backing bean to use String objects and List<String> for the list box, since
the studentId is a varchar(xx) type in the backend db. The same problem exists, even now.
That is, when only an entry is selected from the list and the <Details> button pressed,
the list empties in the jsf page, the jsf page is refresed, and the "Detail1" function for
the <Detail> button is not being called. This function (Detail1) is called when the
list is empty or when no entry is selected from the list and the when the <Detail> button
is pressed.

Everything works correctly when Jpa is used for data access in the backing bean. Why is there
the problem in the hibernate-jsf interaction?

// Jsf
<h:outputLabel value="Teacher Name    "/>
<h:inputText id="Student" value="#{studBean.teacherName}" size="20" maxlength="50">
                <h:selectOneListbox id="studentList" value="#{studBean.selectedItem}" 

                                     size="5" >
                    <f:selectItems value="#{studBean.studentList}" />
<h:commandButton id="Select" action="#{studBean.studSel}" value="Select" />
<h:commandButton id="Details" action="#{studBean.Details1}" value="Details" />

// Backing bean 
public class StudBean implements Serializable  { 
    private String teacherName; 
    private List<String> studentList; 
    private String selectedItem = null;
    private String studentId;
    // Getter and setter methods omitted 
    public String studSel() { 
        studentList = new ArrayList<String>(); 
        List<String> cList = getStudentDetailForTeacher(); 
            return null; 
        for (int i = 0; i < cList.size(); i++) { 
            String studentid = cList.get(i); 
        return null; 

    public List<String[]> getStudentDetailForTeacher() { 
        this.session = HibernateUtil.getSessionFactory().getCurrentSession(); 
        List<String[]> studentlist = null; 
        String strQuery = "select " 
                + "from TeacherStudent c WHERE = :teachid1";

        org.hibernate.Transaction tx = session.beginTransaction(); 
        Query cQuery = session.createQuery(strQuery); 
        // teacherName is in the jsf page tied to this backing bean member variable
        cQuery.setParameter("teachid1", teacherName); 
        studentlist = (List<String[]>) cQuery.list(); 
        return studentlist; 
    public void studentCodeChanged(ValueChangeEvent e){ 
        studentId = e.getNewValue().toString(); 
                System.out.println("studentId = "+studentId); 
    public Boolean Details1() { 
        System.out.println("studentId id = "+studentId);     
        return null; 
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message