Hi,

On Thu, Jan 29, 2009 at 10:06 AM, mleneveut <mlenev...@abusinessware.com> wrote:
>
> Hi all,
>
> I have a very strange thing. I have a multiple select in my JSP, and a
> List<Long> of ids in my Action. When I submit the form, I iterate on that
> List of Long, and I have this error :
>
> java.lang.ClassCastException: java.lang.String
>
> Struts has String in the List instead of Long. The strange thing is that it
> appends on some servers (TomCat 5.5) but not on other : it works on my local
> computer, bug on the test server, works on the production server, and works
> on all other servers.
>
> I first thought it was a Struts dtd cache version problem on the Eclipse of
> the person building the WAR, but I have the same problem on my Eclipse
> (which build working WAR for other servers).
>
> We copied all jars files from shared/lib of a working TomCat to the bugging
> TomCat, but it doesn't fix the problem.
>
> Did someone already see such a thing ? Do you have an idea of where it could
> bug ?
>
> Thanks a lot.
>
> Here is my code :
>
> JSP : (id is a long, nomComplet is a String)
>                        <s:select       id="selectCommercial"
>                                                name="idsCommerciaux"
>                                                list="listCommercial"
>                                                listKey="id"
>                                                listValue="nomComplet"
>                                                cssStyle="width: 200"
>                                                emptyOption="true"
>                                                multiple="true"
>                                                size="10">
>                        </s:select>
>
> Action :
>        private List<Long> idsCommerciaux;
>        public List<Long> getIdsCommerciaux() {
>                return idsCommerciaux;
>        }
>        public void setIdsCommerciaux(List<Long> idsCommerciaux) {
>                this.idsCommerciaux = idsCommerciaux;
>        }
>
>        for (Long unCommercial : idsCommerciaux) { //ClassCastException here

This seems like a type erasure problem. Reflection is used to set the
entries into the list. As the generic type of the idsCommerciaux list
is not available at runtime  the no convertion to Long takes place for
the List elements. So a List containing Strings is injected. Check out
the Collection and Map Support portion from the type conversion
documentation[1]. You might want use an ObjectTypeDeterminer I think.

> Struts2 version : 2.1.0

You should think about upgrading to 2.1.6, as it became GA recently.

Cheers,
-Ralf

[1] http://struts.apache.org/2.0.14/docs/type-conversion.html

>
>
> --
> View this message in context: 
> http://www.nabble.com/Random-ClassCastException-%3A-I%27m-expecting-Long%2C-Struts-gives-me-String-on-some-servers...-tp21722894p21722894.html
> Sent from the Struts - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
> For additional commands, e-mail: user-h...@struts.apache.org
>
>

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

Reply via email to