You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Quenten Van Egeren <qv...@yahoo.com> on 2003/04/15 08:38:54 UTC
How to get Array size from an indexed property in a DynaActionForm
I have the following in my struts-config :
<form-bean
name="enterScoresForm"
type="com.mytry.presentationlogic.EnterScoresForm">
<form-property name="rawResult" size="100"
type="com.mytry.persistence.RawResult[]"/>
<form-property name="eventId"
type="java.lang.String"/>
</form-bean>
This indexed property will give me a
getRawResult(index) and a setRawResult(index,value)
method.
My question is, how can I get the whole Array back at
one time? And is there a way to dynamically set the
size of this Array? Also, is there an easy entry in
this form-bean that will tell me the actual length of
the array?
Any help would be greatly appreciated. I figure
there's a way to do this, but I don't see how.
Quenten
__________________________________________________
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo
http://search.yahoo.com
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: How to accept a form whose fields are determined at run time?
Posted by David Chelimsky <da...@chelimsky.org>.
Of course! Thanks.
Mike Jasnowski wrote:
>Not sure, maybe the indexed properties feature of struts would allow you to
>do this?
>
>-----Original Message-----
>From: David Chelimsky [mailto:david@chelimsky.org]
>Sent: Thursday, April 17, 2003 9:45 AM
>To: Struts Users Mailing List
>Subject: How to accept a form whose fields are determined at run time?
>
>
>I'm developing an app that allows clients to create questions w/
>arbitrary numbers of choices for display in forms that will appear on
>their websites for their users to fill out. I need to be able to manage
>groups of fields related to one choice, but I don't know how many such
>groups will be present before run time. My understanding of the HTTP
>spec is that I can't rely on this approach:
>
><input type="hidden" name="choiceId" value="123">
><input type="text" name="choiceText">
><input type="hidden" name="choiceId" value="456">
><input type="text" name="choiceText">
><input type="numChoices" value="2">
>..........
>//in ActionForm
>public void setChoiceId(String[] choiceId) { this.choiceId = choiceId; }
>public void setChoiceId(String[] choiceText) { this.choiceText =
>choiceText; }
>..........
>//in Action
>for (int i = 0; i < numChoices; i++) {
> Choice c = new Choice();
> c.setId(form.getChoiceId()[i]);
> c.setText(form.getChoiceText()[i]);
> c.setRank(i + 1);
> choices.add(c);
>}
>..........
>Because there's no guarantee that the arrays are correctly ordered. I
>implemented something like this before using JSPs and a CustomTag (not
>Struts) using this approach:
>
><input type="hidden" name="choiceId0" value="123">
><input type="text" name="choiceText0">
><input type="hidden" name="choiceId1" value="456">
><input type="text" name="choiceText1">
><input type="numChoices" value="2">
>..........
>for (int i = 0; i < numChoices; i++) {
> Choice c = new Choice();
> c.setId(request.getParameter("choiceId" + i));
> c.setText(request.getParameter("choiceText" + i));
> c.setRank(i + 1);
> choices.add(c);
>}
>..........
>And that worked well, but I don't see how this would work in Struts
>since I'm never going directly after request.getParameter(). Anybody
>have any advice as to how to manage these in the ActionForm?
>
>Thanks,
>David
>
>ps - I'm concerned with how to handle submission, not how to render the
>form on the JSP.
>pps - One solution that occurred to me is to modify the state of the
>form via javascript so the form submitted looks like this:
> choiceId=123,456
> choiceText=firstChoice,secondChoice
>and then parse the lists in my Action class. I'd prefer to avoid this
>approach and keep the logic in the java layer where I can test it (and
>guarantee that even javascriptless browsers can use this).
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>
>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
RE: How to accept a form whose fields are determined at run time?
Posted by Mike Jasnowski <mj...@bea.com>.
Not sure, maybe the indexed properties feature of struts would allow you to
do this?
-----Original Message-----
From: David Chelimsky [mailto:david@chelimsky.org]
Sent: Thursday, April 17, 2003 9:45 AM
To: Struts Users Mailing List
Subject: How to accept a form whose fields are determined at run time?
I'm developing an app that allows clients to create questions w/
arbitrary numbers of choices for display in forms that will appear on
their websites for their users to fill out. I need to be able to manage
groups of fields related to one choice, but I don't know how many such
groups will be present before run time. My understanding of the HTTP
spec is that I can't rely on this approach:
<input type="hidden" name="choiceId" value="123">
<input type="text" name="choiceText">
<input type="hidden" name="choiceId" value="456">
<input type="text" name="choiceText">
<input type="numChoices" value="2">
..........
//in ActionForm
public void setChoiceId(String[] choiceId) { this.choiceId = choiceId; }
public void setChoiceId(String[] choiceText) { this.choiceText =
choiceText; }
..........
//in Action
for (int i = 0; i < numChoices; i++) {
Choice c = new Choice();
c.setId(form.getChoiceId()[i]);
c.setText(form.getChoiceText()[i]);
c.setRank(i + 1);
choices.add(c);
}
..........
Because there's no guarantee that the arrays are correctly ordered. I
implemented something like this before using JSPs and a CustomTag (not
Struts) using this approach:
<input type="hidden" name="choiceId0" value="123">
<input type="text" name="choiceText0">
<input type="hidden" name="choiceId1" value="456">
<input type="text" name="choiceText1">
<input type="numChoices" value="2">
..........
for (int i = 0; i < numChoices; i++) {
Choice c = new Choice();
c.setId(request.getParameter("choiceId" + i));
c.setText(request.getParameter("choiceText" + i));
c.setRank(i + 1);
choices.add(c);
}
..........
And that worked well, but I don't see how this would work in Struts
since I'm never going directly after request.getParameter(). Anybody
have any advice as to how to manage these in the ActionForm?
Thanks,
David
ps - I'm concerned with how to handle submission, not how to render the
form on the JSP.
pps - One solution that occurred to me is to modify the state of the
form via javascript so the form submitted looks like this:
choiceId=123,456
choiceText=firstChoice,secondChoice
and then parse the lists in my Action class. I'd prefer to avoid this
approach and keep the logic in the java layer where I can test it (and
guarantee that even javascriptless browsers can use this).
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
How to accept a form whose fields are determined at run time?
Posted by David Chelimsky <da...@chelimsky.org>.
I'm developing an app that allows clients to create questions w/
arbitrary numbers of choices for display in forms that will appear on
their websites for their users to fill out. I need to be able to manage
groups of fields related to one choice, but I don't know how many such
groups will be present before run time. My understanding of the HTTP
spec is that I can't rely on this approach:
<input type="hidden" name="choiceId" value="123">
<input type="text" name="choiceText">
<input type="hidden" name="choiceId" value="456">
<input type="text" name="choiceText">
<input type="numChoices" value="2">
..........
//in ActionForm
public void setChoiceId(String[] choiceId) { this.choiceId = choiceId; }
public void setChoiceId(String[] choiceText) { this.choiceText =
choiceText; }
..........
//in Action
for (int i = 0; i < numChoices; i++) {
Choice c = new Choice();
c.setId(form.getChoiceId()[i]);
c.setText(form.getChoiceText()[i]);
c.setRank(i + 1);
choices.add(c);
}
..........
Because there's no guarantee that the arrays are correctly ordered. I
implemented something like this before using JSPs and a CustomTag (not
Struts) using this approach:
<input type="hidden" name="choiceId0" value="123">
<input type="text" name="choiceText0">
<input type="hidden" name="choiceId1" value="456">
<input type="text" name="choiceText1">
<input type="numChoices" value="2">
..........
for (int i = 0; i < numChoices; i++) {
Choice c = new Choice();
c.setId(request.getParameter("choiceId" + i));
c.setText(request.getParameter("choiceText" + i));
c.setRank(i + 1);
choices.add(c);
}
..........
And that worked well, but I don't see how this would work in Struts
since I'm never going directly after request.getParameter(). Anybody
have any advice as to how to manage these in the ActionForm?
Thanks,
David
ps - I'm concerned with how to handle submission, not how to render the
form on the JSP.
pps - One solution that occurred to me is to modify the state of the
form via javascript so the form submitted looks like this:
choiceId=123,456
choiceText=firstChoice,secondChoice
and then parse the lists in my Action class. I'd prefer to avoid this
approach and keep the logic in the java layer where I can test it (and
guarantee that even javascriptless browsers can use this).
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org