@ RequestMapping ( method = RequestMethod . POST , params = "action=renameTab" ) public ModelAndView renameTab ( HttpServletRequest request , HttpServletResponse response ) throws IOException { IUserInstance ui = userInstanceManager . getUserInstance ( request ) ; UserPreferencesManager upm = ( UserPreferencesManager ) ui . getPreferencesManager ( ) ; IUserLayoutManager ulm = upm . getUserLayoutManager ( ) ; // element ID of the tab to be renamed String tabId = request . getParameter ( "tabId" ) ; IUserLayoutFolderDescription tab = ( IUserLayoutFolderDescription ) ulm . getNode ( tabId ) ; // desired new name String tabName = request . getParameter ( "tabName" ) ; if ( ! ulm . canUpdateNode ( tab ) ) { logger . warn ( "Attempting to rename an immutable tab" ) ; response . sendError ( HttpServletResponse . SC_FORBIDDEN ) ; return new ModelAndView ( "jsonView" , Collections . singletonMap ( "error" , getMessage ( "error.element.update" , "Unable to update element" , RequestContextUtils . getLocale ( request ) ) ) ) ; } /* * Update the tab and save the layout */ tab . setName ( StringUtils . isBlank ( tabName ) ? DEFAULT_TAB_NAME : tabName ) ; final boolean updated = ulm . updateNode ( tab ) ; if ( updated ) { try { // save the user's layout ulm . saveUserLayout ( ) ; } catch ( PortalException e ) { return handlePersistError ( request , response , e ) ; } // TODO why do we have to do this, shouldn't modifying the layout be enough to trigger a // full re-render (layout's cache key changes) this . stylesheetUserPreferencesService . setLayoutAttribute ( request , PreferencesScope . STRUCTURE , tabId , "name" , tabName ) ; } Map < String , String > model = Collections . singletonMap ( "message" , "saved new tab name" ) ; return new ModelAndView ( "jsonView" , model ) ; }
Rename a specified tab .