java - Dynamic menu and titles in JSP -
for example, have 2 pages, left menu , use layout tags. tag left menu:
<%@tag description="left panel" pageencoding="utf-8" %> <%@taglib prefix="spring" uri="http://www.springframework.org/tags" %> <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@attribute name="page" required="true"%> <ul> <!-- dashboard --> <li <c:if test="${page == 'dashboard'}">class="active"</c:if>> <a href="<c:url value='/dashboard'/>"> <spring:message code="navigation.button.dashboard"/> </a> </li> <!-- settings --> <li <c:if test="${page == 'settings'}">class="active"</c:if>> <a href="<c:url value='/settings/'/>"> <spring:message code="navigation.button.settings"/> </a> </li> </ul>
for view active menu use variable page , in spring controller set model attribute, example:
@controller @requestmapping(value = "/settings") public final class settingcontroller { @modelattribute("page") public final string getpage() { return "settings";} @requestmapping(value = "/") public final string home(final principal principal) { if (principal == null) return "login"; return "settings"; } }
for title of page used page attribute too. think not best way. maybe knows best way dynamic view active menu , title of page?
Comments
Post a Comment