You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pivot.apache.org by Michael Bushe <mi...@bushe.com> on 2010/01/03 07:17:41 UTC

Bindable not working?

I'm using the new Bindable interface and it doesn't seem to call my
initialize method, maybe I've got something not write.  The class is a
refactoring of the StockTracker tutorial, so it should look familiar:

public class SymbolPane extends BoxPane implements Bindable {
    @WTKX private TextInput symbolTextInput;
    @WTKX private Button addSymbolButton;
    @WTKX private Button removeSymbolsButton;
    ArrayList<SymbolListChangeEventListener> listenerList = new
ArrayList<SymbolListChangeEventListener>();
    private String lastSymbol;

    public SymbolPane() {
        System.out.println("SymbolPane constructed");
    }

    @Override
    public void initialize() {
        System.out.println("SymbolPane initializing, a.k.a. bound");
...
    }

"SymbolPane constructed" is output when I run, but "SymbolPane initializing,
a.k.a. bound" is not.  The WTKX is similar to the StockTracker, but with
this change to call my class:
                <TablePane.Row height="-1">
                    <stocktracker:SymbolPane
                        styles="{horizontalAlignment:'left',
verticalAlignment:'center'}">
                        <Label text="%symbol" styles="{font:{bold:true}}" />
                        <TextInput wtkx:id="symbolTextInput" textSize="10"
                            maximumLength="8" />
  ...
                  </stocktracker:SymbolPane>
                </TablePane.Row>

Michael Bushe
Software Architect/Developer
michael@bushe.com
www.bushe.com

Re: Bindable not working?

Posted by Greg Brown <gk...@mac.com>.
> Curious - if I didn't use an include, and had @WTK fields in my subclass, would they get wired up (I think I had that working before)?  

Not automatically - you need to call WTKXSerializer#bind() (or implement Bindable) to process the annotations.

> If so, how could I add listeners to to the @WTK fields, since I assume they would be null until the constructor finished?

They are null until WTKXSerializer#bind() is called. Once that happens, they are safe to access.


Re: Bindable not working?

Posted by Michael Bushe <mi...@bushe.com>.
OK, I think I was confusing binding and wire-up.  I have it working now by
implementing Bindable and using an include.  Thanks.

Curious - if I didn't use an include, and had @WTK fields in my subclass,
would they get wired up (I think I had that working before)?   If so, how
could I add listeners to to the @WTK fields, since I assume they would be
null until the constructor finished?

Michael Bushe
Software Architect/Developer
michael@bushe.com
www.bushe.com


On Sun, Jan 3, 2010 at 11:33 AM, Greg Brown <gk...@mac.com> wrote:

> > Yup, making it a root element works.  I think it's strange that the
> semantics of an XML element changes at the root element.  Why not always
> call initialize for Bindable elements?
>
> The namespace is defined at the WTKX document level, not the element level,
> so it would be odd to bind to anything other than the root element.
>
> > Otherwise, what's the best way to initialize a component that's not the
> root element?
>
> Generally, you'd do this in the initialize() method for the root element.
> However, another option would be to create subclasses for your inner
> elements:
>
> <foo:MyWindow>
>    <content>
>        <foo:MyPushButton/>
>    </content>
> </foo: MyWindow>
>
> The MyPushButton instance won't be bound to (for the reason I mention
> above), but you can still perform initialization (e.g. event wire-up) in the
> constructor.
>
>
>

Re: Bindable not working?

Posted by Greg Brown <gk...@mac.com>.
> Yup, making it a root element works.  I think it's strange that the semantics of an XML element changes at the root element.  Why not always call initialize for Bindable elements? 

The namespace is defined at the WTKX document level, not the element level, so it would be odd to bind to anything other than the root element.

> Otherwise, what's the best way to initialize a component that's not the root element?

Generally, you'd do this in the initialize() method for the root element. However, another option would be to create subclasses for your inner elements:

<foo:MyWindow>
    <content>
        <foo:MyPushButton/>
    </content>
</foo: MyWindow>

The MyPushButton instance won't be bound to (for the reason I mention above), but you can still perform initialization (e.g. event wire-up) in the constructor.



Re: Bindable not working?

