public int doEndTag() throws JspException {
        try {
            List<ValidationMetaData> rules = new ArrayList<ValidationMetaData>();
            if (commandName != null) {
                rules.addAll(getValidationMetaDataForCommand());
            }
            String bodyString = null;
            if (bodyContent != null) {
              // body can be a JSON object, specifying date formats, or other extra configuration info
              bodyString = FileCopyUtils.copyToString(bodyContent.getReader());
              bodyString = bodyString.trim().replaceAll("\\s{2,}"," ");
            }

            JspWriter out = pageContext.getOut();
            out.write("<script type=\"text/javascript\" id=\"");
            out.write(commandName + "JSR303JSValidator");
            out.write("\">");
            generator.generateJavaScript(out, commandName, true, bodyString, rules, new MessageSourceAccessor(
                getRequestContext().getWebApplicationContext(), getRequestContext().getLocale()));
            out.write("</script>");
            return EVAL_PAGE;
        }
        catch (IOException e) {
            throw new JspException("Could not write validation rules", e);
        }
    }