使用UiBinder在Bootstrap 3中的垂直导航栏

时间:2015-03-12 09:45:21

标签: gwt uibinder gwtbootstrap3

我的项目中有一个Navbar(GWT,GWTBootstrap3,UiBinder),我想在UiBinder中做垂直。

在HTML中很简单

<div class = "nav nav-pills nav-stacked col-sm-3"> 
    <li> <a> Home </a> </li> 
    <li> <a> Settings</a> </li> 
</div> 

但是必须可以在UiBinder中做同样的事情。据我所知,只能将Navbar的位置设置为FIXED_TOP,FIXED_BOTTON等。

我的代码看起来像这样

<g:HTMLPanel>
        <g:ScrollPanel>
            <b:Container >
                 <b:Navbar position="FIXED_TOP">
                    <b:Container>
                        <b:NavbarHeader>
                            <b:NavbarBrand targetHistoryToken="{nameTokens.getHome}" ui:field="brand" text="{resources.ProductName}" />
                            <b:NavbarCollapseButton dataTarget="#navbar-collapse" />
                        </b:NavbarHeader>

                        <b:NavbarCollapse b:id="navbar-collapse">
                            <b:NavbarNav>

                                <b:ListDropDown ui:field="admindropdown">
                                    <b:AnchorButton dataToggle="DROPDOWN" text="{resources.CardHolder}" />
                                    <b:DropDownMenu>
                                        <b:AnchorListItem text="{resources.Employee}" targetHistoryToken="{nameTokens.getCardholderlist}" />
                                        <b:AnchorListItem text="{resources.Guest}" targetHistoryToken="{nameTokens.getHome}" />
                                        <b:AnchorListItem text="{resources.Vendor}" targetHistoryToken="{nameTokens.getHome}" />
                                    </b:DropDownMenu>
                                </b:ListDropDown>

                                <b:ListDropDown>
                                    <b:AnchorButton dataToggle="DROPDOWN" text="{resources.User}" />
                                    <b:DropDownMenu>
                                        <b:AnchorListItem text="{resources.Customer}" targetHistoryToken="{nameTokens.getHome}" />
                                        <b:AnchorListItem text="{resources.Technician}" targetHistoryToken="{nameTokens.getHome}" />
                                        <b:AnchorListItem text="{resources.Portal}" targetHistoryToken="{nameTokens.getHome}" />
                                        <b:AnchorListItem text="{resources.Cloud}" targetHistoryToken="{nameTokens.getHome}" />
                                    </b:DropDownMenu>
                                </b:ListDropDown>

                                <b:ListDropDown>
                                    <b:AnchorButton dataToggle="DROPDOWN" text="{resources.Configuration}" />
                                    <b:DropDownMenu>
                                        <b:AnchorListItem text="{resources.Customer}" targetHistoryToken="{nameTokens.getCustomerlist}" />
                                        <b:AnchorListItem text="{resources.Company}" targetHistoryToken="{nameTokens.getCompanylist}" />
                                        <b:AnchorListItem text="{resources.Portal}" targetHistoryToken="{nameTokens.getHome}" />
                                        <b:AnchorListItem text="{resources.ProductNameServer}" targetHistoryToken="{nameTokens.getCloudlist}" />
                                    </b:DropDownMenu>
                                </b:ListDropDown>

                            </b:NavbarNav>

                            <b:NavbarNav pull="RIGHT">

                                <b:ListDropDown >
                                    <b:AnchorButton text="{resources.SelectedLanguage}" dataToggle="DROPDOWN"  />
                                        <b:DropDownMenu >
                                            <b:Image addStyleNames="btn {style.btnStyle}" ui:field="languageDK" url="/images/DK.png" />
                                            <b:Image addStyleNames="btn {style.btnStyle}" ui:field="languageNO" url="/images/NO.png" />
                                            <b:Image addStyleNames="btn {style.btnStyle}" ui:field="languageUK" url="/images/UK.png" />
                                        </b:DropDownMenu>
                                </b:ListDropDown>

                                <b:ListDropDown ui:field="loginfield">
                                    <b:AnchorButton dataToggle="DROPDOWN" ui:field="loginname" />
                                    <b:DropDownMenu>
                                        <b:AnchorListItem text="{resources.LogOut}" ui:field="logoutitem" />
                                    </b:DropDownMenu>
                                </b:ListDropDown>

                            </b:NavbarNav>
                        </b:NavbarCollapse>
                    </b:Container>
                </b:Navbar>

                <b:Row>
                    <b:Column size="XS_12">
                        <g:SimplePanel ui:field="contentContainer" />
                    </b:Column>
                </b:Row>

            </b:Container>
        </g:ScrollPanel>
    </g:HTMLPanel>

