## ============================================================================ ## Filename : WebDeleteCmdTemplate.vm ## Note(s) : This template is used to generate a DeleteCommand Java class. ## ## Note: The generated code is dependent on the ThinkUI framework. ## Please refer to the SQL Client documentation for details. ## ## Copyright (c) 2007 ThinkUI Software Inc. All rights reserved. ## ============================================================================ ## ## **************************************************************************** ## The following variables are available in this template. For more ## information on any of the following variable, please refer to the user guide. ## **************************************************************************** ## $projectName ## $authorName ## $headerText ## $objectName ## $objectVar ## $pkAttr ## $objectCaption ## $className ## $packageName ## $subPackageName ## $prjPkgName ## $prjClassPrefix ## $superClassName ## $dataClass ## $date ## $codeGen ## $attributes ## #if ($packageName) package $packageName; #end #parse( "ClassHeaderInclude.vm" ) import ${subPackageName}.proxies.${prjClassPrefix}Proxy; import ${subPackageName}.${prjClassPrefix}SessionManager; import thinkui.web.${superClassName}; import thinkui.web.AbstractWebCommand; import thinkui.web.SelectionHandler; import thinkui.web.WebCommandContext; /** * Implements a command to delete the specified ${objectName} object. */ public class ${className} extends ${superClassName} { /** * ${className} constructor. */ public ${className}() { super(); } /* public final ApplicationPermission getPermission() { return Permissions.ADMINISTRATOR_ROLE; } */ /** * Delete the specified data object from the database. */ protected final void deleteObject(WebCommandContext ctx, Object ${objectVar}Id) throws Exception { ${prjClassPrefix}Proxy proxy = (${prjClassPrefix}Proxy) ctx.lookupProxy(${prjClassPrefix}Proxy.NAME); try { proxy.delete${objectName}(${objectVar}Id); } finally { proxy.remove(); } // Clear the current ${objectName} object from the session (if any). ${prjClassPrefix}SessionManager sessionMgr = new ${prjClassPrefix}SessionManager(ctx); sessionMgr.set${objectName}(null); // Clear cached data from the user session (if any). sessionMgr.set${objectName}EnumType(null); ctx.addMessage("${objectCaption} " + ${objectVar}Id + " successfully deleted."); } /** * Delete the specified data object from the database. */ protected final void deleteObjects( WebCommandContext ctx, SelectionHandler selectionHandler) throws Exception { ${prjClassPrefix}Proxy proxy = (${prjClassPrefix}Proxy) ctx.lookupProxy(${prjClassPrefix}Proxy.NAME); java.util.Set selectedIds = selectionHandler.getSelectedValues(ctx); int count = selectedIds.size(); if (count > 0) { try { count = proxy.delete${objectName}s(selectedIds); } finally { proxy.remove(); } // Clear the current ${objectName} object from the session (if any). ${prjClassPrefix}SessionManager sessionMgr = new ${prjClassPrefix}SessionManager(ctx); sessionMgr.set${objectName}(null); // Clear cached data from the user session (if any). sessionMgr.set${objectName}EnumType(null); ctx.addMessage( String.valueOf(count) + " ${objectCaption.toLowerCase()}s successfully deleted."); } else { ctx.addUserError( "Please select at least one ${objectCaption.toLowerCase()} to delete."); } } /** * Return the command that should be forwarded to upon a successful delete. * * @return the command that should be forwarded to upon a successful delete. */ protected final AbstractWebCommand getSuccessCommand( WebCommandContext ctx, Object ${objectVar}Id) throws Exception { ShowSearch${objectName}Command cmd = new ShowSearch${objectName}Command(); cmd.setClearSearchCriteria(false); return cmd; } /** * Return the command that should be forwarded to upon an unsuccessful delete. * * @return the command that should be forwarded to upon an unsuccessful delete. */ protected final AbstractWebCommand getFailureCommand( WebCommandContext ctx, Object ${objectVar}Id) throws Exception { ShowSearch${objectName}Command cmd = new ShowSearch${objectName}Command(); cmd.setClearSearchCriteria(false); return cmd; } }