Order of instantiation in UI-Binder?

66 views
Skip to first unread message

membersound

unread,
May 7, 2013, 7:12:09 AM5/7/13
to google-we...@googlegroups.com
Hi,

I have a SplitLayoutPanel with g:center and g:north.

The north element depends on the center element, and uses it in the contructor after initWidget() has been called.
Problem: I always get a NullPointerException for the center element used in the north element.

How can I force object creation to be first the center, and then the north element? I assume the default is just the other way around?

Thanks

Thad

unread,
May 7, 2013, 7:06:12 PM5/7/13
to google-we...@googlegroups.com
You may have to wait for the entire panel to render before making a call on any panel.

One technique might be to not have a north. Call your current north center and put your current center in south. IIRC, you can have multiple souths, easts, etc. That might allow everything to layout without intervention.

Kody

unread,
May 8, 2013, 4:42:39 AM5/8/13
to google-we...@googlegroups.com
OK that would be possible in general, though I require my stuff in the g:center as it should just take all space that is left in the window. South would require a fixed size...


2013/5/8 Thad <thad.hu...@gmail.com>

--
You received this message because you are subscribed to a topic in the Google Groups "Google Web Toolkit" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-web-toolkit/7fNeQwaaAZ4/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to google-web-tool...@googlegroups.com.
To post to this group, send email to google-we...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Jens

unread,
May 8, 2013, 5:38:16 AM5/8/13
to google-we...@googlegroups.com
SplitLayoutPanel is a DockLayoutPanel and a DockLayoutPanel requirement is that the center layer is added last. Once the center layer is added you can not add anything else. Thats because the center panel takes the remaining space and thus the panel needs to know what is already inside that panel to calculate the remaining space.

So using stock GWT classes there is no way to change that behavior. You would need to implement it yourself. Your best bet is probably writing a custom composite that is backed by a SplitLayoutPanel and provides @UiChild methods for north/east/south/center. These methods just store the widgets you add, and in Composite.onLoad() you would build the SplitLayoutPanel based on the added panels. That way the @UiChild methods can be called in any order and in onLoad() you can still build the SplitLayoutPanel with the center panel added last to satisfy DockLayoutPanel requirements.



As an alternative try to refactor your code so that you dont need to access the center panel inside the constructor of the north panel. You could add a ui:field to the north and center panel and in your UiBinder's Java file "connect" both panels after binder.createAndBindUi(this) is called. With your current constructor approach you are trying to "connect" both panels during the execution of binder.createAndBindUi(this).


-- J.




Patrick Tucker

unread,
May 8, 2013, 11:07:28 AM5/8/13
to google-we...@googlegroups.com
Have you tried providing, in the java code, the widget that is being added to the center?  That is assuming the widget that you are adding is what you are calling to get the NPE.
 
Some code would probably go a long way in getting better guidance...

On Tuesday, May 7, 2013 7:12:09 AM UTC-4, membersound wrote:

Kody

unread,
May 8, 2013, 4:25:03 PM5/8/13
to google-we...@googlegroups.com
OK I see that's not as easy as I thought.
Probably I should refactor my code instead of trying a hacky solution. Thansk!


2013/5/8 Patrick Tucker <tuck...@gmail.com>

--

Patrick Tucker

unread,
May 9, 2013, 11:03:17 AM5/9/13
to google-we...@googlegroups.com
I wouldn't consider providing the object via annotation a hack...
 
@UiField(provided=true)
Reply all
Reply to author
Forward
0 new messages