Only 48 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!



  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Selected value in dropdown list In many to many relationship  RSS feed

 
Samar Land
Ranch Hand
Posts: 68
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I have an adddriver form which it contains a dropdown list for team name to select from, (many to many)

Now in editdriver form I would the dropdown list be selected with what I've selected when I add the driver.


In oneToMany (Vehicle - team) relationship it worked fine, I could setAttribute since I have the team entity mapped in the original class like the code below.

VehicleEntity.java


In my controller I did this in Get method


and then in my jsp I did a test to display it.


But in my manyTomany relation since I have a list instead, I'm not sure how I'm going to do it! Please advise. It should be a simple, but my mind just stopped!

Entity


how will I display the team that I added to be selected in my edit page?

I did my best to explain my question, please let me know if I missed anything to mention.
 
Stefan Evans
Bartender
Posts: 1834
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The thing that is confusing me is a statement of exactly what the relationships are.
You mention Team, Vehicle and Driver entities. You have said one to many and many to many relationships - but I can't figure out which entities are involved exactly.

Trying to puzzle it out:
A vehicle as assigned to one team. (Many to one)
A team consists of many drivers
A driver can drive for multiple teams over a series of races?. (Many to many)

You say you have an add driver/edit driver actions.
What are you adding the driver to?
What entity is involved here?
My instinct would be that your join table which associates the driver and team needs to be involved in the solution some how. But how do you know which one of them to use?

 
Samar Land
Ranch Hand
Posts: 68
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for this confusing in my question, I should give more info,

I have add vehicle form and add driver form

In vehicle entity I have ManyToOne relationship



and I could call the teamName in my vehicleController to set the attribute to pass it to my JSP and select the dropdown list for Team name using this code.


Now,

My Driver Entity has the team as list not just as object:


My question,
How can I set the teamName from the listOfTeams list to my dropdown list

I've tried these:
 
Stefan Evans
Bartender
Posts: 1834
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, so if I interpret things right.

Your page to add a vehicle lets you pick one team.
Your page to edit vehicle lets you change that team, and it picks up the current team from the vehicle record.
This works because the vehicle is associated with only one team.

Your page to add a driver lets you pick one team?
Your page to edit a driver runs into trouble, because the driver is associated with multiple teams, and you can't tell which was the one selected on the "add" page to "select" ?

Some questions then:
What is the relationship between driver and team?
Why the Many to Many relationship?
Are there any other rules governing this? For instance can a driver be on only one team at a given point in time? That would intimate you need to capture a date somewhere?

Suggestions:
Find a way to mark one team as "current" for a driver. So you know which to populate the edit form with.
Change your add/edit form to reflect the many to many relationship and provide the ability to add/edit multiple teams to a driver.

 
Samar Land
Ranch Hand
Posts: 68
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your page to add a vehicle lets you pick one team.
Your page to edit vehicle lets you change that team, and it picks up the current team from the vehicle record.


Correct. In edit vehicle page I can pass the teamName in my controller to the dropdown list and it be as selected value in my form.


However, in edit driver I don't know how to pass the teamName to make my dropdown list display the selected value in my form (it shows me the --Select-- option ) since I don't have a selectedTeam assinged in my driver controller



Your page to add a driver lets you pick one team?
Your page to edit a driver runs into trouble, because the driver is associated with multiple teams, and you can't tell which was the one selected on the "add" page to "select" ?

Right, No trouble in my edit driver, it's just can't pass the selected value as i did in my vehicle
 
Stefan Evans
Bartender
Posts: 1834
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your "add driver" page. lets you only pick one team?
How does that work?

What does the data look like after you have added that driver?
 
Samar Land
Ranch Hand
Posts: 68
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Currently it works like this.

in Driver table:
Id Name
5 SamarDriver

Team table:
Id Name
2 TeamName


Team-Driver
driverId teamId
5 2

Change your add/edit form to reflect the many to many relationship and provide the ability to add/edit multiple teams to a driver.

You're right, my form is not correct like the way it is now,
I totally forgot about adding the same driver to two teams :/

the way I'm going to do is adding a link in add driver page, if user click it, I will populate another dropdown Or make my exist dropdown as multi choose.
Thanks a lot fir this conversation that make me think more about this form.

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!