Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Query regarding stripes:select in Stripes.

 
pawan chopra
Ranch Hand
Posts: 417
jQuery Mac Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I have a Student class which consist of set of courses. Now when a student registers , he can register for more than one course at a time, so in jsp I have used <stripes:select> for a select list with courses in options. I want to ask will Stripes populate it in my Student class or I will have to do it manually? And if I will have to do it manually then should I use the standard way to get value from request object or is there any other way in Stripes?
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, Stripes will populate it in the Student class if you do something like:

 
pawan chopra
Ranch Hand
Posts: 417
jQuery Mac Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have something like this

<stripes:select name="user.courses" size="2" multiple="multiple">
<option value="null"></option>
<option value="java">Java</option>
<option value="qa">QA</option>
<option value="testing">Testing</option>

</stripes:select>


How will I change it according to your example?
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You haven't provided enough information for me to tell you. What is user.courses? A collection of String or a collection of Course objects? If the latter, what are its properties?
 
pawan chopra
Ranch Hand
Posts: 417
jQuery Mac Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, I forgot about that, Its a collection of Course objects, it had name and duration properties. Thanks!
 
pawan chopra
Ranch Hand
Posts: 417
jQuery Mac Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and user.courses is student.courses
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by pawan chopra:
Sorry, I forgot about that, Its a collection of Course objects, it had name and duration properties. Thanks!


Does it have an ID property? Are you saving this stuff in a database? Come on man, get specific. Get detailed. Otherwise, I am just guessing.
 
pawan chopra
Ranch Hand
Posts: 417
jQuery Mac Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am really really sorry, actually its 2:30 am here and I am almost sleeping . anyways Let me explain you, Student class has a Set<Courses> and I am saving it in database using hibernate ,many to many association, Course class also has a Set<Student>, I am having a table called Student_course_relation, where I am saving a relationship of studentId and courseId. Now when a Student registers for some course or courses I want to save that into the database. So for this First I will be getting the names of courses Student wants to register and then I will fetch the Course from database using those names and will presist it in Student. I don't know whether my approach is right or wrong, but I hope that this time I am not missing anything for you . Let me know If I am still incomplete.
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, it would have helped to just show the Course class to me. But I'm going to assume it looks something like this:



So you should populate courses in your JSP from the database. You'd could do it one of a few ways. The simplest is to do this in your action bean:



Then in to setup your select list:



${actionBean.courses} will call the getCourses() method. Then you tell it to use the course.id for the value and course.name for the name. When you submit this Stripes will populate each selected course into student.courses as a Course object with the id of the selected option. So assuming you selected course 1 and 3 student would contain 2 courses, one having an id of 1 and the other an id of 3.

If this isn't working for you then you need to show your code and tell us what specifically doesn't work. Error messages, etc. Now get some sleep.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic