Yes, that works. Knowing that BXMLSerializer needs no-arg constructors is helpful.
Thanks, Josh On Thu, Apr 14, 2016 at 2:18 PM, Roger Whitcomb <roger.whitc...@actian.com> wrote: > So, the technical reason you go the error is that BXMLSerializer must be > able to find a simple no-arg constructor for the class (in this case > EnumList) in order to construct it, before adding data elements using the > “add” method. There is no such constructor for EnumList (nor could there > be, since it is a generic class and would need at least the class as a > parameter in order to specialize it). > > > > So, one thing that comes to mind (and I haven’t tested it to see if works) > would be to make a simple class of your own, that pretty much just “wraps” > an EnumList<Paint.Color>. Not sure exactly how you would code it, but by > providing a no-arg constructor and implementing the “List<?>” interface it > should meet the requirements and be able to be used. So, presumably you > could do something like this: > > public class ColorList extends EnumList<Paint.Color> { > > public ColorList() { > > super(Paint.Color.class); > > } > > } > > Then in your BXML file, use: > > <ListButton selectedItemKey="exteriorColor"> > <listData> > <mypackage:ColorList/> > > </listData> > </ListButton> > > Again, I haven’t tried this, but I **think** it should work (or something > reasonably close to this). > > > > HTH, > > ~Roger > > > > *From:* Josh Highley [mailto:joshhigh...@gmail.com] > *Sent:* Thursday, April 14, 2016 10:38 AM > *To:* user@pivot.apache.org > *Subject:* Re: Populate ListButton with enum data binding ? > > > > Yes, populating in Java is a last resort. Where possible, I've been > trying to keep code like that out of the Java code. I'm converting a QT > Jambi app, and all of the UI definition code in Java makes it a mess trying > to find where functionality is actually implemented. > > > > At this point, my stacktrace isn't really valid since I don't know now to > pass the required Class param to EnumList. Another path I may explore is > using ArrayList and passing the Paint.Color.values() array -- I'm not sure > if there's a way to do this in bxml.... > > > > Thanks, > > > > Josh > > > > > > On Thu, Apr 14, 2016 at 12:20 PM, Roger and Beth Whitcomb < > rogerandb...@rbwhitcomb.com> wrote: > > That is a really good question, Josh. My first thought is that you will > probably have to populate the list in Java code. My second thought is to > poke through the BXMLSerializer code to see it I can figure it out. But, > what was the complete stack trace of the SerializationException (i.e., the > cause). That could point the way to a solution. But, at the moment I > don't know the answer. > > Thanks, > ~Roger > > > > On 4/13/16 11:26 AM, Josh Highley wrote: > > I'm having an issue doing data binding with bxml. My app has a Dialog > with a Form that shows a lot of editable fields for an object. Using > form.load(new BeanAdapter(myObject)) is working for most of the fields > (TextInput and Checkbox) but I'm having trouble with ListButton. I want to > populate the listData with values from an enum and then set the selected > item from a myObject value. I can't figure out how to specify the enum for > the list data in the bxml. I think I'm close: > > (simplified example to mirror actual app) > > public class Paint { > public enum Color { RED, BLUE, GREEN } > } > > public class Car { > private Paint.Color color; > > public Paint.Color getExteriorColor() { return color; } > public void setExteriorColor(Paint.Color color) { this.color = color; } > } > > <ListButton selectedItemKey="exteriorColor"> > <listData> > <collections:EnumList> > <!-- how do I specify constructor parameter Paint.Color class here? > --> > </collections:EnumList> > </listData> > </ListButton> > > > I tried 'enumClass' as an attribute of <EnumList> and a child element, but > I always get an "org.apache.pivot.serialization.SerializationException" on > the line with <collections:EnumList> > > > Thanks, > > Josh > > > > >