Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Option collections problem

 
Gizzmo Zeuzere
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello!
I have a bean called Student (with name, forname...)
All the students are stored in a database.
But when i return the collection of my students, i dont know how getting the names in my jsp page in order to do a optionscollection.
Can anyone help ?
Thanks !
 
Norma Caballero
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, if what you want to display is a select with all your students names, you would need to create a collection, for example a list with only the names of the students and then in your jsp you would do something like:

Hope this helps.
 
Gizzmo Zeuzere
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes sorry.I 've not noticed that i 've my collection. It's a collection of student beans. And i want to extract only their names and fornames in the select. How can i do that ?
Thanks
 
Norma Caballero
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I understand you have a property name and a property forname, separated.
So you would iterate through your beans collection and create a list...for example:

In your formbean you must have a property to set the list and then you would do:

And in your jsp you would do something like the example I gave you on my previous reply.
Hope I made myself clear Good luck!
 
Norma Caballero
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry I didn't specify something. The iteration an creation of the list should not be done in the jsp, in the jsp you only put the select tag. You could do this in your action class or somewhere else.
 
Gizzmo Zeuzere
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Re hello !
My real problem is not the realisation of the collection.
I've the collection with all my students.
My problem is how to access to an attribute of the collection in the jsp
<html:select .... ?
But Thank for your responses
 
Norma Caballero
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I don't understand what you are trying to do.. I would like to help.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic