0

Using seam-gen based code. I have an object "Classroom", which contains an instance of "Location". I want to query for classrooms but specifying a value on the Location object.

Something like 'select from Classroom where Location.State = "NY"'. When I try to bind a selectOneMenu with a list of states to #{ClassroomList.classroom.location.state} I'm getting errors.

Was getting a null pointer exception on Location. I'm assuming I need to instantiate a new "Location" on the Classroom object, but not sure where to do that. On the Classroom entity's constructor? On the ClassroomList backing bean (where the example object is bound to the ClassroomList JSP search fields)?

  • can you post some code? It sounds like you want select a state from a dropdown list and use the selected value to query for classrooms in that state. So you want to set a state as a restriction in your query. I'm not sure what you're doing with `ClassroomList.classroom.location.state` – gebuh May 16 '12 at 00:49

2 Answers2

0

Yes, you need to instantiate ClassroomList.instance.Location. Because the ClassroomList.instance is not bound to the Database, this is not done automagically

arved
  • 4,401
  • 4
  • 30
  • 53
0

Not sure if this is the best way, but I got it working.

I have a String exposed on my ClassroomList backing bean as "String locationState". My dropdown list of states binds to that

Then that's referenced in my restrictions as: ... lower(classroom.location.state) like lower(concat(#{classroomList.locationState}, '%'))", ...

--

When I tried to instantiate ClassroomList.instance.Location, I would get: javax.servlet.ServletException with message: "Id and clazz must not be null" Not sure what's causing that?

  • Your error message seams to be that JSF is unable to convert one of your Entities to something it can printout.I think your solution is ok, as long as you only want to search for one attribute of the location – arved May 18 '12 at 11:48