[prev in list] [next in list] [prev in thread] [next in thread] 

List:       struts-user
Subject:    Re: Extending StrutsTypeConverter :: How to detect specific type of "Class toClass"?
From:       Burton Rhodes <burtonrhodes () gmail ! com>
Date:       2017-09-29 15:56:01
Message-ID: CABueNrFoKLjiyz_PrNrgALxPEO2XTc+49vHTMUd7A8rhz1uD+w () mail ! gmail ! com
[Download RAW message or body]


Sorry for the delay.  I have upgraded to the newest version and everything
seems to be working.  Thanks!

On Mon, Sep 25, 2017 at 2:34 AM, Lukasz Lenart <lukaszlenart@apache.org>
wrote:

> 2017-09-25 5:04 GMT+02:00 Burton Rhodes <burtonrhodes@gmail.com>:
> > When extending the StrutsTypeConverter, is there anyway to figure out if
> > the "toClass" is a List<Integer> or a List<String>?  I have found that
> when
> > converting data from a submitted webpage that has a value of a List in a
> > single variable, the standard struts conversion fails.  For example:
> > <s:hidden name="integerList" value="%{integerList}" /> display as
> <s:hidden
> > name="integerList" value="[1,2,3,4,5]" />.  When the form submits, this
> > value will not convert properly back into the List.  In addition, the
> > conversion fails if you have a list of checkboxes and the user only
> checks
> > one -  hence only a single variable being converted to a List.
> >
> > I have solved this issue by creating a MyListConverter, but I have to
> > declare the converter on each action in a [-conversion.properties] file
> > which is now becoming a bit cumbersome since this is such a common
> > occurrence. I have also declared some on my model/entity beans, but
> > still.... I would love to have a more global "List" converter, such as:
> >
> > [xwork-conversion.properties]
> > java.util.List=com.afs.web.converter.MyListConverter
> >
> > Thus any List that is encountered, I could attempt "my conversion" and
> send
> > up the chain of command if the resulting List is not of List<Integer> or
> > List<String>.
> >
> > [Psuedo_Code]
> > public class MyListConverter extends StrutsTypeConverter {
> >     public Object convertFromString(Map context, String[] values, Class
> > toClass) {
> >         // Is toClass List<Integer>, then try "my" conversion
> >
> >         // Else is toClass List<String?, then try "my" conversion
> >
> >         // Else return performFallbackConversion(context, o, toClass);
> >     }
> > }
> >
> > Any ideas?  Or am I going about this incorrectly?
>
> What version of Struts do you use? I think this was resolved in 2.5.13
> or 2.5.12 - I meant conversion of list of built-in types (ints,
> doubles, etc), to convert your own type just register it (as for the
> List above).
>
>
> Regards
> --
> Ɓukasz
> + 48 606 323 122 http://www.lenart.org.pl/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic