You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Luciano Costa <mo...@gmail.com> on 2007/06/28 19:50:16 UTC

[S2] Master-Detail Form

 

Hi!

 

I have the "Poll" and "PollOption" objects. In my form, I want to be able to
add more options to my Poll via javascript code.

 

The problem is I don't know how to put the fields in my form. The way I try
is not binding the form data with Action properties (a "public Poll poll;"
with getter and setter).

 

My PollAction.poll.pollOptions is null after form submission.

 

Can you help me?

 

 

Sample code I trying:

 

Poll {

  Integer id;

  String question;

  List <PollOption> options;

}

 

 

PollOption {

  Integer id;

  String option;

  Integer totalVotes;

}

 

 

 

My form (freemarker):

 

 

<@s.textfield name="poll.name" />

<@datepicker name="poll.startDate"/>

<@datepicker name="poll.finishDate"/>

<@s.textarea name="poll.question" rows="5"/>

 

<table id="tableAddPollOptions" cellspacing="0" width="100%">


                <tbody>

                <#assign rowIndex = 0>

                <#if poll.pollOptions??>

                                <#list poll.pollOptions as option>

                                                <tr>

                                                                <td>

 
<@s.hidden name="poll.pollOptions[${rowIndex}].id" />

 
<@s.textfield name="poll.pollOptions[${rowIndex}].option" />

 
<input type='button' onclick='dropMyRow(this);' value='remove option'>

                                                                </td>

                                                </tr>

                                                <#assign rowIndex = rowIndex
+ 1>

                                </#list>

                </#if>

                </tbody>


</table>

<br />                   

<a href="javascript:addPollOption();">add option</a>

 

 

Thanks,

 

Luciano Costa


Re: [S2] Master-Detail Form

Posted by Don Brown <do...@gmail.com>.
If you are wanting to do this on the client side via JavaScript, you
won't be using Struts 2 server-side tags.  Look around for JavaScript
tutorials about adding form elements.  Perhaps one of the popular
JavaScript frameworks like Dojo will be of help here.

Don

On 6/29/07, Luciano Costa <mo...@gmail.com> wrote:
>
>
> Hi!
>
>
>
> I have the "Poll" and "PollOption" objects. In my form, I want to be able to
> add more options to my Poll via javascript code.
>
>
>
> The problem is I don't know how to put the fields in my form. The way I try
> is not binding the form data with Action properties (a "public Poll poll;"
> with getter and setter).
>
>
>
> My PollAction.poll.pollOptions is null after form submission.
>
>
>
> Can you help me?
>
>
>
>
>
> Sample code I trying:
>
>
>
> Poll {
>
>   Integer id;
>
>   String question;
>
>   List <PollOption> options;
>
> }
>
>
>
>
>
> PollOption {
>
>   Integer id;
>
>   String option;
>
>   Integer totalVotes;
>
> }
>
>
>
>
>
>
>
> My form (freemarker):
>
>
>
>
>
> <@s.textfield name="poll.name" />
>
> <@datepicker name="poll.startDate"/>
>
> <@datepicker name="poll.finishDate"/>
>
> <@s.textarea name="poll.question" rows="5"/>
>
>
>
> <table id="tableAddPollOptions" cellspacing="0" width="100%">
>
>
>                 <tbody>
>
>                 <#assign rowIndex = 0>
>
>                 <#if poll.pollOptions??>
>
>                                 <#list poll.pollOptions as option>
>
>                                                 <tr>
>
>                                                                 <td>
>
>
> <@s.hidden name="poll.pollOptions[${rowIndex}].id" />
>
>
> <@s.textfield name="poll.pollOptions[${rowIndex}].option" />
>
>
> <input type='button' onclick='dropMyRow(this);' value='remove option'>
>
>                                                                 </td>
>
>                                                 </tr>
>
>                                                 <#assign rowIndex = rowIndex
> + 1>
>
>                                 </#list>
>
>                 </#if>
>
>                 </tbody>
>
>
> </table>
>
> <br />
>
> <a href="javascript:addPollOption();">add option</a>
>
>
>
>
>
> Thanks,
>
>
>
> Luciano Costa
>
>

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