Beans - representing 1-m relationships
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
I am doing it by loading up a separate vector each time the key in the "1" record changes. In my view, I then use an enumeration to loop through each vector, instantiate the bean and call the properties I need at that point (Data is for display only, so not using a control servlet). Just curious if anyone has a better way.
Thanks!
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
I know that isn't technically a bean because I didn't supply a default contsructor and all, but I did that just for brevity. You would have to have a setMethod for flightNo and manually call loadPassengers().
So whereever you make the call to the database to get your list of flights, you would instantiate a new Flight() for each flightNo you got from the database, and then have each Flight object load its passengers. You could then display each flight number followed by a list of the passengers by calling getPassengers().
I would probably do a separate bean (lets call it FlightList) whose function was to make the JDBC call to get the list of flights, instantiate the Flight objects and add them to a Vector, and then have methods for iterating through the vector and returning the proper information, to be called by the JSP. This would keep as much code as possible out of your view. Your view would then only have call FlightList.getFlightTable() for example.
Does this make sense?
Jason Menard
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Does that make sense?
===============================================================
Originally posted by Ed Lance:
We have recently started using java beans and I'm curious about the best way to retrieve and view data from queries involving 1-m realationships. On the veiw (jsp) I only want to display the data from the "1" record once, then loop through the data from the "many" (a basic control-break senario).
I am doing it by loading up a separate vector each time the key in the "1" record changes. In my view, I then use an enumeration to loop through each vector, instantiate the bean and call the properties I need at that point (Data is for display only, so not using a control servlet). Just curious if anyone has a better way.
Thanks!
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Then, in your jsp (or whatever) you could have a vector of Flight objects. Cool.
================================================================
Originally posted by Jason Menard:
[B]If I understand your problem, here's how I would do it. I'll use an example that might be found in an airline scheduling application. Let's say your '1' object is a 'Flight'. A Flight can contain many 'Passengers'.
I know that isn't technically a bean because I didn't supply a default contsructor and all, but I did that just for brevity. You would have to have a setMethod for flightNo and manually call loadPassengers().
So whereever you make the call to the database to get your list of flights, you would instantiate a new Flight() for each flightNo you got from the database, and then have each Flight object load its passengers. You could then display each flight number followed by a list of the passengers by calling getPassengers().
I would probably do a separate bean (lets call it FlightList) whose function was to make the JDBC call to get the list of flights, instantiate the Flight objects and add them to a Vector, and then have methods for iterating through the vector and returning the proper information, to be called by the JSP. This would keep as much code as possible out of your view. Your view would then only have call FlightList.getFlightTable() for example.
Does this make sense?
Jason Menard[/B]
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
| All that thinking. Doesn't it hurt? What do you think about this tiny ad? The new gardening playing cards kickstarter is now live! https://www.kickstarter.com/projects/paulwheaton/garden-cards |







