Announcement Announcement Module
Collapse
No announcement yet.
Handler mappings - access to from a view Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Handler mappings - access to from a view

    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:

    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&#40;currentView.getParentViewName&#40;&#41;.length&#40;&#41;<1&#41; &#123;
          editPath.add&#40;view&#41;;
        &#125;
        
        // re-build the edit path list by adding each parent view of the current view until home is reached
        else &#123;
          AdminTemplateView adminView = currentView;
          while&#40;adminView != null&#41; &#123;
            editPath.add&#40;0, adminView&#41;;
            if&#40;adminView.getParentViewName&#40;&#41;.length&#40;&#41;<1&#41;
              break;  // reached "home" top-level
            adminView = &#40;AdminTemplateView&#41;this.getApplicationContext&#40;&#41;.getBean&#40;adminView.getParentViewName&#40;&#41;&#41;;
          &#125;
        &#125;
        
      &#125;
    
      public void afterCompletion&#40;HttpServletRequest hreq,
          HttpServletResponse hresp, Object handler, Exception exception&#41; throws Exception &#123;
      &#125;
    
    &#125;
    where my supporting app config is (snippet):

    Code:
      <!-- 
        ================
          CONTROLLERS
        ================
      -->
      <bean id="handlerMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
        <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.VelocityView">
        <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:

    Code:
    <!-- current location -->
    <div id="pathlocation">
    #set&#40; $editPath = $editContext.editPath &#41;
    #foreach&#40; $path in $editPath &#41;
    <p><a href="$path.beanName">$path.pageTitle</a></p>
    <p class="branch">&gt;</p>
    #end
    which will render, for example, like this:

    Code:
    &#91;url&#93;Admin Home&#91;/url&#93; > &#91;url&#93;Account Interfaces&#91;/url&#93; > &#91;url&#93;Edit&#91;/url&#93;
    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
Working...
X