PDA

View Full Version : Handler mappings - access to from a view


jopaki
Aug 29th, 2005, 04:23 PM
I have a HandlerInterceptor that maintains a list of View refrences which represent the current "edit path". This serves as model data for a "chain of links" I want to display in rendered pages (views). Here is my "PathLocationInterceptor" code:


public class PathLocationInterceptor extends ApplicationObjectSupport implements HandlerInterceptor {

public boolean preHandle(HttpServletRequest hreq, HttpServletResponse hresp, Object handler) throws Exception {
return true;
}

public void postHandle(HttpServletRequest hreq, HttpServletResponse hresp, Object handler, ModelAndView mav) throws Exception {
// update the view with the current path location

HttpSession session = hreq.getSession(false);
if(session == null) return;

EditContext editContext = (EditContext)session.getAttribute(ServletConstants .EDIT_CONTEXT);
if(editContext == null) return;
List editPath = editContext.getEditPath();

View view = mav.getView();
if( !(view instanceof AdminTemplateView) ) return;

AdminTemplateView currentView = (AdminTemplateView)view;
if(currentView.getBeanName()==null || currentView.getParentViewName()==null) return; // NOTE: bail w/ no exception (?)

editPath.clear();

// at home?
if(currentView.getParentViewName().length()<1) {
editPath.add(view);
}

// re-build the edit path list by adding each parent view of the current view until home is reached
else {
AdminTemplateView adminView = currentView;
while(adminView != null) {
editPath.add(0, adminView);
if(adminView.getParentViewName().length()<1)
break; // reached "home" top-level
adminView = (AdminTemplateView)this.getApplicationContext().ge tBean(adminView.getParentViewName());
}
}

}

public void afterCompletion(HttpServletRequest hreq,
HttpServletResponse hresp, Object handler, Exception exception) throws Exception {
}

}


where my supporting app config is (snippet):


<!--
================
CONTROLLERS
================
-->
<bean id="handlerMapping" class="org.springframework.web.servlet.handler.SimpleUrlH andlerMapping">
<property name="interceptors">
<list>
<ref local="contentInterceptor"/>
<ref local="editContextInterceptor"/>
<ref local="pathLocationInterceptor"/>
</list>
</property>
<property name="mappings">
<props>
<prop key="adminLogin">adminLoginController</prop>
<prop key="/home">adminHomeController</prop>
</props>
</property>
</bean>

<!--
================
VIEWS
================
-->

<bean name="adminLoginView" class="org.springframework.web.servlet.view.velocity.Velo cityView">
<property name="url" value="admin-login.vm"/>
</bean>

<bean name="adminHomeView" class="com.tll.servlet.admin.AdminTemplateView">
<property name="exposeSpringMacroHelpers" value="true"/>
<property name="url" value="admin-home.vm"/>
<property name="layoutUrl" value="template.vm"/>
<property name="parentViewName" value=""/>
<property name="pageTitle" value="Admin Home"/>
</bean>



So in my one velocity layout template I have:


<!-- current location -->
<div id="pathlocation">
#set( $editPath = $editContext.editPath )
#foreach( $path in $editPath )
<p><a href="$path.beanName">$path.pageTitle</a></p>
<p class="branch">&gt;</p>
#end


which will render, for example, like this:


[url]Admin Home[/url] > [url]Account Interfaces[/url] > [url]Edit[/url]


Obvoiously, I need each of these links to route appropriately which implies I need knowledge of the HandlerMapping logical urls that binds to the respective controllers. But these logical urls are not contained in the views.

How do I obtain the needed logical urls for each view link?

Thanks, Jon