Spring Special Code


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;