You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Jakub Milkiewicz <jm...@gmail.com> on 2006/07/20 12:56:35 UTC

dynamic checkboxes and radio buttons in one group

Hi
I have a problem with dynamic form handling. On a page i want to present a
list of questions. For each question you need to make an answer, but answer
widgets can be represented as 2 radio buttons or single checkbox. Initially
all answer widgets should be blank - checkboxes unchecked, radio buttons
unselected.
The problem is that i do not know explicite how many questions i need to
dispaly and what kind of answer i need to present i.e. show a checkbox or 2
radiobuttons. Number of questions, text of each question and decision to
show answer widget as 1 checkbox or 2 radiobuttons is read from some kind of
configuration in action that presents me the page.
 I would like to have all these answers stored in my action form mapped to a
single property as some kind of collection (array or list). Also my
actionform is stored in session scope - i know i need to appropraitely reset
the form.
I searched on the web and i found to use multibox for a group of checkboxes.
The problem is that i do not know if i need to present a checkbox or 2
radiobuttons as single answer widget.
All i would like to get is some kind of collection or array in the
form={"yes",null,null,"yes","no",null}
It means that the answer for question 0, 3, 4  was made but answer widget
for question  1 , 2, 5 was left blank.
Does someone have any idea??

Re: dynamic checkboxes and radio buttons in one group

Posted by elan <eh...@yahoo.com>.
I left out of the original post that I am using Struts 2.

-- 
View this message in context: http://www.nabble.com/dynamic-checkboxes-and-radio-buttons-in-one-group-tf1971631.html#a10423856
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: dynamic checkboxes and radio buttons in one group

Posted by elan <eh...@yahoo.com>.
well, the number of questions and set of answers for each are dynamic
(determined at runtime). I could look at the response object but hopefully
there is a cleaner way of implementating this.


Dave Newton-4 wrote:
> 
> --- elan <eh...@yahoo.com> wrote:
>> On submit how do I capture which radio buttons
>> were selected since the radio name field is dynamic?
> 
> Don't make the whole name dynamic; use a map (or
> something similar).
> 
> d.
> 
> 
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around 
> http://mail.yahoo.com 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/dynamic-checkboxes-and-radio-buttons-in-one-group-tf1971631.html#a10423843
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: dynamic checkboxes and radio buttons in one group

Posted by Dave Newton <ne...@yahoo.com>.
--- elan <eh...@yahoo.com> wrote:
> On submit how do I capture which radio buttons
> were selected since the radio name field is dynamic?

Don't make the whole name dynamic; use a map (or
something similar).

d.


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: dynamic checkboxes and radio buttons in one group

Posted by elan <eh...@yahoo.com>.
I am trying to figure out the same thing but using Struts. I have the
following jsp to display my questions.

  <s:form action="Quiz">
      <s:iterator value="questions">
        <s:radio label="${text}" name="${id}" list="answers"/>
      </s:iterator>
      <s:submit key="Save Me" method="save" />
  </s:form>

For example this will display 2 questions and each question has a set of
answers with radio buttons. On submit how do I capture which radio buttons
were selected since the radio name field is dynamic?

-- 
View this message in context: http://www.nabble.com/dynamic-checkboxes-and-radio-buttons-in-one-group-tf1971631.html#a10423148
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: dynamic checkboxes and radio buttons in one group

Posted by Thomas Joseph <th...@kottsoftware.com>.
Hay, do some Google on Struts Nested Forms.

