ITeye博客

Spring Special Code

zenius · 2009-03-03 09:04 · Spring · Markdown

Set flow and menu item mapping


 
    public void setLocationMaps(MenuComponent[] menuComponents) {

        for (MenuComponent menuComponent: menuComponents) {
           if (null == this.locationMapping.get(menuComponent.getLocation()) 
                   || null != menuComponent.getParent()) {
               this.locationMapping.put(menuComponent.getLocation(), menuComponent);
           }
           if (menuComponent.getMenuComponents().length > 0) {
               this.setLocationMaps(menuComponent.getMenuComponents());
           }
        }
    }


Once Request filter


public class MenuFilter extends OncePerRequestFilter {

    /**
     * This method looks for a "locale" request parameter. If it finds one, it sets it as the preferred locale
     * and also configures it to work with JSTL.
     * 
     * @param request the current request
     * @param response the current response
     * @param chain the chain
     * @throws IOException when something goes wrong
     * @throws ServletException when a communication failure happens
     */
    @SuppressWarnings("unchecked")
    public void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
                                 FilterChain chain)
            throws IOException, ServletException {


        chain.doFilter(request, response);

        // Reset thread-bound LocaleContext.
        LocaleContextHolder.setLocaleContext(null);
    }
}


Flow Execution listener and external context


public class MenuFlowLister extends FlowExecutionListenerAdapter {

    public void requestProcessed(RequestContext context) {
        String id = context.getActiveFlow().getId();

        MenuRepository menus = (MenuRepository) context.getExternalContext().getApplicationMap()
                .get(MenuRepository.MENU_REPOSITORY_KEY);
    }
}

Get session attributes


        Object mutex = RequestContextHolder.currentRequestAttributes().getSessionMutex();
        RequestAttributes attributes = RequestContextHolder.currentRequestAttributes();
        String test;
        synchronized (mutex) {
            test = (String)attributes.getAttribute("zenius", RequestAttributes.SCOPE_SESSION);
        }
        return test;

评论(1)

  1. #1 楼 · iql · 2009-03-12 15:52

    你好,请教一下为什么要这样来取session中的值?而不用HttpSession?

评论功能维护中,当前仅展示历史评论。