You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Aviskaos <jp...@gmail.com> on 2007/05/15 20:43:13 UTC

How to pass a javascript array to formbean array ?

Hi!
In my formbean i have this property:
	private String[] values;

	public String[] getValues() {
		return values;
	}

	public void setValues(String[] values) {
		this.values = values;
	}

Late, in my jsp, i have a global javascript var, an array:
	var myValues = new Array();

that i populate correctly, whit the same dimension, and then when i do 
the submit, i want to do this:
	document.myformbean.values = myArray

But that doesnt work. I try this so:
	document.myformbean.values.value = myArray
and lots of combinations, but nothing. I got a null pointer.

Is this possible ?
How could i do this correctly ?

Thank you very much !


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


Re: How to pass a javascript array to formbean array ?

Posted by Aviskaos <jp...@gmail.com>.
Thank you for your help.
It works fine for me!

Thomas Ramapuram escribió:
> We do this quite often.  We have a method which goes through the array 
> and inserts the elements as new dom input objects of type hidden and 
> name the name of the element in the form bean with an array index.  eg.
> <input type="hidden" name="myelement[0].name" value="Name" />
> do this for all the properties for each element in your array and you 
> will have them in your from bean.
> 
> Frank W. Zammetti wrote:
>> You seem to be mixing server-side and client-side concepts... if I
>> understand you correctly, you have a Javascript array ON THE CLIENT that
>> you want to populate in the form bean ON THE SERVER.  If that's not
>> correct, could you explain it further?
>>
>> If that is correct, you need to pass the array back to the server as part
>> of your form submission (or AJAX request, if your going that route). 
>> Rememeber that at the point your JSP is evaluated, it's on the server, 
>> and
>> Javascript has not executed yet.  Seems like you might be making that
>> mistake, although I'm not sure.
>>
>> Frank
>>
>>   


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


Re: How to pass a javascript array to formbean array ?

Posted by Thomas Ramapuram <th...@gmail.com>.
We do this quite often.  We have a method which goes through the array 
and inserts the elements as new dom input objects of type hidden and 
name the name of the element in the form bean with an array index.  eg.
<input type="hidden" name="myelement[0].name" value="Name" />
do this for all the properties for each element in your array and you 
will have them in your from bean.

Frank W. Zammetti wrote:
> You seem to be mixing server-side and client-side concepts... if I
> understand you correctly, you have a Javascript array ON THE CLIENT that
> you want to populate in the form bean ON THE SERVER.  If that's not
> correct, could you explain it further?
>
> If that is correct, you need to pass the array back to the server as part
> of your form submission (or AJAX request, if your going that route). 
> Rememeber that at the point your JSP is evaluated, it's on the server, and
> Javascript has not executed yet.  Seems like you might be making that
> mistake, although I'm not sure.
>
> Frank
>
>   


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


Re: How to pass a javascript array to formbean array ?

Posted by "Frank W. Zammetti" <fz...@omnytex.com>.
You seem to be mixing server-side and client-side concepts... if I
understand you correctly, you have a Javascript array ON THE CLIENT that
you want to populate in the form bean ON THE SERVER.  If that's not
correct, could you explain it further?

If that is correct, you need to pass the array back to the server as part
of your form submission (or AJAX request, if your going that route). 
Rememeber that at the point your JSP is evaluated, it's on the server, and
Javascript has not executed yet.  Seems like you might be making that
mistake, although I'm not sure.

Frank

-- 
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com
AIM/Yahoo: fzammetti
MSN: fzammetti@hotmail.com
Author of "Practical Ajax Projects With Java Technology"
 (2006, Apress, ISBN 1-59059-695-1)
and "JavaScript, DOM Scripting and Ajax Projects"
 (2007, Apress, ISBN 1-59059-816-4)
Java Web Parts - http://javawebparts.sourceforge.net
 Supplying the wheel, so you don't have to reinvent it!

On Tue, May 15, 2007 2:53 pm, Aviskaos wrote:
> Sorry the var name in the jsp is
> 	var myArray = new Array()
>
>
>
> Aviskaos escribió:
>> Hi!
>> In my formbean i have this property:
>>     private String[] values;
>>
>>     public String[] getValues() {
>>         return values;
>>     }
>>
>>     public void setValues(String[] values) {
>>         this.values = values;
>>     }
>>
>> Late, in my jsp, i have a global javascript var, an array:
>>     var myValues = new Array();
>>
>> that i populate correctly, whit the same dimension, and then when i do
>> the submit, i want to do this:
>>     document.myformbean.values = myArray
>>
>> But that doesnt work. I try this so:
>>     document.myformbean.values.value = myArray
>> and lots of combinations, but nothing. I got a null pointer.
>>
>> Is this possible ?
>> How could i do this correctly ?
>>
>> Thank you very much !
>
>
> ---------------------------------------------------------------------
> 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


Re: How to pass a javascript array to formbean array ?

Posted by Aviskaos <jp...@gmail.com>.
Sorry the var name in the jsp is
	var myArray = new Array()



Aviskaos escribió:
> Hi!
> In my formbean i have this property:
>     private String[] values;
> 
>     public String[] getValues() {
>         return values;
>     }
> 
>     public void setValues(String[] values) {
>         this.values = values;
>     }
> 
> Late, in my jsp, i have a global javascript var, an array:
>     var myValues = new Array();
> 
> that i populate correctly, whit the same dimension, and then when i do 
> the submit, i want to do this:
>     document.myformbean.values = myArray
> 
> But that doesnt work. I try this so:
>     document.myformbean.values.value = myArray
> and lots of combinations, but nothing. I got a null pointer.
> 
> Is this possible ?
> How could i do this correctly ?
> 
> Thank you very much !


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