Re: Jsf Hibernate problem in SelectOneList event
3) Does session scoped have to be used?? Try using a limited scope such as ViewScoped when you don't need to have session scoped objects. --- I made the following changes : Changed the jsf file to use courseid, for the list box, as in below code. Made the bean to view scoped. Implemented equals method using Netbeans code gen function. Selecting a courseid from the list and pressing button, produces the following error, on the web form: j_id_id12:studentList: Validation Error: Value is not valid @ManagedBean @ViewScoped public class StudBean implements Serializable { @Override public boolean equals(Object obj) { if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } final StudBean other = (StudBean) obj; if ((this.courseID == null) ? (other.courseID != null) : !this.courseID.equals(other.courseID)) { return false; } return true; }
Re: Jsf Hibernate problem in SelectOneList event
I recently had a problem with jsf+hibernate, with another control from the selectOneXXX family (see http://forum.primefaces.org/viewtopic.php?f=3&t=27919#p88162 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 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 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 button pressed, the list empties in the jsf page, the jsf page is refresed, and the "Detail1" function for the 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 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 * // Backing bean @ManagedBean @SessionScoped public class StudBean implements Serializable { private String teacherName; private List studentList; private String selectedItem = null; private String studentId; // 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++) { String studentid = cList.get(i); studentList.add(courseid); } return null; } public List getStudentDetailForTeacher() { this.session = HibernateUtil.getSessionFactory().getCurrentSession(); List 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); // teacherName is in the jsf page tied to this backing bean member variable cQuery.setParameter("teachid1", teacherName); studentlist = (List) 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; } }
Re: Jsf Hibernate problem in SelectOneList event
Couple of things I noticed: 1) action method is typically used for returning string for jsf navigation. I have encounter weird issues sometimes with JSF when I use action method as something else than a method called for custom logic with navigation. Give ActionListener a try to see what happens. 2) Was the netbeans debugger used at all?? Try debugging the app and put break points in each of the methods so that you can see what is happening. 3) Does session scoped have to be used?? Try using a limited scope such as ViewScoped when you don't need to have session scoped objects. Jim - 1. I have tried ActionListener as follows. with the rest of the code the same, as in my first post: On this scenario, after the list populates, when I select one entry from the list using the mouse, the screen refresehes and the list goes empty. No backing bean function is called. In this case, the function 'studentCodeChanged' should have been called. But when I press button the value of studentId is null; public void studentCodeChanged(ValueChangeEvent e){ studentId = e.getNewValue().toString(); System.out.println("studentId = "+studentId); } 2. I am extensively using only System.out.println in the backing bean functions. The glassfish log shows my messages on all the conditions, except when selecting a entry from the list and then the button being pressed. As in the prev sentence, the glassfish entry shows nothing. 3. I will try to limit the scope, but will this in any way help to find a solution to this problem. Thanks for your comments. Regards,
Re: Jsf Hibernate problem in SelectOneList event
if i can clarify, 1. the button executes correctly when NO entry in list. 2. When the list is populated the does not execute. i am guessing that the button is generating an error is occurring preventing subsequent operations. easy to confirm, check that tag on page is clear. The details button executes correctly when NO entry is in the list.The details button executes correctly when NO entry is selected from the list. The problem is only when a entry is selected from the list, and the button pressed, the screen refreshes, the list empties, and glassfish log shows nothing of the output messages in the button handler. I need to check on the tag. Thanks for your inputs. Regards,