Re: Jsf Hibernate problem in SelectOneList event

2013-01-31 Thread Giri Prasad


if i can clarify, 
1. the details button executes correctly when NO entry in list.
2. When the list is populated the details does not execute.

i am guessing that the select button is generating an error is occurring 
preventing subsequent operations.
easy to confirm, check that h:messages 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 Detail 
button pressed, the screen refreshes, the list empties, and glassfish log shows 
nothing of the output messages in the Detail button handler.

I need to check on the h:messages tag.

Thanks for your inputs.

Regards,

Re: Jsf Hibernate problem in SelectOneList event

2013-01-31 Thread Giri Prasad
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:

    h:selectOneListbox id=studentList 
value=#{studBean.selectedItem}   
    onchange=submit() 
valueChangeListener=#{studBean.studentCodeChanged} size=5  
    f:selectItems value=#{studBean.studentList} / 
    /h:selectOneListbox

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 Detail 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 Detail 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

2013-01-31 Thread Giri Prasad


I recently had a problem with jsf+hibernate, with another control from the 
selectOneXXX family (see 
http://forum.primefaces.org/viewtopic.php?f=3t=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

    ListStudent 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 ListString 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: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.Details1} value=Details /

*
// Backing bean 
 
@ManagedBean 
@SessionScoped 
public class StudBean implements Serializable  { 
 
    private String teacherName; 
    private ListString studentList; 
    private String selectedItem = null;
    private String studentId;
 
    // Getter and setter methods omitted 
    // 
    public String studSel() { 
    studentList = new ArrayListString(); 
    ListString 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 ListString[] getStudentDetailForTeacher() { 
    this.session = HibernateUtil.getSessionFactory().getCurrentSession(); 
    ListString[] 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 = (ListString[]) 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

2013-01-31 Thread l.pe...@senat.fr

On 31/01/2013 16:05, Giri Prasad wrote:


I recently had a problem with jsf+hibernate, with another control from the 
selectOneXXX family (see 
http://forum.primefaces.org/viewtopic.php?f=3t=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

 ListStudent 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 ListString 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?
Can you share an archive of a simple, ideally buildable with maven, 
subset of your project ?


Ludovic
|
| AVANT D'IMPRIMER, PENSEZ A L'ENVIRONNEMENT.
|



Re: Jsf Hibernate problem in SelectOneList event

2013-01-31 Thread Giri Prasad


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 Details button, produces the 
following error, on the web form:

j_id_id12:studentList: Validation Error: Value is not valid 


    h:selectOneListbox id=courseList 
value=#{studBean.courseID}  
    f:selectItems value=#{studBean.courseList} / 
    /h:selectOneListbox 
 
@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

2013-01-30 Thread l.pe...@senat.fr

On 30/01/2013 14:05, Giri Prasad wrote:

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.
I recently had a problem with jsf+hibernate, with another control from 
the selectOneXXX family (see 
http://forum.primefaces.org/viewtopic.php?f=3t=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

ListStudent 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.


Hope this helps,

Ludovic

|
| AVANT D'IMPRIMER, PENSEZ A L'ENVIRONNEMENT.
|


Re: Jsf Hibernate problem in SelectOneList event

2013-01-30 Thread lucio piccoli
On 30 January 2013 23:05, Giri Prasad g_p...@yahoo.com wrote:



  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.


if i can clarify,
1. the details button executes correctly when NO entry in list.
2. When the list is populated the details does not execute.

i am guessing that the select button is generating an error
is occurring preventing subsequent operations.
easy to confirm, check that h:messages tag on page is clear.


-- 
regards

-Lucio Piccoli


Re: Jsf Hibernate problem in SelectOneList event

2013-01-30 Thread Jim May
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
On 30/01/2013 14:05, Giri Prasad wrote:

 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.

I recently had a problem with jsf+hibernate, with another control from the
selectOneXXX family (see http://forum.primefaces.org/**
viewtopic.php?f=3t=27919#**p88162http://forum.primefaces.org/viewtopic.php?f=3t=27919#p88162and
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

ListStudent 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.


Hope this helps,

Ludovic

|
| AVANT D'IMPRIMER, PENSEZ A L'ENVIRONNEMENT.
|