aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes accessing object from List of object using JPA & JSTL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "accessing object from List of object using JPA & JSTL" Watch "accessing object from List of object using JPA & JSTL" New topic
Author

accessing object from List of object using JPA & JSTL

Sammy Robert
Greenhorn

Joined: Oct 14, 2011
Posts: 5
Hi,
I am trying to access the object from a list of objects using JSP & JSTL without any success. I'm using JPA.

DvdRecord.java



Record.java


Now, in the JSP page


The output is printed when I do b1[0] but its 1 line with all the track names. However the 2nd output i.e. b1[0].track when used gives error saying it can't find 'track'. I want to display the track and the corresponding album name in a tabular format. How do I access the track or album variable in the for each loop of JSTL. I guess the problem is with the way JPA query puts the result into the list.

Thanks for the help.
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3838

Welcome to CodeRanch!

However the 2nd output i.e. b1[0].track when used gives error saying it can't find 'track'.

Can you show us the exact exception you see in the JSP?


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Sammy Robert
Greenhorn

Joined: Oct 14, 2011
Posts: 5
Below is the error

This is from the glassfish server output window. (I am using NetBeans IDE to develop the project)


The error says that there is no method in the list with the name 'track' I even tried using the get property as .getTrack() without any luck. However I'm populating the bRListM (which is list of Record objects) as shown previously in the DvdRecord.java class. I'm not sure but i think the way JPA query is inserting into the list is not proper. Any feedback would be appreciated.
Thank You.
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3838

...The class 'java.lang.String' does not have the property 'track'.

According to this it looks like that the expression "b1[0]" returns a String value not an object where you expect it to be...

And what is the relationship between DvdRecord and the Record classes? Are you populating and using the correct domain class here?
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: accessing object from List of object using JPA & JSTL