You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Pierre-Alain Branger <pb...@ccg.unam.mx> on 2007/02/08 21:25:24 UTC

Undefined number of input parameter in a form.

Hi everybody,

I explain my problem. I am doing an application with struts and velocity
that permit to automatically generate my forms.

To make simple my form would be something like that:

<form name="element" action="$link.setAction("runJob")">
  #foreach ($element in $myBean.listofelements )
    <input type="hidden" name="name" value="$element.name">
    <input type="text" name="value">
  #end
  <input type="submit" value="Run">
</form>

What I need is a way to retreive my parameters in a list or a hashtable of
the same size as the number of elements I have which contains
$element.name and corresponding value enter by users.

I investigated on DynaActionForm but it does not seem that I can do that
with it. So, is Struts permits a such things or is anyone would propose me
an alternative way to do what I want?

Thank you for your help.

Pierre-Alain Branger
Program of Computational Genomics
Campus Morelos
Tel. +52 777 13 100 24
pbranger@ccg.unam.mx

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


Re: Undefined number of input parameter in a form.

Posted by Dave Newton <ne...@yahoo.com>.
--- Pierre-Alain Branger <pb...@ccg.unam.mx> wrote:
> <form-bean name="runJobForm"
>      type="org.apache.struts.action.DynaActionForm">
>      <form-property
>             name="nameParam"
>             type="java.util.ArrayList"/>

<form-property name="nameParam"
type="java.lang.String[]"/> ?

Sorry; I really don't remember :(

d.



 
____________________________________________________________________________________
Do you Yahoo!?
Everyone is raving about the all-new Yahoo! Mail beta.
http://new.mail.yahoo.com

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


Re: Undefined number of input parameter in a form.

Posted by Pierre-Alain Branger <pb...@ccg.unam.mx>.
Well, I have tried the following:

With the following velocity code:

#set( $i = 0 )
#foreach ($param in $dataApplication.paramsList )
  $param.nameparam : $param.descparam
  <input type="hidden" name="nameParam[$i]" value="$param.nameparam">
  <input type="text" name="valueParam[$i]">
  #set( $i = $i +1 )
#end
<input type="submit" value="$text.get("common.run")">

I obtain the following HTML code:

<form name="param" action="/PortalCCG/runJob.do">
  <input type="hidden" name="nameParam[0]" value="i">
  <input type="text" name="valueParam[0]" value="">
  <input type="hidden" name="nameParam[1]" value="toto">
  <input type="text" name="valueParam[1]" value="">
  <input type="submit" value="Run">
</form

Struts-config.xml is defined as is:

<form-bean name="runJobForm"
     type="org.apache.struts.action.DynaActionForm">
     <form-property
            name="nameParam"
            type="java.util.ArrayList"/>
     <form-property
            name="valueParam"
            type="java.util.ArrayList"/>
</form-bean>

And I try to retreive my parameters in my Action Class as is:

DynaActionForm resultJobForm = (DynaActionForm)form;
ArrayList nameParam = (ArrayList)resultJobForm.get("nameParam");
ArrayList valueParam = (ArrayList)resultJobForm.get("valueParam");

But executing, I have the following error:

javax.servlet.ServletException: BeanUtils.populate
	org.apache.struts.util.RequestUtils.populate(RequestUtils.java:1254)

root cause

java.lang.IndexOutOfBoundsException: Index: 1, Size: 0
	java.util.ArrayList.RangeCheck(ArrayList.java:546)
	java.util.ArrayList.set(ArrayList.java:337)
	org.apache.struts.action.DynaActionForm.set(DynaActionForm.java:460)

Some ideas??

Pierre

> Great! I'll test it and let you learn!
>
> Thanks a lot,
>
> Pierre
>
>> --- Pierre-Alain Branger <pb...@ccg.unam.mx> wrote:
>>> Yes I have seen that it is possible to use an
>>> ArrayList in DynaActionForm.
>>> [...]
>>
>> <input type="text" name="value[index]">
>>
>> You may need to just add an index from your iteration
>> to the input tag.
>>
>> http://struts.apache.org/1.2.9/faqs/indexedprops.html
>>
>> might provide more insight than I have time for right
>> now :) But basically if you're building the input tags
>> by hand IIRC you can just add the array notation and
>> as long as it's defined as an array in your ActionForm
>> (or DynaActionForm) you may be okay (I did something
>> similar, also with Velocity).
>>
>> Dave
>>
>>
>>
>>
>> ____________________________________________________________________________________
>> Do you Yahoo!?
>> Everyone is raving about the all-new Yahoo! Mail beta.
>> http://new.mail.yahoo.com
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>
>
> Pierre-Alain Branger
> Program of Computational Genomics
> Campus Morelos
> Tel. +52 777 13 100 24
> pbranger@ccg.unam.mx
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>


