Below codes doen’t work
for (int i = 0, j = navList.size(); i < j; i++) {
Channel chn = (Channel) navList.get(i);
String channelName = chn.getData().getName();
String channelId = chn.getContentManagementId().getId();
RequestContext rqCtx = PageUtil.getCurrentRequestContext(pageContext);// get request context from somewhere
String currntChannelId = (rqCtx.getRequestChannelId()== null? null:rqCtx.getRequestChannelId().getId());
String link = XSLPageUtil.buildLinkURI(rqCtx, channelId, "", "");
if(currntChannelId!= null && currntChannelId.equals(channelId)) {
%>
<tr>
<td class="nav_menuitem_selected"><a href="<%=link %>"><%=channelName %></a></td>
</tr>
<%
} else {
Below codes works
for (int i = 0, j = navList.size(); i < j; i++) {
Channel chn = (Channel) navList.get(i);
String channelName = chn.getData().getName();
String channelId = chn.getContentManagementId().getId();
RequestContext rqCtx = PageUtil.getCurrentRequestContext(pageContext);// get request context from somewhere
String currntChannelId = null;
Channel currntChannel = rqCtx.getRequestedChannel();
if(currntChannel != null) {
currntChannelId = currntChannel.getContentManagementId()
.getId();
}
String link = XSLPageUtil.buildLinkURI(rqCtx, channelId, "", "");
if(currntChannelId!= null && currntChannelId.equals(channelId)) {
%>
本文探讨了在网页开发中如何正确实现导航菜单的选中状态。通过对比两种不同的实现方式,指出了其中一种方法存在的问题,并给出了有效的解决方案。文章详细介绍了如何获取当前请求上下文及如何判断当前导航项是否被选中。
548

被折叠的 条评论
为什么被折叠?



