Setting content for HeaderPanel

404 views
Skip to first unread message

CF

unread,
Jul 13, 2012, 1:19:25 PM7/13/12
to google-we...@googlegroups.com
If I am using HeaderPanel and UiBinder and I want to have a static header and footer, but dynamic content area, how do I swap the content widget (middle section) in and out?  So, say a user hits a search button and I want the content widget to show the search results rather than the button.

I know that I can use setContentWidget(..), but since my HeaderPanel is declared in the ui.xml file and not in code, how would I manipulate it?

<g:HeaderPanel styleName="{style.headerPanel}">

        <g:FlowPanel styleName="{style.header}">
            <g:Label>This is the header</g:Label>
</g:FlowPanel> <g:FlowPanel styleName="{style.middle}"> <g:Label>This is the middle section</g:Label> </g:FlowPanel> <g:FlowPanel styleName="{style.footer}"> <g:Label>This is the footer</g:Label> </g:FlowPanel> </g:HeaderPanel>

Jens

unread,
Jul 13, 2012, 2:58:14 PM7/13/12
to google-we...@googlegroups.com
In your java file you can call getWidget() to get the HeaderPanel, so you would probably define:

private HeaderPanel getHeaderPanel() {
  return (HeaderPanel) getWidget();
}

Alternatively you could assign a ui:field to your HeaderPanel and use @UiField in your java file to access it. Or you could change your UiBinder interface definition and constructor a bit so you have:

interface MyUiBinder extends UiBinder<HeaderPanel, MyHeaderPanelWidget> {}
private static MyUiBinder uiBinder = GWT.create(MyUiBinder.class);

public MyHeaderPanelWidget() {
  HeaderPanel headerPanel = uiBinder.createAndBindUi(this);
  initWidget(headerPanel);
}



-- J.

CF

unread,
Jul 13, 2012, 4:59:45 PM7/13/12
to google-we...@googlegroups.com
Thanks!

I tried using the @UiField to access the HeaderPanel and change the content, but when the searchButton is clicked, the content area becomes blank and doesn't show my label.  Any ideas why?
@UiField
HeaderPanel headerPanel;
@UiField
TextBox queryInput;
@UiField
Button searchButton;
@UiField
UListElement results;

public MyHeaderPanel() {
    headerPanel = ( HeaderPanel ) uiBinder.createAndBindUi( this );
    initWidget(headerPanel);
    queryInput.getElement().setId("queryInput");
}

@UiHandler("searchButton")
void buttonClick(ClickEvent event) {
    headerPanel.setContentWidget( new Label( "new results.... blah blah blah" ) );
}
Reply all
Reply to author
Forward
0 new messages