2 个答案:

答案 0 :(得分:4)

您似乎误以为Navbar Navs - 您的HTML示例使用nav-pills,而UiBinder则使用Navbarnavbar,{{ 1}}等。据我所知(从Bootstrap和gwtbootstrap3的文档中),不可能实现垂直(“堆叠”,就像他们在文档中所称的那样)navbar-header。但是 可以获得垂直/堆叠Navbar

NavPills

有关更多示例,请参阅the demo

答案 1 :(得分:1)

我采用了另一种解决问题的方法,并在bootstrap中使用了网格系统。因此,当我们在桌面时,我会显示侧面导航栏,而当我在平板电脑/手机上时,我会显示导航栏。它需要稍微调整一下,但这是我遇到问题的重要部分。

这是我的UiBinder代码

<b:Container>

    <b:Row>

        <b:Column size="XS_12,SM_12,MD_10,LG_10" visibleOn="XS_SM">

            <b:Navbar position="FIXED_TOP">
                <b:Container>
                    <b:NavbarHeader>
                        <b:NavbarBrand targetHistoryToken="{nameTokens.getHome}"
                            ui:field="brand" text="{resources.ProductName}" />
                        <b:NavbarCollapseButton dataTarget="#navbar-collapse" />
                    </b:NavbarHeader>

                    <b:NavbarCollapse b:id="navbar-collapse">
                        <b:NavbarNav>

                            <b:ListDropDown ui:field="admindropdown">
                                <b:AnchorButton dataToggle="DROPDOWN" text="{resources.CardHolder}" />
                                <b:DropDownMenu>
                                    <b:AnchorListItem text="{resources.Employee}" targetHistoryToken="{nameTokens.getCardholderlist}" />
                                    <b:AnchorListItem text="{resources.Guest}" targetHistoryToken="{nameTokens.getHome}" />
                                    <b:AnchorListItem text="{resources.Vendor}" targetHistoryToken="{nameTokens.getHome}" />
                                </b:DropDownMenu>
                            </b:ListDropDown>

                            <b:ListDropDown>
                                <b:AnchorButton dataToggle="DROPDOWN" text="{resources.User}" />
                                <b:DropDownMenu>
                                    <b:AnchorListItem text="{resources.Customer}" targetHistoryToken="{nameTokens.getHome}" />
                                    <b:AnchorListItem text="{resources.Technician}" targetHistoryToken="{nameTokens.getHome}" />
                                    <b:AnchorListItem text="{resources.Portal}" targetHistoryToken="{nameTokens.getHome}" />
                                    <b:AnchorListItem text="{resources.Cloud}" targetHistoryToken="{nameTokens.getHome}" />
                                </b:DropDownMenu>
                            </b:ListDropDown>

                            <b:ListDropDown>
                                <b:AnchorButton dataToggle="DROPDOWN" text="{resources.Configuration}" />
                                <b:DropDownMenu>
                                    <b:AnchorListItem text="{resources.Customer}" targetHistoryToken="{nameTokens.getCustomerlist}" />
                                    <b:AnchorListItem text="{resources.Company}" targetHistoryToken="{nameTokens.getCompanylist}" />
                                    <b:AnchorListItem text="{resources.Portal}" targetHistoryToken="{nameTokens.getHome}" />
                                    <b:AnchorListItem text="{resources.ProductNameServer}" targetHistoryToken="{nameTokens.getCloudlist}" />
                                </b:DropDownMenu>
                            </b:ListDropDown>

                        </b:NavbarNav>

                        <b:NavbarNav pull="RIGHT">

                            <b:ListDropDown addStyleNames="{style.languageImageStyle}">
                                <b:Image url="{resources.SelectedLanguageURL}" />
                            </b:ListDropDown>

                            <b:ListDropDown>
                                <b:AnchorButton text="{resources.SelectedLanguage}" dataToggle="DROPDOWN" />
                                <b:DropDownMenu>
                                    <b:Image addStyleNames="btn {style.btnStyle}" ui:field="languageDK" url="/images/DK.png" />
                                    <b:Image addStyleNames="btn {style.btnStyle}" ui:field="languageNO" url="/images/NO.png" />
                                    <b:Image addStyleNames="btn {style.btnStyle}" ui:field="languageUK" url="/images/UK.png" />
                                </b:DropDownMenu>
                            </b:ListDropDown>

                            <b:ListDropDown ui:field="loginfield">
                                <b:AnchorButton dataToggle="DROPDOWN" ui:field="loginname" />
                                <b:DropDownMenu>
                                    <b:AnchorListItem text="{resources.LogOut}" ui:field="logoutitem" />
                                </b:DropDownMenu>
                            </b:ListDropDown>

                        </b:NavbarNav>
                    </b:NavbarCollapse>
                </b:Container>
            </b:Navbar>

        </b:Column>
    </b:Row>

    <b:Row>

        <b:Column size="MD_3,LG_3" visibleOn="MD_LG">

             <b:Panel>

            <b:PanelBody>
                <b:PanelGroup b:id="accordion">

                    <b:Panel>
                        <b:PanelHeader>
                            <b:Heading size="H4">
                                <b:Anchor dataToggle="COLLAPSE" dataTarget="#collapseOne" text="{resources.CardHolder}"/>
                            </b:Heading>
                        </b:PanelHeader>
                        <b:PanelCollapse b:id="collapseOne" in="true" ui:field="collapseOne">
                            <b:PanelBody>
                                <b:AnchorListItem text="{resources.Employee}" targetHistoryToken="{nameTokens.getCardholderlist}" />
                                <b:AnchorListItem text="{resources.Guest}" targetHistoryToken="{nameTokens.getHome}" />
                                <b:AnchorListItem text="{resources.Vendor}" targetHistoryToken="{nameTokens.getHome}" />
                            </b:PanelBody>
                        </b:PanelCollapse>
                    </b:Panel>

                    <b:Panel>
                        <b:PanelHeader>
                            <b:Heading size="H4">
                                <b:Anchor dataToggle="COLLAPSE" dataTarget="#collapseTwo" text="{resources.User}"/>
                            </b:Heading>
                        </b:PanelHeader>
                        <b:PanelCollapse b:id="collapseTwo" in="true">
                            <b:PanelBody>
                                <b:AnchorListItem text="{resources.Customer}" targetHistoryToken="{nameTokens.getHome}" />
                                <b:AnchorListItem text="{resources.Technician}" targetHistoryToken="{nameTokens.getHome}" />
                                <b:AnchorListItem text="{resources.Portal}" targetHistoryToken="{nameTokens.getHome}" />
                                <b:AnchorListItem text="{resources.Cloud}" targetHistoryToken="{nameTokens.getHome}" />
                            </b:PanelBody>
                        </b:PanelCollapse>
                    </b:Panel>
                    <b:Panel>
                        <b:PanelHeader>
                            <b:Heading size="H4">
                                <b:Anchor dataToggle="COLLAPSE" dataTarget="#collapseThree" text="{resources.Configuration}"/>
                            </b:Heading>
                        </b:PanelHeader>
                        <b:PanelCollapse b:id="collapseThree" in="true">
                            <b:PanelBody>
                                <b:AnchorListItem text="{resources.Customer}" targetHistoryToken="{nameTokens.getCustomerlist}" />
                                <b:AnchorListItem text="{resources.Company}" targetHistoryToken="{nameTokens.getCompanylist}" />
                                <b:AnchorListItem text="{resources.Portal}" targetHistoryToken="{nameTokens.getHome}" />
                                <b:AnchorListItem text="{resources.ProductNameServer}" targetHistoryToken="{nameTokens.getCloudlist}" />
                            </b:PanelBody>
                        </b:PanelCollapse>
                    </b:Panel>

                    <b:Panel>
                        <b:PanelHeader>
                            <b:Heading size="H4">
                                <b:Anchor dataToggle="COLLAPSE" dataTarget="#collapseFour" text="Sprog"/>
                            </b:Heading>
                        </b:PanelHeader>
                        <b:PanelCollapse b:id="collapseFour" in="true">
                            <b:PanelBody>
                                <b:Image addStyleNames="btn" ui:field="languageDK2" url="/images/DK.png" />
                                <b:Image addStyleNames="btn" ui:field="languageNO2" url="/images/NO.png" />
                                <b:Image addStyleNames="btn" ui:field="languageUK2" url="/images/UK.png" />
                            </b:PanelBody>
                        </b:PanelCollapse>
                    </b:Panel>

                    <b:Panel>
                        <b:PanelHeader>
                            <b:Heading size="H4">
                                <b:Anchor dataToggle="COLLAPSE" dataTarget="#collapseFive" text="Login"/>
                            </b:Heading>
                        </b:PanelHeader>
                        <b:PanelCollapse b:id="collapseFive" in="true">
                            <b:PanelBody>
                                <b:AnchorListItem text="{resources.LogOut}" ui:field="logoutitem2" />
                            </b:PanelBody>
                        </b:PanelCollapse>
                    </b:Panel>

                </b:PanelGroup>
            </b:PanelBody>
        </b:Panel>

        </b:Column>

        <b:Column size="XS_12,SM_12,MD_9,LG_9">
            <g:SimplePanel ui:field="contentContainer" />
        </b:Column>
    </b:Row>

</b:Container>