You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Nick Broadhurst <ho...@gmail.com> on 2011/02/17 18:04:16 UTC

Handling dynamic set of radio buttons

Hi Folks,

I have a set of radio buttons and text fields that display based on user
selections from prior page. This code:

<s:iterator value="deniedAreas" status="rowstatus">
     <s:property/>
          <s:radio name="conclusion.radio%{#rowstatus.index}"
list="#{'Yes':'Yes','No':'No'}"></s:radio>
          <s:textfield name="conclusion.text%{rowstatus.index}"/>
</s:iterator>

displays it fine and names the radio/text inputs, but is there any other way
to accept this info in my submit action than hard coding the field names in
the Action or the Conclusion entity in the Action? I am trying to avoid that
because everything this section is based on is dynamic. I am using JPA for
persistence, and I can handle this there with @ElementCollection but the
radio/text inputs having different names are getting in the way.

Basically I need to capture a yes/no and explanation of each box selected in
a different part of app.

Any ideas would be appreciated.

Nick

Re: Handling dynamic set of radio buttons

Posted by Dave Newton <da...@gmail.com>.
Yep :)

Check out the type conversion docs; they discuss array and map naming
conventions.

Dave
 On Feb 17, 2011 8:58 PM, "Nick Broadhurst" <ho...@gmail.com> wrote:
> Thanks Dave.
>
> So are you saying have a Map property in the Action and the first radio
> button would have Map position 1 as its name?
>
> Nick
>
> On Thu, Feb 17, 2011 at 2:40 PM, Dave Newton <da...@gmail.com>
wrote:
>
>> Use a map or array rather than actual field names that include the index
as
>> part of the field names.
>>
>> dave
>> On Feb 17, 2011 12:04 PM, "Nick Broadhurst" <ho...@gmail.com> wrote:
>> > Hi Folks,
>> >
>> > I have a set of radio buttons and text fields that display based on
user
>> > selections from prior page. This code:
>> >
>> > <s:iterator value="deniedAreas" status="rowstatus">
>> > <s:property/>
>> > <s:radio name="conclusion.radio%{#rowstatus.index}"
>> > list="#{'Yes':'Yes','No':'No'}"></s:radio>
>> > <s:textfield name="conclusion.text%{rowstatus.index}"/>
>> > </s:iterator>
>> >
>> > displays it fine and names the radio/text inputs, but is there any
other
>> way
>> > to accept this info in my submit action than hard coding the field
names
>> in
>> > the Action or the Conclusion entity in the Action? I am trying to avoid
>> that
>> > because everything this section is based on is dynamic. I am using JPA
>> for
>> > persistence, and I can handle this there with @ElementCollection but
the
>> > radio/text inputs having different names are getting in the way.
>> >
>> > Basically I need to capture a yes/no and explanation of each box
selected
>> in
>> > a different part of app.
>> >
>> > Any ideas would be appreciated.
>> >
>> > Nick
>>

Re: Handling dynamic set of radio buttons

Posted by Nick Broadhurst <ho...@gmail.com>.
Thanks Dave.

So are you saying have a Map property in the Action and the first radio
button would have Map position 1 as its name?

Nick

On Thu, Feb 17, 2011 at 2:40 PM, Dave Newton <da...@gmail.com> wrote:

> Use a map or array rather than actual field names that include the index as
> part of the field names.
>
> dave
>  On Feb 17, 2011 12:04 PM, "Nick Broadhurst" <ho...@gmail.com> wrote:
> > Hi Folks,
> >
> > I have a set of radio buttons and text fields that display based on user
> > selections from prior page. This code:
> >
> > <s:iterator value="deniedAreas" status="rowstatus">
> > <s:property/>
> > <s:radio name="conclusion.radio%{#rowstatus.index}"
> > list="#{'Yes':'Yes','No':'No'}"></s:radio>
> > <s:textfield name="conclusion.text%{rowstatus.index}"/>
> > </s:iterator>
> >
> > displays it fine and names the radio/text inputs, but is there any other
> way
> > to accept this info in my submit action than hard coding the field names
> in
> > the Action or the Conclusion entity in the Action? I am trying to avoid
> that
> > because everything this section is based on is dynamic. I am using JPA
> for
> > persistence, and I can handle this there with @ElementCollection but the
> > radio/text inputs having different names are getting in the way.
> >
> > Basically I need to capture a yes/no and explanation of each box selected
> in
> > a different part of app.
> >
> > Any ideas would be appreciated.
> >
> > Nick
>

Re: Handling dynamic set of radio buttons

Posted by Dave Newton <da...@gmail.com>.
Use a map or array rather than actual field names that include the index as
part of the field names.

dave
 On Feb 17, 2011 12:04 PM, "Nick Broadhurst" <ho...@gmail.com> wrote:
> Hi Folks,
>
> I have a set of radio buttons and text fields that display based on user
> selections from prior page. This code:
>
> <s:iterator value="deniedAreas" status="rowstatus">
> <s:property/>
> <s:radio name="conclusion.radio%{#rowstatus.index}"
> list="#{'Yes':'Yes','No':'No'}"></s:radio>
> <s:textfield name="conclusion.text%{rowstatus.index}"/>
> </s:iterator>
>
> displays it fine and names the radio/text inputs, but is there any other
way
> to accept this info in my submit action than hard coding the field names
in
> the Action or the Conclusion entity in the Action? I am trying to avoid
that
> because everything this section is based on is dynamic. I am using JPA for
> persistence, and I can handle this there with @ElementCollection but the
> radio/text inputs having different names are getting in the way.
>
> Basically I need to capture a yes/no and explanation of each box selected
in
> a different part of app.
>
> Any ideas would be appreciated.
>
> Nick