On Tue, 14 Sep 2004 17:31:17 -0400, Ross, Douglas <[EMAIL PROTECTED]> wrote:
> Nic,
> 
> I don't know how Struts or JSTL deals with arrays of request parameters
> but the following might be helpful:
> 
> <form>
> <br><input name="colors" value="Red">
> <br><input name="colors" value="Blue">
> <br><input name="colors" value="Orange">
> <br><input name="textures" value="Smooth">
> <br><input name="textures" value="Rough">
> <br><input type=submit>
> </form>
> 
> On the server, you can access the arrays as follows:
> 
> <%
>        String[] colors = request.getParameterValues("colors");
>        String[] textures = request.getParameterValues("textures");
>        if(null != colors){
>        for(int i=0; i<colors.length; i++){
>                %><br>color[<%=String.valueOf(i)%>] is <%=colors[i]%><%
>        }}
>        if(null != textures){
>        for(int i=0; i<textures.length; i++){
>                %><br>texture[<%=String.valueOf(i)%>] is
> <%=textures[i]%><%
>        }}
> %>
> 
> I would like to know how to access these in Struts, the ActionForm, if
> anyone knows if this is possible.

Yes, it's possible. Just make your action form properties string
arrays instead of strings, and it will "just work". ;-)

--
Martin Cooper


> 
> Thanks,
> 
> Doug
> 
> 
> 
> -----Original Message-----
> From: Nic Werner [mailto:[EMAIL PROTECTED]
> Sent: Tuesday, September 14, 2004 5:08 PM
> To: Tag Libraries Users List
> Subject: Re: Looping with paramValues
> 
> I had to depend on the order in my instance. I had 15 params that were
> repeated three times (each for a different variant), so I wanted to loop
> 
> through each param, and also know if I was on the first,second or third
> set of data. So basically, I wanted
> param.currentparam[current_set].value.
> 
> I couldn't merely name each param with a signifier in front, ie
> X-param,Y-param,Z-param because (as asked previously), there is no way
> to dynamically
> create a variable name and then access its data
> 
> - Nic.
> 
> Helios Alonso wrote:
> 
> > In this case, ignoring the order the order is not defensive
> > programming (avoiding not expectable bad cases) but avoiding coupling
> > with the implementation of the server (Tomcat) and avoiding extra
> > requiriments for the calling entity (call me with this params *and in
> > this order*).
> >
> > [9] works if the implementation of params implements List (or is an
> > array).
> >
> > At 16:20 14/09/2004 -0400, you wrote:
> >
> >> Defensive programming might suggest that one presume the worst not
> the
> >> spec.
> >>
> >> At any rate, presuming you intend and design the nth element is
> *always*
> >> the one you use from the request, does the following work?
> >>
> >> <c:out value="${params[9].value}" />
> >>
> >> I don't use el enough to remember all the nuances.
> >>
> >> Doug
> >>
> >>
> >> -----Original Message-----
> >> From: Martin Cooper [mailto:[EMAIL PROTECTED]
> >> Sent: Tuesday, September 14, 2004 4:02 PM
> >> To: Kris Schneider
> >> Cc: Tag Libraries Users List
> >> Subject: Re: Looping with paramValues
> >>
> >> On Tue, 14 Sep 2004 15:18:24 -0400, Kris Schneider <[EMAIL PROTECTED]>
> >> wrote:
> >> > I was thinking more along the lines of the HTTP spec not
> guaranteeing
> >> the order.
> >> > So that if you made the same request with parameters "foo" and
> "bar",
> >> in some
> >> > cases "foo" might be first and in other cases it might be "bar".
> >>
> >> Clearly the HTTP spec can't say anything about the order; that
> >> wouldn't be meaningful. However, the HTML spec does state that the
> >> order of parameters is preserved. Taken together with the Servlet
> spec
> >> requirements, that does state that the order of parameters as
> received
> >> by the servlet is the same as the order of fields in the submitted
> >> form.
> >>
> >> --
> >> Martin Cooper
> >>
> >>
> >> >
> >> > Quoting Martin Cooper <[EMAIL PROTECTED]>:
> >> >
> >> > > On Tue, 14 Sep 2004 13:31:22 -0400, Kris Schneider
> <[EMAIL PROTECTED]>
> >> wrote:
> >> > > > Well, even if you could do it cleanly, there's no guarantee on
> the
> >> ordering
> >> > > of
> >> > > > request parameters.
> >> > >
> >> > > Although the Servlet spec doesn't state it explicitly, it does
> >> > > actually specify that the order of values for a given parameter,
> as
> >> > > returned by getParameterValues(), is the same as the order in
> which
> >> > > they are submitted.
> >> > >
> >> > > --
> >> > > Martin Cooper
> >> > >
> >> > >
> >> > > > Are you really just checking to see if a particular
> >> > > > parameter has been passed? If so, you should be able to do that
> >> with just:
> >> > > >
> >> > > > <c:if test="${param.nameOfTheParameter}">
> >> > > >  ...
> >> > > > </c:if>
> >> > > >
> >> > > > Quoting Nic Werner <[EMAIL PROTECTED]>:
> >> > > >
> >> > > > > Thanks everyone for the help. I ended up taking your
> examples,
> >> and just
> >> > > > > 'on the side' iterating through the paramValues until I found
> >> the
> >> > > > > matching one, and then setting a temp flag. Its unfortunate
> that
> >> I
> >> > > > > couldn't just use an index to access the nth param and its
> nth
> >> value.
> >> > > > >
> >> > > > > - Nic.
> >> > > > >
> >> > > > > Helios Alonso wrote:
> >> > > > >
> >> > > > > > Oops.  Exactly.
> >> > > > > >
> >> > > > > > At 11:56 13/09/2004 -0400, you wrote:
> >> > > > > >
> >> > > > > >> Helios,
> >> > > > > >>
> >> > > > > >> Small correction (I think), did you mean ...
> >> > > > > >> ><c:forEach var='entry' items='${params}'>
> >> > > > > >> >   <c:if test="${entry.key == 'test1'>
> >> > > > > >> >     <c:out value="${entry.value}"/>
> >> > > > > >> >   </c:if>
> >> > > > > >> ></c:forEach>
> >> > > > > >> Note: I switched var and items values.
> >> > > >
> >> > > > --
> >> > > > Kris Schneider <mailto:[EMAIL PROTECTED]>
> >> > > > D.O.Tech       <http://www.dotech.com/>
> >> >
> >> > --
> >> >
> >> >
> >> > Kris Schneider <mailto:[EMAIL PROTECTED]>
> >> > D.O.Tech       <http://www.dotech.com/>
> >> >
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: [EMAIL PROTECTED]
> >> For additional commands, e-mail: [EMAIL PROTECTED]
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: [EMAIL PROTECTED]
> >> For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to