myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Giri Prasad <g_p...@yahoo.com>
Subject Jsf Hibernate problem in SelectOneList event
Date Wed, 30 Jan 2013 13:05:46 GMT
Hello All,

 I have a very simple jsf page and a backing bean for this jsf, which is implemented in hibernate
using Netbeans.

 <Select> button does properly populate the list box. <Details> button does display
the debug message in glassfish log, when no entry in list box is chosen.

 After I press <Select>, choose a entry from the list, pressing <Detail> button,
is not executing the backing bean function 'studDet()'. On this situation, the screen just
refreshes, the list goes empty, and the backing bean function is not executed.

 The same backing bean function ['studDet()']  is executed when nothing is selected from
the list. Apparently the logic when implemented via jpa seems to work just perfectly correctly.

Can any one provide your insights, as why this problem is occuring. Thanks in advance.

Regards,

**************
Code
**************
<%-- 
    Document   : StudentPage.jsp
--%>
 
<%@page contentType="text/html" pageEncoding="UTF-8"%>
 
<%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
 
<f:view>
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
            <title>Student Page</title>
            <h:form>    
 
<h:outputLabel value="Teacher Name    "/>
 
<h:inputText id="Student" value="#{studBean.teacherName}" size="20" maxlength="50">
</h:inputText>
                
                <h:selectOneListbox id="studentList" value="#{studBean.selectedItem}"
 
                                     size="5" >
                    <f:selectItems value="#{studBean.studentList}" />
                </h:selectOneListbox>
 
<h:commandButton id="Select" action="#{studBean.studSel}" value="Select" />
<h:commandButton id="Details" action="#{studBean.studDet}" value="Details" />
 
                
            </h:form>
        </body>
</html>
</f:view>
 
 
*********************************************************
// Backing bean
 
@ManagedBean
@SessionScoped
public class StudBean implements Serializable  {
 
    private String teacherName;
    private List studentList;
 
    // Getter and setter methods omitted
    //
 
    public String studSel() {
        studentlist = new ArrayList();
        List cList = getStudentDetailForTeacher();
        if(cList.isEmpty())
            return null;
        
        for (int i = 0; i < cList.size(); i++) {
            SelectItem studentid = new SelectItem(cList.get(i).toString());
            studentList.add(studentid);
        }
        return null;
    }
 
 
    public List<String[]> getStudentDetailForTeacher() {
        this.session = HibernateUtil.getSessionFactory().getCurrentSession();
        List<String[]> studentlist = null;
        String strQuery = "select c.id.studentId "
                + "from TeacherStudent c WHERE c.id.teacherId = :teachid1";
        org.hibernate.Transaction tx = session.beginTransaction();
        Query cQuery = session.createQuery(strQuery);
 
        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 studDet() {
        System.out.println("studentId id = "+studentId);    
        return null;
    }        
 
} 
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message