@RequestMapping(method = RequestMethod.POST, params = "action=removeByFName")
    public ModelAndView removeByFName(
            HttpServletRequest request,
            HttpServletResponse response,
            @RequestParam(value = "fname") String fname)
            throws IOException {

        IUserInstance ui = userInstanceManager.getUserInstance(request);

        UserPreferencesManager upm = (UserPreferencesManager) ui.getPreferencesManager();
        IUserLayoutManager ulm = upm.getUserLayoutManager();

        try {
            String elementId =
                    ulm.getUserLayout().findNodeId(new PortletSubscribeIdResolver(fname));
            if (elementId != null) {
                // Delete the requested element node.  This code is the same for
                // all node types, so we can just have a generic action.
                if (!ulm.deleteNode(elementId)) {
                    logger.info(
                            "Failed to remove element ID {} from layout root folder ID {}, delete node returned false",
                            elementId,
                            ulm.getRootFolderId());
                    response.setStatus(HttpServletResponse.SC_FORBIDDEN);
                    return new ModelAndView(
                            "jsonView",
                            Collections.singletonMap(
                                    "error",
                                    getMessage(
                                            "error.element.update",
                                            "Unable to update element",
                                            RequestContextUtils.getLocale(request))));
                }
            } else {
                response.sendError(HttpServletResponse.SC_BAD_REQUEST);
                return null;
            }

            ulm.saveUserLayout();

            return new ModelAndView("jsonView", Collections.emptyMap());

        } catch (PortalException e) {
            return handlePersistError(request, response, e);
        }
    }
@ RequestMapping ( method = RequestMethod . POST , params = "action=removeByFName" ) public ModelAndView removeByFName ( HttpServletRequest request , HttpServletResponse response , @ RequestParam ( value = "fname" ) String fname ) throws IOException { IUserInstance ui = userInstanceManager . getUserInstance ( request ) ; UserPreferencesManager upm = ( UserPreferencesManager ) ui . getPreferencesManager ( ) ; IUserLayoutManager ulm = upm . getUserLayoutManager ( ) ; try { String elementId = ulm . getUserLayout ( ) . findNodeId ( new PortletSubscribeIdResolver ( fname ) ) ; if ( elementId != null ) { if ( ! ulm . deleteNode ( elementId ) ) { logger . info ( "Failed to remove element ID {} from layout root folder ID {}, delete node returned false" , elementId , ulm . getRootFolderId ( ) ) ; response . setStatus ( HttpServletResponse . SC_FORBIDDEN ) ; return new ModelAndView ( "jsonView" , Collections . singletonMap ( "error" , getMessage ( "error.element.update" , "Unable to update element" , RequestContextUtils . getLocale ( request ) ) ) ) ; } } else { response . sendError ( HttpServletResponse . SC_BAD_REQUEST ) ; return null ; } ulm . saveUserLayout ( ) ; return new ModelAndView ( "jsonView" , Collections . emptyMap ( ) ) ; } catch ( PortalException e ) { return handlePersistError ( request , response , e ) ; } }
Remove the first element with the provided fname from the layout.

@param request HttpServletRequest
@param response HttpServletResponse
@param fname fname of the portlet to remove from the layout
@return json response
@throws IOException if the person cannot be retrieved