Return-Path: Delivered-To: apmail-struts-user-archive@www.apache.org Received: (qmail 52854 invoked from network); 20 Aug 2008 17:18:33 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 20 Aug 2008 17:18:33 -0000 Received: (qmail 43565 invoked by uid 500); 20 Aug 2008 17:18:22 -0000 Delivered-To: apmail-struts-user-archive@struts.apache.org Received: (qmail 43537 invoked by uid 500); 20 Aug 2008 17:18:22 -0000 Mailing-List: contact user-help@struts.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Struts Users Mailing List" Reply-To: "Struts Users Mailing List" Delivered-To: mailing list user@struts.apache.org Received: (qmail 43526 invoked by uid 99); 20 Aug 2008 17:18:22 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 20 Aug 2008 10:18:22 -0700 X-ASF-Spam-Status: No, hits=2.0 required=10.0 tests=HTML_MESSAGE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of valimaa.jukka@gmail.com designates 209.85.217.11 as permitted sender) Received: from [209.85.217.11] (HELO mail-gx0-f11.google.com) (209.85.217.11) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 20 Aug 2008 17:17:26 +0000 Received: by gxk4 with SMTP id 4so576176gxk.11 for ; Wed, 20 Aug 2008 10:16:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:in-reply-to:mime-version:content-type:references; bh=V4ABFTwW5bMQr24DZ/mZWz4ThYOEZ9Ete6aGi3hGOq4=; b=kmSLITjJE1HPyLB/JWJBCJDQ5IvFcsLM4z4Bgzn0oID3/y7JOjOa1M60Dtjy87rZD5 O04I/HqwH67zkaL9XSTwie0Tw6SHKxK2cRMryvLhSz5+HSDJX7PH0xSO3mZMmvqWOMDr xI2xsXOAV/SVlfHpJmCZj7vOHyvp5xvoq3+Ks= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:in-reply-to:mime-version :content-type:references; b=EJQRDiH6TXEf8uu7ZXOHri5jDu3wg1Tgr/HImx4GJhnkQARjTMrBTu+cDi/1m/Zius dXaB3xy9i90VIcDaCAqoaWAsJXHXQ7wSa1M1Ahqj6hxn9YSOYBFp1iD1iWbkKRrF8tix H4tTgFgGVD1Zr4XTQbdD3KQrElp0I5S16unVA= Received: by 10.142.207.8 with SMTP id e8mr104691wfg.195.1219252613821; Wed, 20 Aug 2008 10:16:53 -0700 (PDT) Received: by 10.142.80.21 with HTTP; Wed, 20 Aug 2008 10:16:53 -0700 (PDT) Message-ID: <1def873e0808201016y8338cc5k264623a8bc20b323@mail.gmail.com> Date: Wed, 20 Aug 2008 20:16:53 +0300 From: "=?ISO-8859-1?Q?Jukka_V=E4limaa?=" To: "Struts Users Mailing List" Subject: Re: S2 type conversion problem with generics In-Reply-To: <42db7f0a0808200906gdaf5d2an6bbf2bf5c426cdbb@mail.gmail.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_20904_890979.1219252613819" References: <1def873e0808200817x4eccc62ax2609cd386279aab5@mail.gmail.com> <42db7f0a0808200906gdaf5d2an6bbf2bf5c426cdbb@mail.gmail.com> X-Virus-Checked: Checked by ClamAV on apache.org ------=_Part_20904_890979.1219252613819 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Sounds reasonable, thanks for the answer. But why do the generics used in java collections work with type conversion, and generics in my custom class won't? On Wed, Aug 20, 2008 at 7:06 PM, Chris Pratt wrote= : > My bet is that, because Struts uses run-time introspection to determine h= ow > to pass the parameters, and the new Java Generics use type erasure to > ensure > backward portability, what Struts see's isn't your generic type, it's an > Object. So it passes in the unconverted value that it got from > Request.getParameters(), which is a String Array. > (*Chris*) > > On Wed, Aug 20, 2008 at 8:17 AM, Jukka V=E4limaa >wrote: > > > Hi all, > > > > I have the following problem which I think is caused by Struts 2 type > > conversion. > > > > I have a class I use to wrap a map for easier interface with view: > > > > public class ObjectWeekHandler { > > private Map weekDayObjects =3D new > HashMap > T>(); > > > > public Map getWeekDayObjects() { > > return weekDayObjects; > > } > > > > public void setWeekDayObjects(Map weekDayObjects) { > > this.weekDayObjects =3D weekDayObjects; > > } > > > > public T getEvenMonObject() { > > return weekDayObjects.get(WeekDayEntry.EVEN_MONDAY); > > } > > > > public void setEvenMonObject(T evenMonObject) { > > weekDayObjects.put(WeekDayEntry.EVEN_MONDAY, evenMonObject); > > } > > > > [...] > > > > I use this class in my action class to get strings for various weekdays= : > > private ObjectWeekHandler weekDayTruckIds =3D new > > ObjectWeekHandler(); > > > > public ObjectWeekHandler getWeekDayIds() { > > return weekDayIds; > > } > > > > When I send the request, the parameters are of this type: > > weekDayIds.evenMonObject=3D-1 > > > > If I understand the workings of Struts 2 type conversion correctly, it > > should call getWeekDayIds.setEvenMonObject(type converted parameter > value). > > This is indeed what happens, but instead of setting the parameter as > > String, > > it is set as String array. The same thing happens if I parameterize > > weekDayIds as weekDayIds. > > > > I have an ugly workaround in place- I cast the supposed String value I > get > > from getEvenMonObject into Object and then into String[], and get the > first > > value. It works, but I certainly don't like it. Does anyone have an ide= a > > what might be wrong and how to fix it? > > > ------=_Part_20904_890979.1219252613819--