well, this could be of good help to you. (i haven't done much investigations with your needs)
http://www.learntechnology.net/struts-nested.do

Thanks and Regards,
Thomas Joseph 
  ----- Original Message ----- 
  From: Jakub Milkiewicz 
  To: Struts Users Mailing List 
  Sent: Friday, July 21, 2006 1:34 AM
  Subject: Re: dynamic checkboxes and radio buttons in one group


  Hi
  I think i didn't express clearly in my previous mail.
  I will try to do it again.
  In my Configuration file i can have any number of questions, for each
  question i store question text and some kind of flag to indicate if i should
  render single checkbox or 2 radio buttons.
  If i render checkbox then its value is "Yes", if i render 2 radio buttons
  values are "Yes" or "No".
  My config file is read in action that prepares me a page with questions.
  Reading configuration is the only place where i can figure how namy
  questions i need to present. Cause for each question i can have only one
  answer (one of the radio buttons selected or checkbox checked) i want to map
  all answers for questions to a single action form property - let's call it
  questionAnswers. I do not wanna to have a fixed number of properties
  indicating answer for question1, answer for question2, answer for question3
  ...
  Please take a look at example:
  Question1:
   Do you like struts
  Answer:
     YES   NO (2 radio buttons)
  Question2:
   Do you like yourself
  Answers:
     YES  (checkbox)
  Question3:
   Do you feel like a shower
  Answers:
     YES   NO  (2 radio buttons)
  Question4:
   Do you like struts-mailing list
  Answers:
     YES  (checkbox)

  Submitt.

Re: dynamic checkboxes and radio buttons in one group

Posted by Thomas Joseph <th...@kottsoftware.com>.
Hi,

One possible workaround that comes in my mind is to have a DataForm for each widget, assemble them into an ArrayList inside the Action class, according to how you want the q/a to appear. When submitting this page (collection of forms), just do the reverse to know the user response to each widget rendered.

Please let us know, your workaround. I guess there can be more brilliant minds who have much greater solutions to this.

Thanks and Regards,
Thomas Joseph 
  ----- Original Message ----- 
  From: Jakub Milkiewicz 
  To: Struts Users Mailing List 
  Sent: Friday, July 21, 2006 1:34 AM
  Subject: Re: dynamic checkboxes and radio buttons in one group


  Hi
  I think i didn't express clearly in my previous mail.
  I will try to do it again.
  In my Configuration file i can have any number of questions, for each
  question i store question text and some kind of flag to indicate if i should
  render single checkbox or 2 radio buttons.
  If i render checkbox then its value is "Yes", if i render 2 radio buttons
  values are "Yes" or "No".
  My config file is read in action that prepares me a page with questions.
  Reading configuration is the only place where i can figure how namy
  questions i need to present. Cause for each question i can have only one
  answer (one of the radio buttons selected or checkbox checked) i want to map
  all answers for questions to a single action form property - let's call it
  questionAnswers. I do not wanna to have a fixed number of properties
  indicating answer for question1, answer for question2, answer for question3
  ...
  Please take a look at example:
  Question1:
   Do you like struts
  Answer:
     YES   NO (2 radio buttons)
  Question2:
   Do you like yourself
  Answers:
     YES  (checkbox)
  Question3:
   Do you feel like a shower
  Answers:
     YES   NO  (2 radio buttons)
  Question4:
   Do you like struts-mailing list
  Answers:
     YES  (checkbox)

  Submitt.


  After the submission button is pressed i would like to have my action form
  property that conforms to these radiobuttons and  checkboxes looks like this
  ["Yes","Yes",null, null] . It indicates that user selected yes radio button
  for question1 , chcecked checkbox for question2 and didn't select/check any
  answer widget for question3 and question4.
  Obviously after submission form need to be validated. Form can be invalid if
  for some of these questions answer need to be made.
  If form is not valid it should be redispalyed and previously selected
  widgets need to be shown.
  My action form is stored in session scope.
  I hope that;s clear and i belive that someone can help me...

  2006/7/20, Thomas Joseph <th...@kottsoftware.com>:
  >
  > You can try to have an ArrayList/HashMap of HasMaps representing the
  > page/form.  Each Hashmap can hold the Question/Answer set.
  >
  > Please refer to Mapped Properties for more info
  >         1. http://struts.apache.org/1.2.9/faqs/indexedprops.html
  >         2.
  > http://struts.apache.org/1.2.9/userGuide/building_view.html#indexed
  >
  > Pass some flag to decide on wheter to display checkbox or radiobuttons.
  > Hope this will help.
  >
  > Thanks and Regards,
  > Thomas Joseph
  >   ----- Original Message -----
  >   From: Jakub Milkiewicz
  >   To: Struts Users Mailing List
  >   Sent: Thursday, July 20, 2006 4:26 PM
  >   Subject: dynamic checkboxes and radio buttons in one group
  >
  >
  >   Hi
  >   I have a problem with dynamic form handling. On a page i want to present
  > a
  >   list of questions. For each question you need to make an answer, but
  > answer
  >   widgets can be represented as 2 radio buttons or single checkbox.
  > Initially
  >   all answer widgets should be blank - checkboxes unchecked, radio buttons
  >   unselected.
  >   The problem is that i do not know explicite how many questions i need to
  >   dispaly and what kind of answer i need to present i.e. show a checkbox
  > or 2
  >   radiobuttons. Number of questions, text of each question and decision to
  >   show answer widget as 1 checkbox or 2 radiobuttons is read from some
  > kind of
  >   configuration in action that presents me the page.
  >    I would like to have all these answers stored in my action form mapped
  > to a
  >   single property as some kind of collection (array or list). Also my
  >   actionform is stored in session scope - i know i need to appropraitely
  > reset
  >   the form.
  >   I searched on the web and i found to use multibox for a group of
  > checkboxes.
  >   The problem is that i do not know if i need to present a checkbox or 2
  >   radiobuttons as single answer widget.
  >   All i would like to get is some kind of collection or array in the
  >   form={"yes",null,null,"yes","no",null}
  >   It means that the answer for question 0, 3, 4  was made but answer
  > widget
  >   for question  1 , 2, 5 was left blank.
  >   Does someone have any idea??
  >
  >

Re: dynamic checkboxes and radio buttons in one group

Posted by Jakub Milkiewicz <jm...@gmail.com>.
Hi
I think i didn't express clearly in my previous mail.
I will try to do it again.
In my Configuration file i can have any number of questions, for each
question i store question text and some kind of flag to indicate if i should
render single checkbox or 2 radio buttons.
If i render checkbox then its value is "Yes", if i render 2 radio buttons
values are "Yes" or "No".
My config file is read in action that prepares me a page with questions.
Reading configuration is the only place where i can figure how namy
questions i need to present. Cause for each question i can have only one
answer (one of the radio buttons selected or checkbox checked) i want to map
all answers for questions to a single action form property - let's call it
questionAnswers. I do not wanna to have a fixed number of properties
indicating answer for question1, answer for question2, answer for question3
...
Please take a look at example:
Question1:
 Do you like struts
Answer:
   YES   NO (2 radio buttons)
Question2:
 Do you like yourself
Answers:
   YES  (checkbox)
Question3:
 Do you feel like a shower
Answers:
   YES   NO  (2 radio buttons)
Question4:
 Do you like struts-mailing list
Answers:
   YES  (checkbox)

Submitt.


After the submission button is pressed i would like to have my action form
property that conforms to these radiobuttons and  checkboxes looks like this
["Yes","Yes",null, null] . It indicates that user selected yes radio button
for question1 , chcecked checkbox for question2 and didn't select/check any
answer widget for question3 and question4.
Obviously after submission form need to be validated. Form can be invalid if
for some of these questions answer need to be made.
If form is not valid it should be redispalyed and previously selected
widgets need to be shown.
My action form is stored in session scope.
I hope that;s clear and i belive that someone can help me...

2006/7/20, Thomas Joseph <th...@kottsoftware.com>:
>
> You can try to have an ArrayList/HashMap of HasMaps representing the
> page/form.  Each Hashmap can hold the Question/Answer set.
>
> Please refer to Mapped Properties for more info
>         1. http://struts.apache.org/1.2.9/faqs/indexedprops.html
>         2.
> http://struts.apache.org/1.2.9/userGuide/building_view.html#indexed
>
> Pass some flag to decide on wheter to display checkbox or radiobuttons.
> Hope this will help.
>
> Thanks and Regards,
> Thomas Joseph
>   ----- Original Message -----
>   From: Jakub Milkiewicz
>   To: Struts Users Mailing List
>   Sent: Thursday, July 20, 2006 4:26 PM
>   Subject: dynamic checkboxes and radio buttons in one group
>
>
>   Hi
>   I have a problem with dynamic form handling. On a page i want to present
> a
>   list of questions. For each question you need to make an answer, but
> answer
>   widgets can be represented as 2 radio buttons or single checkbox.
> Initially
>   all answer widgets should be blank - checkboxes unchecked, radio buttons
>   unselected.
>   The problem is that i do not know explicite how many questions i need to
>   dispaly and what kind of answer i need to present i.e. show a checkbox
> or 2
>   radiobuttons. Number of questions, text of each question and decision to
>   show answer widget as 1 checkbox or 2 radiobuttons is read from some
> kind of
>   configuration in action that presents me the page.
>    I would like to have all these answers stored in my action form mapped
> to a
>   single property as some kind of collection (array or list). Also my
>   actionform is stored in session scope - i know i need to appropraitely
> reset
>   the form.
>   I searched on the web and i found to use multibox for a group of
> checkboxes.
>   The problem is that i do not know if i need to present a checkbox or 2
>   radiobuttons as single answer widget.
>   All i would like to get is some kind of collection or array in the
>   form={"yes",null,null,"yes","no",null}
>   It means that the answer for question 0, 3, 4  was made but answer
> widget
>   for question  1 , 2, 5 was left blank.
>   Does someone have any idea??
>
>

Re: dynamic checkboxes and radio buttons in one group

Posted by Thomas Joseph <th...@kottsoftware.com>.
You can try to have an ArrayList/HashMap of HasMaps representing the page/form.  Each Hashmap can hold the Question/Answer set.

Please refer to Mapped Properties for more info
        1. http://struts.apache.org/1.2.9/faqs/indexedprops.html
        2. http://struts.apache.org/1.2.9/userGuide/building_view.html#indexed

Pass some flag to decide on wheter to display checkbox or radiobuttons. Hope this will help.

Thanks and Regards,
Thomas Joseph
  ----- Original Message ----- 
  From: Jakub Milkiewicz 
  To: Struts Users Mailing List 
  Sent: Thursday, July 20, 2006 4:26 PM
  Subject: dynamic checkboxes and radio buttons in one group


  Hi
  I have a problem with dynamic form handling. On a page i want to present a
  list of questions. For each question you need to make an answer, but answer
  widgets can be represented as 2 radio buttons or single checkbox. Initially
  all answer widgets should be blank - checkboxes unchecked, radio buttons
  unselected.
  The problem is that i do not know explicite how many questions i need to
  dispaly and what kind of answer i need to present i.e. show a checkbox or 2
  radiobuttons. Number of questions, text of each question and decision to
  show answer widget as 1 checkbox or 2 radiobuttons is read from some kind of
  configuration in action that presents me the page.
   I would like to have all these answers stored in my action form mapped to a
  single property as some kind of collection (array or list). Also my
  actionform is stored in session scope - i know i need to appropraitely reset
  the form.
  I searched on the web and i found to use multibox for a group of checkboxes.
  The problem is that i do not know if i need to present a checkbox or 2
  radiobuttons as single answer widget.
  All i would like to get is some kind of collection or array in the
  form={"yes",null,null,"yes","no",null}
  It means that the answer for question 0, 3, 4  was made but answer widget
  for question  1 , 2, 5 was left blank.
  Does someone have any idea??