how to populate a nevigation bar from a data base

91 views Asked by At

i tried to populate a dynamic navigation bar using data base.there are maintab and subtab tables.

i tried by this code but did not work :

<nav id="bb" class="navbar navbar-default">
    <div  class="container-fluid">
      <div  class="navbar-header">
        <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
          <span class="sr-only">Toggle navigation</span>
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
        </button>
        <a class="navbar-brand" href="#">home</a>
      </div>
      <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
        <ul class="nav navbar-nav">
        <c:if test="${not empty SubtabsList}">
          <c:forEach var="maintab"  items="${MaintabsList}">
            <li><a href="#">${maintab.description}</a></li>
            <ul class="dropdown-menu" role="menu">
              <c:forEach var="subtab"  items="${SubtabsList}">
                <c:if test="${subtab.maintab.maiTabId eq maintab.maiTabId}">
                  <li><a href="#">${subtab.description}</a></li>
                </c:if>
              </ul>
            </c:forEach>
          </c:forEach>
        </c:if>
      </ul>
    </div>
  </div>
</nav>

the sample reffering nevigation bar is as follows : i want auto generate this nevigation bar by data base.but unable to include <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">Dropdown <span class="caret"></span></a> in proper place.


<!-- <nav id="bb" class="navbar navbar-default"> -->

<!--    <div  class="container-fluid"> -->
<!--     Brand and toggle get grouped for better mobile display -->

<!--      <div  class="navbar-header"> -->

<!--        <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1"> -->
<!--         <span class="sr-only">Toggle navigation</span> -->

<!--            <span class="icon-bar"></span> -->
<!--         <span class="icon-bar"></span> -->
<!--         <span class="icon-bar"></span> -->
<!--       </button> -->

<!--         <a class="navbar-brand" href="#">Brand</a> -->

<!--     </div> -->

<!--     Collect the nav links, forms, and other content for toggling -->

<!--      <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1"> -->

<!--        <ul class="nav navbar-nav"> -->

<!--            <li class="active"><a href="#">Link <span class="sr-only">(current)</span></a></li> -->

<!--                <li><a href="#">Link</a></li> -->

<!--                <li class="dropdown"> -->

<!--                    <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">Dropdown <span class="caret"></span></a> -->

<!--                <ul class="dropdown-menu" role="menu"> -->

<!--                    <li><a href="#">Action</a></li> -->

<!--                    <li><a href="#">Another action</a></li> -->

<!--                    <li><a href="#">Something else here</a></li> -->

<!--                    <li class="divider"></li> -->

<!--                    <li><a href="#">Separated link</a></li> -->

<!--                    <li class="divider"></li> -->

<!--                    <li><a href="#">One more separated link</a></li> -->

<!--                </ul> -->

<!--            </li> -->

<!--        </ul> -->

<!--    </div>/.navbar-collapse -->

<!--        </div>/.container-fluid -->

<!-- </nav> -->
1

There are 1 answers

0
nimaya On BEST ANSWER
<nav id="bb" class="navbar navbar-default">

        <div class="container-fluid">


            <div class="navbar-header">

                <button type="button" class="navbar-toggle collapsed"
                    data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
                    <span class="sr-only">Toggle navigation</span> <span
                        class="icon-bar"></span> <span class="icon-bar"></span> <span
                        class="icon-bar"></span>
                </button>
                <a class="navbar-brand" href="#">home</a>
            </div>



            <div class="collapse navbar-collapse"
                id="bs-example-navbar-collapse-1">

                <ul class="nav navbar-nav">
                    <c:if test="${not empty SubtabsList}">
                        <c:forEach var="maintab" items="${MaintabsList}">
                            <li class="dropdown"><a href="#" class="dropdown-toggle"
                                data-toggle="dropdown" role="button" aria-expanded="false">${maintab.description}
                                    <span class="caret"></span>
                            </a>

                                <ul class="dropdown-menu" role="menu">
                                    <c:forEach var="subtab" items="${SubtabsList}">

                                        <c:if test="${subtab.maintab.maiTabId == maintab.maiTabId}">


                                            <li><a href="${subtab.ref}">${subtab.description}</a></li>



                                        </c:if>



                                    </c:forEach>
                                </ul></li>


                        </c:forEach>

                    </c:if>
                </ul>
            </div>
        </div>
    </nav>