Pierre-Alain Branger
Program of Computational Genomics
Campus Morelos
Tel. +52 777 13 100 24
pbranger@ccg.unam.mx

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


Re: Undefined number of input parameter in a form.

Posted by Pierre-Alain Branger <pb...@ccg.unam.mx>.
Great! I'll test it and let you learn!

Thanks a lot,

Pierre

> --- Pierre-Alain Branger <pb...@ccg.unam.mx> wrote:
>> Yes I have seen that it is possible to use an
>> ArrayList in DynaActionForm.
>> [...]
>
> <input type="text" name="value[index]">
>
> You may need to just add an index from your iteration
> to the input tag.
>
> http://struts.apache.org/1.2.9/faqs/indexedprops.html
>
> might provide more insight than I have time for right
> now :) But basically if you're building the input tags
> by hand IIRC you can just add the array notation and
> as long as it's defined as an array in your ActionForm
> (or DynaActionForm) you may be okay (I did something
> similar, also with Velocity).
>
> Dave
>
>
>
>
> ____________________________________________________________________________________
> Do you Yahoo!?
> Everyone is raving about the all-new Yahoo! Mail beta.
> http://new.mail.yahoo.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>


Pierre-Alain Branger
Program of Computational Genomics
Campus Morelos
Tel. +52 777 13 100 24
pbranger@ccg.unam.mx

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


Re: Undefined number of input parameter in a form.

Posted by Dave Newton <ne...@yahoo.com>.
--- Pierre-Alain Branger <pb...@ccg.unam.mx> wrote:
> Yes I have seen that it is possible to use an
> ArrayList in DynaActionForm.
> [...] 

<input type="text" name="value[index]">

You may need to just add an index from your iteration
to the input tag.

http://struts.apache.org/1.2.9/faqs/indexedprops.html

might provide more insight than I have time for right
now :) But basically if you're building the input tags
by hand IIRC you can just add the array notation and
as long as it's defined as an array in your ActionForm
(or DynaActionForm) you may be okay (I did something
similar, also with Velocity).

Dave



 
____________________________________________________________________________________
Do you Yahoo!?
Everyone is raving about the all-new Yahoo! Mail beta.
http://new.mail.yahoo.com

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


Re: Undefined number of input parameter in a form.

Posted by Pierre-Alain Branger <pb...@ccg.unam.mx>.
Hi again,

Yes I have seen that it is possible to use an ArrayList in DynaActionForm.
Maybe you ll be able to enlight me:
- When I use an ArrayList all controls of the same name (<input
type="text" name="value">) added to this list inclusding the empty ones,
isn'it
- Admitting it do, how can I retreive the correspondance between the names
and the values in my Action Class.

Thanks

Pierre

> --- Pierre-Alain Branger <pb...@ccg.unam.mx> wrote:
>> I investigated on DynaActionForm but it does not
>> seem that I can do that with it.
>
> You can't use an array in DynaActionForm?
>
> Dave
>
>
>
>
> ____________________________________________________________________________________
> Don't pick lemons.
> See all the new 2007 cars at Yahoo! Autos.
> http://autos.yahoo.com/new_cars.html
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>


Pierre-Alain Branger
Program of Computational Genomics
Campus Morelos
Tel. +52 777 13 100 24
pbranger@ccg.unam.mx

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


Re: Undefined number of input parameter in a form.

Posted by Dave Newton <ne...@yahoo.com>.
--- Pierre-Alain Branger <pb...@ccg.unam.mx> wrote:
> I investigated on DynaActionForm but it does not
> seem that I can do that with it.

You can't use an array in DynaActionForm?

Dave



 
____________________________________________________________________________________
Don't pick lemons.
See all the new 2007 cars at Yahoo! Autos.
http://autos.yahoo.com/new_cars.html 

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