Hi Greg,

I modified setSelectedItem to not throw an exception if the object was not 
found in the lists' data.

In my case I have a TableView bound to a database table via a custom 
Dictionary.  I don't pass field values around directly so Null is never passed 
to any function as an argument. The field values are encapsulated in a class. 
When a new record is added to the table the individual fields of the record are 
mostly null. When invoking a TableViewRowEditor (that contains ListButtons) on 
the new row, when the editor grabs data from the TableView so it can set the 
selected index on a ListButton it gets essentially an empty value that does 
not appear in the ListButtons list data. I don't want the user to be able to 
select an empty value so it is never added to the list data. So I modified 
setSelectedItem to not throw an exception if it could not find the object in 
the list.

On Tue, 15 Sep 2009 08:48:36 am Greg Brown wrote:
> Hi Scott,
>
> Just wondering what specifically you needed to modify in ListButton to
> accept a -1 value? -1 should already have been a valid value for
> setSelectedIndex() - were you finding otherwise?
>
> Would it be possible for you to build Pivot with debug info turned on?
> That way we can see specific line numbers when error like this occur.
>
> Thanks,
> Greg
>
> On Sep 14, 2009, at 6:14 PM, Scott Lanham wrote:
> > I have modified ListButton to simply accept -1 as a valid index and
> > everything
> > works great on that front. But there is another problem. If a new
> > row is added
> > to the TableView via the associated Dictionary and the
> > TablieViewRowEditor is
> > immediately invoked on that new row the error below occurs:
> >
> > Exception in thread "AWT-EventQueue-0"
> > java.lang.IndexOutOfBoundsException
> >        at org.apache.pivot.collections.ArrayList.get(Unknown Source)
> >        at org.apache.pivot.wtk.Container.validate(Unknown Source)
> >        at org.apache.pivot.wtk.Display$ValidateCallback.run(Unknown
> > Source)
> >        at java.awt.event.InvocationEvent.dispatch
> > (InvocationEvent.java:209)
> >        at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
> >        at
> > java.awt.EventDispatchThread.pumpOneEventForFilters
> > (EventDispatchThread.java:269)
> >        at
> > java.awt.EventDispatchThread.pumpEventsForFilter
> > (EventDispatchThread.java:184)
> >        at
> > java.awt.EventDispatchThread.pumpEventsForHierarchy
> > (EventDispatchThread.java:174)
> >        at
> > java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
> >        at
> > java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
> >        at java.awt.EventDispatchThread.run(EventDispatchThread.java:
> > 122)
> > Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
> >        at
> > org.apache.pivot.wtk.content.TableViewRowEditor
> > $2$1.selectedIndexChanged(Unknown
> > Source)
> >        at
> > org.apache.pivot.wtk.CardPane
> > $CardPaneListenerList.selectedIndexChanged(Unknown
> > Source)
> >        at org.apache.pivot.wtk.CardPane.setSelectedIndex(Unknown
> > Source)
> >        at
> > org.apache.pivot.wtk.skin.CardPaneSkin$1.transitionCompleted(Unknown
> > Source)
> >        at org.apache.pivot.wtk.effects.Transition$1.run(Unknown
> > Source)
> >        at
> > org.apache.pivot.wtk.ApplicationContext$ScheduledCallback$1.run
> > (Unknown
> > Source)
> >        at java.awt.event.InvocationEvent.dispatch
> > (InvocationEvent.java:209)
> >        at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
> >        at
> > java.awt.EventDispatchThread.pumpOneEventForFilters
> > (EventDispatchThread.java:269)
> >        at
> > java.awt.EventDispatchThread.pumpEventsForFilter
> > (EventDispatchThread.java:184)
> >        at
> > java.awt.EventDispatchThread.pumpEventsForHierarchy
> > (EventDispatchThread.java:174)
> >        at
> > java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
> >        at
> > java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
> >        at java.awt.EventDispatchThread.run(EventDispatchThread.java:
> > 122)
> >
> > On Mon, 14 Sep 2009 09:07:18 pm Todd Volkert wrote:
> >> The update I made to ListButton should be preventing that case -
> >> did you
> >> make sure to rebuild the Pivot jars?
> >>
> >>    public void setSelectedItem(Object item) {
> >>        int index = -1;
> >>
> >>        if (item != null) {
> >>            index = ((List<Object>)listData).indexOf(item);
> >>            if (index == -1) {
> >>                throw new IllegalArgumentException("\"" + item + "\"
> >> is not
> >> a valid selection.");
> >>            }
> >>        }
> >>
> >>        setSelectedIndex(index);
> >>    }
> >>
> >> If you're getting ["null" is not a valid selection.] with the above
> >> code,
> >> then it means that your bind context has the actual String, "null",
> >> as the
> >> value to load...
> >>
> >> -T
> >>
> >> On Mon, Sep 14, 2009 at 12:20 AM, Scott Lanham <li...@sael.com.au>
> >>
> >> wrote:
> >>> Digging a little deeper the ListButton is asking its list data, a
> >>> custom
> >>> Dictionary, which index the "null" item belongs to. As the list data
> >>> doesn't
> >>> have a null item, my Dictionary replies -1.
> >>>
> >>> On Mon, 14 Sep 2009 01:58:32 pm Scott Lanham wrote:
> >>>> Okay, made sure SVN is up to date and no blonde moment occuring
> >>>> ( much
> >>>> ).
> >>>>
> >>>> What I get now is:
> >>>>
> >>>> java.lang.IllegalArgumentException: "null" is not a valid
> >>>> selection.
> >>>>        at org.apache.pivot.wtk.ListButton.setSelectedItem(Unknown
> >>>
> >>> Source)
> >>>
> >>>>        at org.apache.pivot.wtk.ListButton.load(Unknown Source)
> >>>>        at org.apache.pivot.wtk.Container.load(Unknown Source)
> >>>>        at org.apache.pivot.wtk.content.TableViewRowEditor.edit
> >>>> (Unknown
> >>>> Source)
> >>>>
> >>>> On Mon, 14 Sep 2009 11:51:59 am Todd Volkert wrote:
> >>>>> One problem stems from the fact that ListButton.setSelectedItem
> >>>>> (null)
> >>>
> >>> was
> >>>
> >>>>> explicitly throwing IllegalArgumentException, when it probably
> >>>>> should
> >>>>> have been translating to setSelectedIndex(-1).  I just checked
> >>>>> in a
> >>>>> fix for this, so that might fix you up.
> >>>>>
> >>>>> So you're creating blank rows, and immediately opening an editor
> >>>>> on
> >>>>> the row for the user to populate it with initial values?
> >>>>>
> >>>>> Let me know if that check-in fixes the issue.
> >>>>>
> >>>>> -T
> >>>>>
> >>>>> On Sun, Sep 13, 2009 at 9:22 PM, Scott Lanham <li...@sael.com.au>
> >>>
> >>> wrote:
> >>>>>> Howdy Hi,
> >>>>>>
> >>>>>> I have a TableView which displays data from a database table.
> >>>>>> That
> >>>
> >>> data
> >>>
> >>>>>> is bound to the TableView using a custom Dictionary. It all works
> >>>
> >>> fine
> >>>
> >>>>>> until it is
> >>>>>> time to add a new record using the TableView and in place editing
> >>>>>> it using TableViewRowEditor. Several of the fields in a TableView
> >>>>>> row
> >>>
> >>> have
> >>>
> >>>>>> ListButtons
> >>>>>> assocated with them to restrict the field values. When the field
> >>>
> >>> value
> >>>
> >>>>>> is initially Null, as with a new record, the ListButtons don't
> >>>>>> like
> >>>
> >>> it
> >>>
> >>>>>> because Null can't be found in the lists data.
> >>>>>>
> >>>>>> Is there any way I can get ListButton to not throw an exception
> >>>>>> in
> >>>
> >>> this
> >>>
> >>>>>> case?
> >>>>>>
> >>>>>> Thanks,
> >>>>>>
> >>>>>> Scott.

Reply via email to