class ScriptKtrl extends BaseKontroller {

    private static final Logger log = LoggerFactory.getLogger(ScriptKtrl.class);

    @Model(name = "sortedSet")
    SortedSet sortedSet = new SortedSet();
    @Model(name = "script")
    Script script = new Script();

    public ScriptKtrl(HttpServletRequest request, HttpServletResponse response) {
        super(request, response);
    }

    @Kontrol(path = "/admin/viewScripts", method = MethodType.GET)
    public String viewScripts() throws ServletException {
        try {
            Long userId = AuthUtil.getUserId(getRequest().getSession());
            sortedSet = ScriptDB.getScriptSet(sortedSet, userId);
        } catch (SQLException | GeneralSecurityException ex) {
            log.error(ex.toString(), ex);
            throw new ServletException(ex.toString(), ex);
        }

        return "/admin/view_scripts.html";
    }


    @Kontrol(path = "/admin/saveScript", method = MethodType.POST)
    public String saveScript() throws ServletException {
        try {
            Long userId = AuthUtil.getUserId(getRequest().getSession());
            if (script.getId() != null) {
                ScriptDB.updateScript(script, userId);
            } else {
                ScriptDB.insertScript(script, userId);
            }
        } catch (SQLException | GeneralSecurityException ex) {
            log.error(ex.toString(), ex);
            throw new ServletException(ex.toString(), ex);
        }
        return "redirect:/admin/viewScripts.ktrl?sortedSet.orderByDirection=" + sortedSet.getOrderByDirection() + "&sortedSet.orderByField=" + sortedSet.getOrderByField();
    }

    @Kontrol(path = "/admin/deleteScript", method = MethodType.GET)
    public String deleteScript() throws ServletException {

        if (script.getId() != null) {
            try {
                Long userId = AuthUtil.getUserId(getRequest().getSession());
                ScriptDB.deleteScript(script.getId(), userId);
            } catch (SQLException | GeneralSecurityException ex) {
                log.error(ex.toString(), ex);
                throw new ServletException(ex.toString(), ex);
            }
        }
        return "redirect:/admin/viewScripts.ktrl?sortedSet.orderByDirection=" + sortedSet.getOrderByDirection() + "&sortedSet.orderByField=" + sortedSet.getOrderByField();
    }


    /**
     * Validates all fields for adding a user
     */
    @Validate(input = "/admin/view_scripts.html")
    public void validateSaveScript() throws ServletException {<FILL_FUNCTION_BODY>}
}

        if (script == null
                || script.getDisplayNm() == null
                || script.getDisplayNm().trim().equals("")) {
            addFieldError("script.displayNm", "Required");
        }

        if (script == null
                || script.getScript() == null
                || script.getScript().trim().equals("")
                || (new Script()).getScript().trim().equals(script.getScript().trim())) {
            addFieldError("script.script", "Required");
        }

        if (!this.getFieldErrors().isEmpty()) {
            try {
                Long userId = AuthUtil.getUserId(getRequest().getSession());
                sortedSet = ScriptDB.getScriptSet(sortedSet, userId);
            } catch (SQLException | GeneralSecurityException ex) {
                log.error(ex.toString(), ex);
                throw new ServletException(ex.toString(), ex);
            }
        }
    
<no_super_class>