You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Lally Singh <la...@gmail.com> on 2007/06/06 22:05:31 UTC

[S2] Basic form with Radio Buttons

Hey all,  a few questions about getting started with a form in Struts 2.

Questions
---------
  The scenario: an action generates a form (from a
dynamically-generated list of questions, called a Survey), that's then
submitted.

  I have a class, QuestionGeneratorAction, with two methods:
    - quesionGroups() which generates a survey to fill out
    - saveSurvey() which saves the survey.

  Will the form submit to saveSurvey hit the same instance of
QuestionGeneratorAction as the one that generated the survey
originally?  If not:
    - Can I make it do that?
       - I'm using Spring in my project (but not for this part -- just
DAOs for now), can that help?
    - If not, where can I store the generated survey?
    - Am I missing the whole point of this?

  If it does already, then how do I get a <s:radio> to eventually
result in a call to Response.setValue(int)?  (see Background, below).

Background
----------

The survey's a field in QuestionGeneratorAction, an instance of a
class called Survey, which just has a list of ResponseGroups, which in
turn has a list of Responses.

  The JSP is this: (severely stripped down)
<s:form action="saveSurvey" theme="iddl" validate="false">
	<s:iterator value="survey.responseGroups">
		<s:iterator value="responses">
			<s:radio name="value" list="{1,2,3,4}" />
                             <!-- that should hit the 'setValue(int)'
method of Response -->
		</s:iterator>
	</s:iterator>
	<s:submit />
</s:form>

(my custom theme iddl just formats the <s:radio> into a table, the
rest is copied from xhtml).


Thanks in advance for any help!!

-- 
H. Lally Singh
Ph.D. Candidate, Computer Science
Virginia Tech

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


Re: [S2] Basic form with Radio Buttons

Posted by Lally Singh <la...@gmail.com>.
Ok, I put my survey in my session.  That's working fine.

So, another question, (with the same situation), how do I use a
<s:radio> inside an <s:iterator>?

E.g. I've got a set of Responses inside a list of ResponseGroups, and
iterating through, it seems that the radio button doesn't know how to
bind itself to the object on top of the OGNL stack.

My generated HTML is like this:

<input type="radio" name="value" id="saveSurvey_value1" value="1"/>
<input type="radio" name="value" id="saveSurvey_value2" value="2"/>
<input type="radio" name="value" id="saveSurvey_value3" value="3"/>
<input type="radio" name="value" id="saveSurvey_value4" value="4"/>

Which is clearly not what I want.  How do I get the inputs to map to
specific elements of a container?

I've also tried this:
<s:radio name="#session.survey_current.responseGroups[%{#rgnum}].responseForId(%{question.id}).value"
list="{1,2,3,4}" />

But that doesn't seem to do it (responseGroups is a list, and
responseForId looks up the ID# in a set).

Thanks in advance for any help!
Lally Singh <la...@gmail.com> wrote:
> Hey all,  a few questions about getting started with a form in Struts 2.
>
> Questions
> ---------
>   The scenario: an action generates a form (from a
> dynamically-generated list of questions, called a Survey), that's then
> submitted.
>
>   I have a class, QuestionGeneratorAction, with two methods:
>     - quesionGroups() which generates a survey to fill out
>     - saveSurvey() which saves the survey.
>
>   Will the form submit to saveSurvey hit the same instance of
> QuestionGeneratorAction as the one that generated the survey
> originally?  If not:
>     - Can I make it do that?
>        - I'm using Spring in my project (but not for this part -- just
> DAOs for now), can that help?
>     - If not, where can I store the generated survey?
>     - Am I missing the whole point of this?
>
>   If it does already, then how do I get a <s:radio> to eventually
> result in a call to Response.setValue(int)?  (see Background, below).
>
> Background
> ----------
>
> The survey's a field in QuestionGeneratorAction, an instance of a
> class called Survey, which just has a list of ResponseGroups, which in
> turn has a list of Responses.
>
>   The JSP is this: (severely stripped down)
> <s:form action="saveSurvey" theme="iddl" validate="false">
>         <s:iterator value="survey.responseGroups">
>                 <s:iterator value="responses">
>                         <s:radio name="value" list="{1,2,3,4}" />
>                              <!-- that should hit the 'setValue(int)'
> method of Response -->
>                 </s:iterator>
>         </s:iterator>
>         <s:submit />
> </s:form>
>
> (my custom theme iddl just formats the <s:radio> into a table, the
> rest is copied from xhtml).
>
>
> Thanks in advance for any help!!
>
> --
> H. Lally Singh
> Ph.D. Candidate, Computer Science
> Virginia Tech
>


-- 
H. Lally Singh
Ph.D. Candidate, Computer Science
Virginia Tech

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