File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes JSP Radio button iterate problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "JSP Radio button iterate problem" Watch "JSP Radio button iterate problem" New topic
Author

JSP Radio button iterate problem

zsa tan
Greenhorn

Joined: Mar 24, 2009
Posts: 2
Good day,

I hope I'm posting on the right section of the forum, but I really need help badly.

I have an action form let's say. questionform with attributes of string question, question choice 1, question choice 2, question choice 3, question choice 4, and answer. (all with proper getters and setters)
My program requires me to connect to the database, get the quiz the user is taking, and from there, use the information to get the questions of the quiz.
once the user has to answer the quiz, my action class will connect to the database and get all the questions of the quiz,

I stored these in an array list and put it in session.set attribute . I will then be forwarded to a jsp page where the questions are being properly outputed.

Now. My problem is when iterating.

Within my jsp page i have the

<iterate tag>
bean output etc etc
<closing iterate>

my problem comes from trying to create radio buttons for the question choice

thus
<iterate tag>
<html: radio property="choice" etc etc>bean output choice 1
<html: radio property="choice" etc etc>bean output choice 2
<html: radio property="choice" etc etc>bean output choice 3
<html: radio property="choice" etc etc>bean output choice 4

<closing iterate>

The problem with this is, the radio button treats ALL questions as one whole group. I need question 1 to have one radio group. Question 2 to have another and so on.

I tried to define an index id in the iterate and outout it with
<iterate tag indexid=id>
<html: radio property="answers[+index+]" etc etc>bean output choice 1
<html: radio property="answers[+index+]" etc etc>bean output choice 2
<html: radio property="answers[+index+]" etc etc>bean output choice 3
<html: radio property="answers[+index+]" etc etc>bean output choice 4
<closing iterate>

but this doesnt seem to work, any examples? the bean being submitted to contains a string of answers
String answers[]; with getter and setter

How do I go on implementing this? And is there a way to store all these to a bean, even when you don't know how many questions there will be in the first place? Once the user clicks on the sbumit btton, ALL questions(and the answer the user picked) should be stored in the bean.

Ex. Array list of bean?

any help would gratly be appreciated

this is for struts 1.3.8
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9280
    
  17

Hi Zsa, welcome to javaranch.

Well to create separate groups for radio buttons, you need to provide them separate value in the name parameter. So all the options for question one must have name1, for question 2 - name2 and so on. And I think it would be better if you provide some proper code instead of fragments so that we can understand the problem better and help you with your problem.


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSP Radio button iterate problem
 
Similar Threads
need help on jsp and xml
help on jsp and xml
Retrieving value from radio buttons using struts tag(Please let me know if my quest is not clear)
how to group <nested:radio> tag
Adding Dynamic Rows to Table using addrow button