You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Ezequiel Puig <e....@opodo.fr> on 2008/03/26 10:01:08 UTC
RE : How to eliminate an entry from an array with s2 tags
Hi Dave,
Thanks for your reponse. Anyway, I will try to convince you ;)
Some background: i have a page where a list of products are shown. In that page there is a button to compare products. What the button does is collect all the selected product's id and call an action: CompareProducts.do?productID=111&productID=222 etc. As the product selection is done by the user, the complete url is created with javascript :(. Consequently, the action CompareProducts has an array like that: String[] productID. So, when the action returns the page, i can access the array productID.
What i want to do is to put an button in the comparation page that allows the user to deselect a product. So, i need to call the action CompareProducts with all the ids (productID) removing the product's id that has been deselected.
And i want to do that with s2 tags and not with javascript.
Well, i hope it's a little bit more clear.
Thanks,
Ezequiel.
-----Message d'origine-----
De : Dave Newton [mailto:newton.dave@yahoo.com]
Envoyé : mardi 25 mars 2008 13:08
À : Struts Users Mailing List
Objet : Re: How to eliminate an entry from an array with s2 tags
--- Ezequiel Puig <e....@opodo.fr> wrote:
> in my jsp, i have an array of ids and i will like to remove one of
> that ids using s2 tags:
>
> I have tried the following, but it doesn't work :(
> <s:set name="allIDs" value="#parameters.productCode"/>
> <s:set name="newID" value=""/>
> <s:iterator value="#allIDs" status="stat">
> <s:set name="myID" value="top"/>
> <s:if test='%{ idToRemove != #myID }'>
> <s:set name="newID[#stat]" value="#myID"/>
> </s:if>
> </s:iterator>
>
> Does anyone know how to do it ?
Depending on the underlying collection type you might get an exception. You're not removing anything in the above code anyway, you're replacing a value. You're also using the "status" value like it's an index, but it's not [1].
But why? You'd have to work hard to convince me that the JSP is the place to do something like that.
Dave
[1] http://struts.apache.org/2.0.11.1/struts2-core/apidocs/org/apache/struts2/views/jsp/IteratorStatus.html
---------------------------------------------------------------------
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: RE : How to eliminate an entry from an array with s2 tags
Posted by Dave Newton <ne...@yahoo.com>.
Why wouldn't you just use the collection of checkboxes that have been
checked?
Maybe I'm not understanding correctly, but I don't see any reason to remove
anything from an array; whether you're using JavaScript to build the URL or
not. Why do you need to remove the ID from the array?
Dave
--- Ezequiel Puig <e....@opodo.fr> wrote:
> Hi Dave,
>
> Thanks for your reponse. Anyway, I will try to convince you ;)
>
> Some background: i have a page where a list of products are shown. In that
> page there is a button to compare products. What the button does is collect
> all the selected product's id and call an action:
> CompareProducts.do?productID=111&productID=222 etc. As the product
> selection is done by the user, the complete url is created with javascript
> :(. Consequently, the action CompareProducts has an array like that:
> String[] productID. So, when the action returns the page, i can access the
> array productID.
> What i want to do is to put an button in the comparation page that allows
> the user to deselect a product. So, i need to call the action
> CompareProducts with all the ids (productID) removing the product's id that
> has been deselected.
> And i want to do that with s2 tags and not with javascript.
>
> Well, i hope it's a little bit more clear.
>
> Thanks,
>
> Ezequiel.
>
>
> -----Message d'origine-----
> De : Dave Newton [mailto:newton.dave@yahoo.com]
> Envoyé : mardi 25 mars 2008 13:08
> À : Struts Users Mailing List
> Objet : Re: How to eliminate an entry from an array with s2 tags
>
>
> --- Ezequiel Puig <e....@opodo.fr> wrote:
> > in my jsp, i have an array of ids and i will like to remove one of
> > that ids using s2 tags:
> >
> > I have tried the following, but it doesn't work :(
> > <s:set name="allIDs" value="#parameters.productCode"/>
> > <s:set name="newID" value=""/>
> > <s:iterator value="#allIDs" status="stat">
> > <s:set name="myID" value="top"/>
> > <s:if test='%{ idToRemove != #myID }'>
> > <s:set name="newID[#stat]" value="#myID"/>
> > </s:if>
> > </s:iterator>
> >
> > Does anyone know how to do it ?
>
> Depending on the underlying collection type you might get an exception.
> You're not removing anything in the above code anyway, you're replacing a
> value. You're also using the "status" value like it's an index, but it's
> not [1].
>
> But why? You'd have to work hard to convince me that the JSP is the place
> to do something like that.
>
> Dave
>
> [1]
>
http://struts.apache.org/2.0.11.1/struts2-core/apidocs/org/apache/struts2/views/jsp/IteratorStatus.html
>
>
> ---------------------------------------------------------------------
> 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
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org