Posted by Michael Bushe <mi...@bushe.com>.
Yup, making it a root element works.  I think it's strange that the
semantics of an XML element changes at the root element.  Why not always
call initialize for Bindable elements?  Even though it's the component that
calls Bind, the subcomponent is still bound and it's @WTK fields are bound.

Otherwise, what's the best way to initialize a component that's not the root
element?   I tried setParent(), but that's called during serialization
before the fields of the subcomponent are bound, which is not the right step
in the lifecycle for adding listeners.

Michael Bushe
Software Architect/Developer
michael@bushe.com
www.bushe.com


On Sun, Jan 3, 2010 at 8:52 AM, Greg Brown <gk...@mac.com> wrote:

> Bindable applies only to root elements. Try putting SymbolPane in an
> include - that should work.
> G
>
>
> On Jan 3, 2010, at 1:17 AM, Michael Bushe wrote:
>
> I'm using the new Bindable interface and it doesn't seem to call my
> initialize method, maybe I've got something not write.  The class is a
> refactoring of the StockTracker tutorial, so it should look familiar:
>
> public class SymbolPane extends BoxPane implements Bindable {
>     @WTKX private TextInput symbolTextInput;
>     @WTKX private Button addSymbolButton;
>     @WTKX private Button removeSymbolsButton;
>     ArrayList<SymbolListChangeEventListener> listenerList = new
> ArrayList<SymbolListChangeEventListener>();
>     private String lastSymbol;
>
>     public SymbolPane() {
>         System.out.println("SymbolPane constructed");
>     }
>
>     @Override
>     public void initialize() {
>         System.out.println("SymbolPane initializing, a.k.a. bound");
> ...
>     }
>
> "SymbolPane constructed" is output when I run, but "SymbolPane
> initializing, a.k.a. bound" is not.  The WTKX is similar to the
> StockTracker, but with this change to call my class:
>                 <TablePane.Row height="-1">
>                     <stocktracker:SymbolPane
>                         styles="{horizontalAlignment:'left',
> verticalAlignment:'center'}">
>                         <Label text="%symbol" styles="{font:{bold:true}}"
> />
>                         <TextInput wtkx:id="symbolTextInput" textSize="10"
>                             maximumLength="8" />
>   ...
>                   </stocktracker:SymbolPane>
>                 </TablePane.Row>
>
> Michael Bushe
> Software Architect/Developer
> michael@bushe.com
> www.bushe.com
>
>
>

Re: Bindable not working?

Posted by Greg Brown <gk...@mac.com>.
Bindable applies only to root elements. Try putting SymbolPane in an include - that should work.
G

On Jan 3, 2010, at 1:17 AM, Michael Bushe wrote:

> I'm using the new Bindable interface and it doesn't seem to call my initialize method, maybe I've got something not write.  The class is a refactoring of the StockTracker tutorial, so it should look familiar:
> 
> public class SymbolPane extends BoxPane implements Bindable {
>     @WTKX private TextInput symbolTextInput;
>     @WTKX private Button addSymbolButton;
>     @WTKX private Button removeSymbolsButton;
>     ArrayList<SymbolListChangeEventListener> listenerList = new ArrayList<SymbolListChangeEventListener>();
>     private String lastSymbol;
> 
>     public SymbolPane() {
>         System.out.println("SymbolPane constructed");
>     }
> 
>     @Override
>     public void initialize() {
>         System.out.println("SymbolPane initializing, a.k.a. bound");
> ...
>     }
> 
> "SymbolPane constructed" is output when I run, but "SymbolPane initializing, a.k.a. bound" is not.  The WTKX is similar to the StockTracker, but with this change to call my class:
>                 <TablePane.Row height="-1">
>                     <stocktracker:SymbolPane
>                         styles="{horizontalAlignment:'left', verticalAlignment:'center'}">
>                         <Label text="%symbol" styles="{font:{bold:true}}" />
>                         <TextInput wtkx:id="symbolTextInput" textSize="10"
>                             maximumLength="8" />
>   ...
>                   </stocktracker:SymbolPane>
>                 </TablePane.Row>
>   
> Michael Bushe
> Software Architect/Developer
> michael@bushe.com
> www.bushe.com