struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "venkat reddy" <venkatonf...@gmail.com>
Subject Re: How to get dynamic number of arguments into ActionForm
Date Mon, 05 May 2008 13:17:24 GMT
First thing is I can't use Struts 2.0.

I think you didn't understand my problem. So i'm giving all the details from
struts-config.xml file onwards...

struts-config.xml
============
<form-beans>
        <form-bean name="multipleFieldForm"
type="org.apache.struts.action.DynaActionForm">
            <form-property name="choices" type="java.lang.String[]" />
        </form-bean>
    </form-beans>

pollsForm.jsp
==========
<html:form method="get" action="/multipleForm">
            <html:text property="choices" /><br/>
            <html:text property="choices" /><br/>
            <html:submit />
        </html:form>

If i use the above form the choices that are entered by user are recived in
the ActionForm as follows:

MultipleFormAction.java --- execute()
===========================
DynaActionForm dynaForm = (DynaActionForm)form;
        String[] choices = (String[]) dynaForm.get("choices");
        System.out.println("<ol>");
        for(int i=0;i<choices.length;i++) {
            System.out.println("<li>"+choices[i]+"</li>");
        }
        System.out.println("</ol>");

But if it use the choices fields in array form i.e.,
pollsForm.jsp
==========
<html:form method="get" action="/multipleForm">
            <html:text property="choices[0]" /><br/>
            <html:text property="choices[1]" /><br/>
            <html:submit />
        </html:form>

If i follow the above procedure i'm getting ArrayIndexOutOfBoundsException.
I tried setting size attribute in <form-property> element. But When that
size exceeds i'm getting the same exception.

So what i want is to add dynamic number of choce-fields in the above
html-array type form and get them into my ActionForm object.

Please friends help!!!!!!!!!!!!!!!
On Mon, May 5, 2008 at 6:30 AM, Martin Gainty <mgainty@hotmail.com> wrote:

> Why not use Autocompleter?
>
> When used on the "simple" theme, the autocompleter can be used like the
> ComboBox.
> When used on the "ajax" theme, the list can be retieved from an action.
>
>
> http://struts.apache.org/2.0.6/struts2-core/apidocs/org/apache/struts2/components/Autocompleter.html
> ----- Original Message ----- From: "Mead Lai" <laiqinyi@gmail.com>
> To: "Struts Users Mailing List" <user@struts.apache.org>
> Sent: Sunday, May 04, 2008 8:43 PM
> Subject: Re: How to get dynamic number of arguments into ActionForm
>
>
>
>  List type
>>
>> On Sun, May 4, 2008 at 7:51 PM, venkat reddy <venkatonfire@gmail.com>
>> wrote:
>>
>>> I'm using struts 1.2.7
>>>
>>>  I've a poll-posting-form in adminstrator section of my application.
>>> format
>>>  of the form is as follows.
>>>
>>>  pollsubject: String
>>>  lastDate:String
>>>  choice1:String
>>>  choice2:String
>>>  .
>>>  .
>>>  .
>>>  <a href="addChoice();">Add another option</a>
>>>
>>>  As you can see here, the number of choices are dynamic and i want to add
>>> a
>>>  link to give the administrator another choice field.
>>>
>>>  Now, how can i get these dynamic fields into my ActionForm and what type
>>> of
>>>  object should i declare in <form-beans> tag. explain in detail plz
>>>
>>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message