You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Patil, Sheetal" <pa...@diebold.com> on 2006/07/13 08:40:08 UTC
show value in array into textbox
hi everybody,
i am doing an application for an survay. here i have a list of questions
and i am getting answer by the users for that questions.
to read the answers i create an int array in actionform as
int[] answers;
and in jsp i write like
<html:text property="answers"/>
<html:text property="answers"/>
in action i get the data as
answers[0] or answers[1] ect..
it works fine and i am able to get the answers filled by the user
but now the problem is with updating an survay
for updating in action i put values in actionform as
form.answers[0]=100;
form.answers[1]=200;
and setted actionform to it's scope
now i can show the values stored in jsp using
<logic:iterate name="actionform" property="answers" id="ans">
<bean:write name="ans"/>
</logic:iterate>
as
100
200
but the problem is that i want textboxes to get input for the questions
so i put as previously
<html:text property="answers"/>
<html:text property="answers"/>
this displays textboxes and returns inseted values finely
but in textbox it shows address kind of thing rather than showing 100 /
200 in textbox
so is there any way to show values stored in array into textbox
Sp
Re: show value in array into textbox
Posted by Laurie Harper <la...@holoweb.net>.
Patil, Sheetal wrote:
> hi everybody,
> i am doing an application for an survay. here i have a list of questions
> and i am getting answer by the users for that questions.
> to read the answers i create an int array in actionform as
> int[] answers;
> and in jsp i write like
> <html:text property="answers"/>
> <html:text property="answers"/>
> in action i get the data as
> answers[0] or answers[1] ect..
>
> it works fine and i am able to get the answers filled by the user
>
> but now the problem is with updating an survay
> for updating in action i put values in actionform as
> form.answers[0]=100;
> form.answers[1]=200;
> and setted actionform to it's scope
> now i can show the values stored in jsp using
> <logic:iterate name="actionform" property="answers" id="ans">
> <bean:write name="ans"/>
> </logic:iterate>
> as
> 100
> 200
>
> but the problem is that i want textboxes to get input for the questions
> so i put as previously
> <html:text property="answers"/>
> <html:text property="answers"/>
> this displays textboxes and returns inseted values finely
> but in textbox it shows address kind of thing rather than showing 100 /
> 200 in textbox
>
> so is there any way to show values stored in array into textbox
You need to use indexed properties; property="answers" binds the control
to the full array. Use property="answers[1]", property="answers[2]", ...
You can fill in the index with a JSTL or RT expression.
Alternatively, take a look at the 'nested' tag library, which can help
make this kind of thing easier to manage.
L.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org