Example usage for javax.servlet.jsp JspException JspException

List of usage examples for javax.servlet.jsp JspException JspException

Introduction

In this page you can find the example usage for javax.servlet.jsp JspException JspException.

Prototype

public JspException(Throwable cause) 

Source Link

Document

Constructs a new JspException with the specified cause.

Usage

From source file:com.jaspersoft.jasperserver.war.tags.JasperViewerTag.java

public int doEndTag() throws JspException {
    HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
    HttpServletResponse response = (HttpServletResponse) pageContext.getResponse();

    try {//from   w w  w .  j  a v  a 2 s  .  co  m
        ReportUnitResult reportResult = getReportResult(request);
        JasperPrintAccessor printAccessor = reportResult.getJasperPrintAccessor();
        if (printAccessor == null) {
            log.error("There is no JasperPrint object cannot be accessed.");
            return EVAL_PAGE;
        }

        setReportContextAttributes(request, reportResult);

        Integer pageIndex = (Integer) request.getAttribute(getPageIndexAttribute());
        if (pageIndex == null) {
            pageIndex = new Integer(0);
        }

        ReportExecutionStatus reportStatus = printAccessor.getReportStatus();

        // get the status of the page, waiting for the page to be available in necessary
        ReportPageStatus pageStatus = printAccessor.pageStatus(pageIndex.intValue(), null);

        request.setAttribute("page", page);
        request.setAttribute("dataTimestamp", reportResult.getDataTimestamp());

        request.setAttribute(INNER_PAGINATION_ATTRIBUTE, innerPagination);
        request.setAttribute(IGNORE_PAGE_MARGINS, ignorePageMargins);

        Integer totalPageCount = reportStatus.getTotalPageCount();
        // set the total page count if known
        if (totalPageCount != null) {
            request.setAttribute("lastPageIndex", new Integer(totalPageCount - 1));

            //FIXME this duplicates logic in ReportExecutionController.viewReportPageUpdateCheck
            SnapshotSaveStatus snapshotSaveStatus = getDataCacheProvider()
                    .getSnapshotSaveStatus(reportResult.getReportContext());
            if (snapshotSaveStatus != null) {
                request.setAttribute("snapshotSaveStatus", snapshotSaveStatus.toString());
            }
        }

        // set the partial page count
        request.setAttribute("lastPartialPageIndex", new Integer(reportStatus.getCurrentPageCount() - 1));

        // if the page count is null, it means that the fill is not yet done but there is at least a page
        boolean emptyReport = totalPageCount != null && totalPageCount.intValue() == 0;
        request.setAttribute(EMPTY_REPORT_ATTRIBUTE, Boolean.valueOf(emptyReport));

        ApplicationContext applicationContext = getRequestContext().getWebApplicationContext();
        request.setAttribute(MESSAGE_SOURCE, applicationContext.getBean("messageSource"));

        if (!emptyReport) {
            if (!pageStatus.pageExists()) {
                // setting a header as there's no simple way currently to detect a specific exception in the client
                response.setHeader("reportPageNonExisting", "true");
                throw new JSException("jsexception.view.page.does.not.exist", new Object[] { pageIndex });
            }

            request.setAttribute("pageIndex", pageIndex);

            if (!pageStatus.isPageFinal()) {
                request.setAttribute("pageTimestamp", pageStatus.getTimestamp());
            }

            JasperReportsContext jasperReportsContext = getJasperReportsContext(applicationContext);

            AbstractHtmlExporter exporter = HtmlExportUtil.getHtmlExporter(jasperReportsContext);
            exporter.setParameter(JRExporterParameter.JASPER_PRINT, printAccessor.getJasperPrint());
            exporter.setParameter(JRExporterParameter.PAGE_INDEX, pageIndex);
            exporter.setImageHandler(
                    new WebHtmlResourceHandler(response.encodeURL(imageServlet + "image={0}")));
            exporter.setResourceHandler(
                    new WebHtmlResourceHandler(response.encodeURL(resourceServlet + "/{0}")));
            exporter.setFontHandler(
                    new WebHtmlResourceHandler(response.encodeURL(resourceServlet + "&font={0}")));

            StringBuffer htmlHeader = new StringBuffer();
            String contextPath = request.getContextPath();

            // fix for Bug 26294 - [case #24473 +1] Problem with IE8 and IE9 when embedding app into iframe
            String referer = request.getHeader("Referer");
            referer = referer.substring(0, referer.indexOf(contextPath) + contextPath.length());
            // end fix
            exporter.setParameter(JRHtmlExporterParameter.HTML_HEADER, htmlHeader.toString());

            exporter.setParameter(JRHtmlExporterParameter.HTML_FOOTER, "");
            exporter.setParameter(JRHtmlExportUtils.PARAMETER_HTTP_REQUEST, request);
            exporter.setParameter(JRExporterParameter.IGNORE_PAGE_MARGINS, ignorePageMargins);
            WebflowReportContext webflowReportContext = getReportContextAccessor().getContext(request,
                    reportContextMap);
            webflowReportContext.setParameterValue("net.sf.jasperreports.web.app.context.path", contextPath);//FIXMEJIVE use constant
            //              webflowReportContext.setParameterValue(JRParameter.REPORT_CONTEXT, webflowReportContext);
            exporter.setReportContext(webflowReportContext);
            // hide the preview toolbar if view as dashboard frame
            if ((webflowReportContext.getParameterValue(ReportParametersAction.VIEW_AS_DASHBOARD_FRAME) != null)
                    && webflowReportContext.getParameterValue(ReportParametersAction.VIEW_AS_DASHBOARD_FRAME)
                            .toString().equalsIgnoreCase("true")) {
                request.setAttribute(ReportParametersAction.VIEW_AS_DASHBOARD_FRAME, "true");
            }
            HyperlinkProducerFactoryFlowFactory linkProducerFactory = (HyperlinkProducerFactoryFlowFactory) request
                    .getAttribute(getLinkProducerFactoryAttribute());
            if (linkProducerFactory != null) {
                JRHyperlinkProducerFactory hyperlinkProducerFactory = linkProducerFactory
                        .getHyperlinkProducerFactory(request, response);
                exporter.setParameter(JRExporterParameter.HYPERLINK_PRODUCER_FACTORY, hyperlinkProducerFactory);
            }

            /*
             * Future enhancement
             * 
             *             JRExporter exporter = (providedExporterClassName != null)
                   ? defaultExporter(jasperPrint, pageIndex) 
                   : providedExporter(jasperPrint, pageIndex);
                        setParameters(exporter);
            */
            request.setAttribute("exporter", exporter);

            boolean isComponentMetadataEmbedded = WebUtil.getInstance(jasperReportsContext)
                    .isComponentMetadataEmbedded();
            request.setAttribute("isComponentMetadataEmbedded", isComponentMetadataEmbedded);
            if (isComponentMetadataEmbedded) {
                JsonExporter jsonExporter = new JsonExporter(jasperReportsContext);
                jsonExporter.setReportContext(webflowReportContext);
                jsonExporter.setParameter(JRExporterParameter.JASPER_PRINT, printAccessor.getJasperPrint());
                request.setAttribute("jsonExporter", jsonExporter);
            }

            // set report status on response header
            LinkedHashMap<String, Object> result = new LinkedHashMap<String, Object>();
            result.put("reportStatus", reportStatus.getStatus().toString().toLowerCase());
            result.put("totalPages", reportStatus.getTotalPageCount());
            result.put("partialPageCount", reportStatus.getCurrentPageCount());
            result.put("pageFinal", pageStatus.isPageFinal());
            result.put("contextid", webflowReportContext.getId());
            result.put("isComponentMetadataEmbedded", isComponentMetadataEmbedded);
            result.put("jasperPrintName", request.getAttribute("jasperPrintName"));
            if (!pageStatus.isPageFinal()) {
                result.put("pageTimestamp", String.valueOf(pageStatus.getTimestamp()));
            }

            String defaultZoomProperty = printAccessor.getJasperPrint()
                    .getProperty("net.sf.jasperreports.viewer.zoom"); // FIXME: use constant
            if (defaultZoomProperty != null) {
                ZoomTypeEnum zoomType = ZoomTypeEnum.getByName(defaultZoomProperty);
                result.put("defaultZoom", zoomType != null ? zoomType.getHtmlValue() : defaultZoomProperty);
            }

            response.setHeader("jasperreports-report-status",
                    JacksonUtil.getInstance(jasperReportsContext).getJsonString(result));
        }

        BodyContent nestedContent = pageContext.pushBody();
        boolean popped = false;
        try {
            pageContext.include(getRenderJsp());
            popped = true;
            pageContext.popBody();
            nestedContent.writeOut(pageContext.getOut());
        } finally {
            if (!popped) {
                pageContext.popBody();
            }
        }

    } catch (Exception e) {
        if (e instanceof SessionAttribMissingException) {
            throw new SessionAttribMissingException(e.getMessage(),
                    ((SessionAttribMissingException) e).getArgs());
        } else {
            throw new JspException(e);
        }
    }

    return EVAL_PAGE;
}

From source file:com.hightern.ecside.table.tag.ColumnTag.java

/**
 * Must make a copy of the column because this tag may be reused. Send the
 * copy up to the Model./*from   w  w w . java 2 s.c  o  m*/
 */
public int doEndTag() throws JspException {
    try {
        TableModel model = TagUtils.getModel(this);

        if (TagUtils.isIteratingBody(this)) {
            String alias = TagUtils.evaluateExpressionAsString("alias", this.alias, this, pageContext);
            String property = TagUtils.evaluateExpressionAsString("property", this.property, this, pageContext);
            Column column = model.getColumnHandler()
                    .getColumnByAlias(TableModelUtils.getAlias(alias, property));
            if (column != null) { // null if view not allowed
                Object bean = TagUtils.getModel(this).getCurrentRowBean();
                Object propertyValue = TableModelUtils.getColumnPropertyValue(bean, property);
                column.setValue(getColumnValue(propertyValue));
                column.setPropertyValue(propertyValue);

                modifyColumnAttributes(model, column);
                model.getColumnHandler().modifyColumnAttributes(column);
                model.getViewHandler().addColumnValueToView(column);
            }
        } else {
            Column column = new Column(model);
            column.setAlias(TagUtils.evaluateExpressionAsString("alias", this.alias, this, pageContext));
            column.setCalc(TagUtils.evaluateExpressionAsString("calc", this.calc, this, pageContext));
            column.setCalcTitle(TagUtils.evaluateExpressionAsString("calcTitle", calcTitle, this, pageContext));
            column.setCell(TagUtils.evaluateExpressionAsString("cell", this.cell, this, pageContext));
            column.setEscapeAutoFormat(TagUtils.evaluateExpressionAsBoolean("escapeAutoFormat",
                    this.escapeAutoFormat, this, pageContext));
            column.setFilterable(
                    TagUtils.evaluateExpressionAsBoolean("filterable", this.filterable, this, pageContext));
            column.setFilterCell(
                    TagUtils.evaluateExpressionAsString("filterCell", this.filterCell, this, pageContext));
            column.setFilterClass(
                    TagUtils.evaluateExpressionAsString("filterClass", this.filterClass, this, pageContext));
            column.setFilterOptions(TagUtils.evaluateExpressionAsObject("filterOptions", this.filterOptions,
                    this, pageContext));
            column.setFilterStyle(
                    TagUtils.evaluateExpressionAsString("filterStyle", this.filterStyle, this, pageContext));
            column.setFormat(TagUtils.evaluateExpressionAsString("format", this.format, this, pageContext));
            column.setHeaderCell(
                    TagUtils.evaluateExpressionAsString("headerCell", this.headerCell, this, pageContext));
            column.setHeaderClass(
                    TagUtils.evaluateExpressionAsString("headerClass", this.headerClass, this, pageContext));
            column.setHeaderStyle(
                    TagUtils.evaluateExpressionAsString("headerStyle", this.headerStyle, this, pageContext));
            column.setInterceptor(
                    TagUtils.evaluateExpressionAsString("interceptor", this.interceptor, this, pageContext));
            column.setParse(TagUtils.evaluateExpressionAsString("parse", this.parse, this, pageContext));
            column.setProperty(
                    TagUtils.evaluateExpressionAsString("property", this.property, this, pageContext));
            column.setSortable(
                    TagUtils.evaluateExpressionAsBoolean("sortable", this.sortable, this, pageContext));
            column.setStyle(TagUtils.evaluateExpressionAsString("style", this.style, this, pageContext));
            column.setStyleClass(
                    TagUtils.evaluateExpressionAsString("styleClass", this.styleClass, this, pageContext));
            column.setTitle(TagUtils.evaluateExpressionAsString("title", this.title, this, pageContext));
            column.setViewsAllowed(
                    TagUtils.evaluateExpressionAsString("viewsToAllow", this.viewsAllowed, this, pageContext));
            column.setViewsDenied(
                    TagUtils.evaluateExpressionAsString("viewsToDeny", this.viewsDenied, this, pageContext));
            column.setWidth(TagUtils.evaluateExpressionAsString("width", this.width, this, pageContext));

            addColumnAttributes(model, column);
            model.getColumnHandler().addColumn(column);
        }

        if (bodyContent != null) {
            bodyContent.clearBody();
        }
    } catch (Exception e) {
        throw new JspException("ColumnTag.doEndTag() Problem: " + ExceptionUtils.formatStackTrace(e));
    }

    return EVAL_PAGE;
}

From source file:com.sun.faces.taglib.html_basic.CommandLinkTag.java

public int doEndTag() throws JspException {
    String content = null;/*from  w  w  w . j a v  a 2 s.c om*/
    try {
        if (null != (bodyContent = getBodyContent())) {
            content = bodyContent.getString();
            getPreviousOut().write(content);
        }
    } catch (IOException iox) {
        throw new JspException(iox);
    }
    int rc = super.doEndTag();
    return rc;
}

From source file:com.redhat.rhn.frontend.taglibs.list.ListTagUtil.java

/**
 * Includes arbitrary _local_ url as content
 * @param ctx caller's page context//from ww  w .  j a v  a 2 s  .  co  m
 * @param url local url
 * @throws JspException if something goes wrong
 *
 * Note: Local means Urls in the same application
 */
public static void includeContent(PageContext ctx, String url) throws JspException {
    HttpServletRequest request = (HttpServletRequest) ctx.getRequest();
    HttpServletResponse response = (HttpServletResponse) ctx.getResponse();
    RequestDispatcher rd = request.getSession(true).getServletContext().getRequestDispatcher(url);
    if (rd == null) {
        ListTagUtil.write(ctx, "<!-- " + url + " not found -->");
    } else {
        try {
            BufferedResponseWrapper wrapper = new BufferedResponseWrapper(response);
            rd.include(request, wrapper);
            wrapper.flush();
            ListTagUtil.write(ctx, wrapper.getBufferedOutput());
        } catch (Exception e) {
            throw new JspException(e);
        }
    }
}

From source file:com.googlecode.jtiger.modules.ecside.tag.TableTag.java

public int doStartTag() throws JspException {
    try {/*  w  w  w .j  a v  a2 s . c  o m*/
        // initialize the attributes
        iterator = null;
        pageContext.setAttribute(TableConstants.ROWCOUNT, "0");
        // fire up the model with the context, preferences and messages
        model = new TableModelImpl(new JspPageContext(pageContext),
                TagUtils.evaluateExpressionAsString("locale", this.locale, this, pageContext));

        // boolean isExported =
        // ExportFilterUtils.isExported(model.getContext());
        // boolean isPrint =
        // "_print_".equals(ExportFilterUtils.getExportFileName(model.getContext()));

        table = new Table(model);
        table.setView(TagUtils.evaluateExpressionAsString("view", this.view, this, pageContext));

        table.setGenerateScript(
                TagUtils.evaluateExpressionAsBoolean("generateScript", this.generateScript, this, pageContext));
        table.setUseAjax(TagUtils.evaluateExpressionAsBoolean("useAjax", this.useAjax, this, pageContext));
        table.setDoPreload(
                TagUtils.evaluateExpressionAsBoolean("doPreload", this.doPreload, this, pageContext));
        table.setClassic(TagUtils.evaluateExpressionAsBoolean("classic", this.classic, this, pageContext));

        table.setAction(TagUtils.evaluateExpressionAsString("action", action, this, pageContext));
        table.setEnctype(TagUtils.evaluateExpressionAsString("enctype", enctype, this, pageContext));

        table.setInsertAction(
                TagUtils.evaluateExpressionAsString("insertAction", insertAction, this, pageContext));
        table.setUpdateAction(
                TagUtils.evaluateExpressionAsString("updateAction", updateAction, this, pageContext));
        table.setDeleteAction(
                TagUtils.evaluateExpressionAsString("deleteAction", deleteAction, this, pageContext));
        table.setShadowRowAction(
                TagUtils.evaluateExpressionAsString("shadowRowAction", shadowRowAction, this, pageContext));

        table.setBatchUpdate(
                TagUtils.evaluateExpressionAsBoolean("batchUpdate", this.batchUpdate, this, pageContext));
        table.setAutoIncludeParameters(TagUtils.evaluateExpressionAsBoolean("autoIncludeParameters",
                this.autoIncludeParameters, this, pageContext));
        table.setBorder(TagUtils.evaluateExpressionAsString("border", this.border, this, pageContext));
        table.setBufferView(
                TagUtils.evaluateExpressionAsBoolean("bufferView", this.bufferView, this, pageContext));
        table.setCellpadding(
                TagUtils.evaluateExpressionAsString("cellpadding", this.cellpadding, this, pageContext));
        table.setCellspacing(
                TagUtils.evaluateExpressionAsString("cellspacing", this.cellspacing, this, pageContext));
        table.setFilterable(
                TagUtils.evaluateExpressionAsBoolean("filterable", this.filterable, this, pageContext));
        table.setFilterRowsCallback(TagUtils.evaluateExpressionAsString("filterRowsCallback",
                this.filterRowsCallback, this, pageContext));
        table.setForm(TagUtils.evaluateExpressionAsString("form", this.form, this, pageContext));
        table.setInterceptor(
                TagUtils.evaluateExpressionAsString("interceptor", this.interceptor, this, pageContext));
        table.setItems(TagUtils.evaluateExpressionAsObject("items", this.items, this, pageContext));
        table.setLocale(TagUtils.evaluateExpressionAsString("locale", this.locale, this, pageContext));
        table.setMethod(TagUtils.evaluateExpressionAsString("method", this.method, this, pageContext));
        table.setOnInvokeAction(
                TagUtils.evaluateExpressionAsString("onInvokeAction", this.onInvokeAction, this, pageContext));
        table.setRetrieveRowsCallback(TagUtils.evaluateExpressionAsString("retrieveRowsCallback",
                this.retrieveRowsCallback, this, pageContext));
        table.setRowsDisplayed(
                TagUtils.evaluateExpressionAsInt("rowsDisplayed", this.rowsDisplayed, this, pageContext));
        table.setScope(TagUtils.evaluateExpressionAsString("scope", scope, this, pageContext));
        table.setShowTitle(
                TagUtils.evaluateExpressionAsBoolean("showTitle", this.showTitle, this, pageContext));
        table.setShowTooltips(
                TagUtils.evaluateExpressionAsBoolean("showTooltips", this.showTooltips, this, pageContext));
        table.setSortRowsCallback(TagUtils.evaluateExpressionAsString("sortRowsCallback", this.sortRowsCallback,
                this, pageContext));
        table.setSortable(TagUtils.evaluateExpressionAsBoolean("sortable", this.sortable, this, pageContext));
        table.setState(TagUtils.evaluateExpressionAsString("state", this.state, this, pageContext));
        table.setStateAttr(TagUtils.evaluateExpressionAsString("stateAttr", this.stateAttr, this, pageContext));
        table.setStyle(TagUtils.evaluateExpressionAsString("style", style, this, pageContext));
        table.setStyleClass(
                TagUtils.evaluateExpressionAsString("styleClass", this.styleClass, this, pageContext));
        table.setTableId(TagUtils.evaluateExpressionAsString("tableId", getTableId(), this, pageContext));
        table.setTheme(TagUtils.evaluateExpressionAsString("theme", this.theme, this, pageContext));
        table.setTitle(TagUtils.evaluateExpressionAsString("title", this.title, this, pageContext));
        table.setVar(TagUtils.evaluateExpressionAsString("var", this.var, this, pageContext));

        table.setWidth(TagUtils.evaluateExpressionAsString("width", this.width, this, pageContext));

        table.setExcludeTool(
                TagUtils.evaluateExpressionAsString("excludeTool", this.excludeTool, this, pageContext));

        table.setOddRowBgColor(
                TagUtils.evaluateExpressionAsString("oddRowBgColor", this.oddRowBgColor, this, pageContext));
        table.setEvenRowBgColor(
                TagUtils.evaluateExpressionAsString("evenRowBgColor", this.evenRowBgColor, this, pageContext));

        table.setHeight(TagUtils.evaluateExpressionAsString("height", this.height, this, pageContext));
        if (StringUtils.isBlank(table.getHeight())) {
            table.setHeight(
                    TagUtils.evaluateExpressionAsString("listHeight", this.listHeight, this, pageContext));
        }
        table.setMinHeight(TagUtils.evaluateExpressionAsString("minHeight", this.minHeight, this, pageContext));

        table.setListWidth(TagUtils.evaluateExpressionAsString("listWidth", this.listWidth, this, pageContext));

        table.setScrollList(
                TagUtils.evaluateExpressionAsBoolean("scrollList", this.scrollList, this, pageContext));

        table.setResizeColWidth(
                TagUtils.evaluateExpressionAsBoolean("resizeColWidth", this.resizeColWidth, this, pageContext));
        table.setMinColWidth(
                TagUtils.evaluateExpressionAsInt("minColWidth", this.minColWidth, this, pageContext));

        table.setNearPageNum(
                TagUtils.evaluateExpressionAsString("nearPageNum", this.nearPageNum, this, pageContext));
        table.setMaxRowsExported(TagUtils.evaluateExpressionAsString("maxRowsExported", this.maxRowsExported,
                this, pageContext));

        table.setToolbarContent(
                TagUtils.evaluateExpressionAsString("toolbarContent", this.toolbarContent, this, pageContext));
        table.setToolbarLocation(TagUtils.evaluateExpressionAsString("toolbarLocation", this.toolbarLocation,
                this, pageContext));
        table.setAlwaysShowExtend(TagUtils.evaluateExpressionAsString("alwaysShowExtend", this.alwaysShowExtend,
                this, pageContext));

        table.setTagAttributes(TagUtils.evaluateExpressionAsString(TableConstants.TAG_ATTRIBUTES,
                this.tagAttributes, this, pageContext));

        table.setIncludeParameters(TagUtils.evaluateExpressionAsString("includeParameters",
                this.includeParameters, this, pageContext));
        table.setExcludeParameters(TagUtils.evaluateExpressionAsString("excludeParameters",
                this.excludeParameters, this, pageContext));

        table.setShowHeader(
                TagUtils.evaluateExpressionAsBoolean("showHeader", this.showHeader, this, pageContext));
        table.setPageSizeList(
                TagUtils.evaluateExpressionAsString("pageSizeList", this.pageSizeList, this, pageContext));

        table.setMinWidth(TagUtils.evaluateExpressionAsString("minWidth", this.minWidth, this, pageContext));

        table.setEditable(TagUtils.evaluateExpressionAsBoolean("editable", this.editable, this, pageContext));
        if (StringUtils.isBlank(table.getAction())) {
            table.setAction(((HttpServletRequest) pageContext.getRequest()).getRequestURL().toString());
        }

        table.setAttribute(TableConstants.XLS_FILE, TagUtils.evaluateExpressionAsString(TableConstants.XLS_FILE,
                this.xlsFileName, this, pageContext));

        table.setAttribute(TableConstants.CSV_FILE, TagUtils.evaluateExpressionAsString(TableConstants.CSV_FILE,
                this.csvFileName, this, pageContext));

        table.setAttribute(TableConstants.PDF_FILE, TagUtils.evaluateExpressionAsString(TableConstants.PDF_FILE,
                this.pdfFileName, this, pageContext));

        table.setAttribute(TableConstants.SHOW_PRINT, TagUtils
                .evaluateExpressionAsString(TableConstants.SHOW_PRINT, this.showPrint, this, pageContext));

        exportsMaker(model, table);

        // }

        addTableAttributes(model, table);

        model.addTable(table);

        Object tempQueryResult = pageContext.findAttribute(String.valueOf(table.getItems()));
        if (tempQueryResult instanceof QueryResult) {
            queryResult = (QueryResult) tempQueryResult;
        } else {
            queryResult = null;
            tempQueryResult = null;
        }
        table.beforeBody();
    } catch (Exception e) {
        throw new JspException("TableTag.doStartTag() Problem: " + ExceptionUtils.formatStackTrace(e));
    }

    return EVAL_BODY_INCLUDE;
}

From source file:org.springmodules.validation.commons.taglib.JavascriptValidatorTag.java

/**
 * Render the JavaScript for to perform validations based on the form name.
 *
 * @throws javax.servlet.jsp.JspException if a JSP exception has occurred
 *///w w  w. j  a v  a 2  s. c om
public int doStartTag() throws JspException {
    StringBuffer results = new StringBuffer();

    Locale locale = RequestContextUtils.getLocale((HttpServletRequest) pageContext.getRequest());

    ValidatorResources resources = getValidatorResources();

    Form form = resources.getForm(locale, formName);
    if (form != null) {
        if ("true".equalsIgnoreCase(dynamicJavascript)) {
            MessageSource messages = getMessageSource();

            List lActions = new ArrayList();
            List lActionMethods = new ArrayList();

            // Get List of actions for this Form
            for (Iterator i = form.getFields().iterator(); i.hasNext();) {
                Field field = (Field) i.next();

                for (Iterator x = field.getDependencyList().iterator(); x.hasNext();) {
                    Object o = x.next();

                    if (o != null && !lActionMethods.contains(o)) {
                        lActionMethods.add(o);
                    }
                }
            }

            // Create list of ValidatorActions based on lActionMethods
            for (Iterator i = lActionMethods.iterator(); i.hasNext();) {
                String depends = (String) i.next();
                ValidatorAction va = resources.getValidatorAction(depends);

                // throw nicer NPE for easier debugging
                if (va == null) {
                    throw new NullPointerException(
                            "Depends string \"" + depends + "\" was not found in validator-rules.xml.");
                }

                String javascript = va.getJavascript();
                if (javascript != null && javascript.length() > 0) {
                    lActions.add(va);
                } else {
                    i.remove();
                }
            }

            Collections.sort(lActions, new Comparator() {
                public int compare(Object o1, Object o2) {
                    ValidatorAction va1 = (ValidatorAction) o1;
                    ValidatorAction va2 = (ValidatorAction) o2;

                    if ((va1.getDepends() == null || va1.getDepends().length() == 0)
                            && (va2.getDepends() == null || va2.getDepends().length() == 0)) {
                        return 0;
                    } else if ((va1.getDepends() != null && va1.getDepends().length() > 0)
                            && (va2.getDepends() == null || va2.getDepends().length() == 0)) {
                        return 1;
                    } else if ((va1.getDepends() == null || va1.getDepends().length() == 0)
                            && (va2.getDepends() != null && va2.getDepends().length() > 0)) {
                        return -1;
                    } else {
                        return va1.getDependencyList().size() - va2.getDependencyList().size();
                    }
                }
            });

            String methods = null;
            for (Iterator i = lActions.iterator(); i.hasNext();) {
                ValidatorAction va = (ValidatorAction) i.next();

                if (methods == null) {
                    methods = va.getMethod() + "(form)";
                } else {
                    methods += " && " + va.getMethod() + "(form)";
                }
            }

            results.append(getJavascriptBegin(methods));

            for (Iterator i = lActions.iterator(); i.hasNext();) {
                ValidatorAction va = (ValidatorAction) i.next();
                String jscriptVar = null;
                String functionName = null;

                if (va.getJsFunctionName() != null && va.getJsFunctionName().length() > 0) {
                    functionName = va.getJsFunctionName();
                } else {
                    functionName = va.getName();
                }

                results.append("    function " + functionName + " () { \n");
                for (Iterator x = form.getFields().iterator(); x.hasNext();) {
                    Field field = (Field) x.next();

                    // Skip indexed fields for now until there is a good way to handle
                    // error messages (and the length of the list (could retrieve from scope?))
                    if (field.isIndexed() || field.getPage() != page || !field.isDependency(va.getName())) {

                        continue;
                    }

                    String message = MessageUtils.getMessage(messages, locale, va, field);

                    message = (message != null) ? message : "";

                    jscriptVar = this.getNextVar(jscriptVar);

                    results.append("     this." + jscriptVar + " = new Array(\"" + field.getKey() + "\", \""
                            + message + "\", ");

                    results.append("new Function (\"varName\", \"");

                    Map vars = field.getVars();
                    // Loop through the field's variables.
                    Iterator varsIterator = vars.keySet().iterator();
                    while (varsIterator.hasNext()) {
                        String varName = (String) varsIterator.next();
                        Var var = (Var) vars.get(varName);
                        String varValue = var.getValue();
                        String jsType = var.getJsType();

                        // skip requiredif variables field, fieldIndexed, fieldTest, fieldValue
                        if (varName.startsWith("field")) {
                            continue;
                        }

                        if (Var.JSTYPE_INT.equalsIgnoreCase(jsType)) {
                            results.append("this." + varName + "="
                                    + ValidatorUtils.replace(varValue, "\\", "\\\\") + "; ");
                        } else if (Var.JSTYPE_REGEXP.equalsIgnoreCase(jsType)) {
                            results.append("this." + varName + "=/"
                                    + ValidatorUtils.replace(varValue, "\\", "\\\\") + "/; ");
                        } else if (Var.JSTYPE_STRING.equalsIgnoreCase(jsType)) {
                            results.append("this." + varName + "='"
                                    + ValidatorUtils.replace(varValue, "\\", "\\\\") + "'; ");
                            // So everyone using the latest format doesn't need to change their xml files immediately.
                        } else if ("mask".equalsIgnoreCase(varName)) {
                            results.append("this." + varName + "=/"
                                    + ValidatorUtils.replace(varValue, "\\", "\\\\") + "/; ");
                        } else {
                            results.append("this." + varName + "='"
                                    + ValidatorUtils.replace(varValue, "\\", "\\\\") + "'; ");
                        }
                    }

                    results.append(" return this[varName];\"));\n");
                }
                results.append("    } \n\n");
            }
        } else if ("true".equalsIgnoreCase(staticJavascript)) {
            results.append(this.getStartElement());
            if ("true".equalsIgnoreCase(htmlComment)) {
                results.append(htmlBeginComment);
            }
        }
    }

    if ("true".equalsIgnoreCase(staticJavascript)) {
        results.append(getJavascriptStaticMethods(resources));
    }

    if (form != null
            && ("true".equalsIgnoreCase(dynamicJavascript) || "true".equalsIgnoreCase(staticJavascript))) {

        results.append(getJavascriptEnd());
    }

    JspWriter writer = pageContext.getOut();
    try {
        writer.print(results.toString());
    } catch (IOException e) {
        throw new JspException(e.getMessage());
    }

    return (SKIP_BODY);

}

From source file:com.glaf.core.tag.TagUtils.java

/**
 * Returns the appropriate MessageResources object for the current module
 * and the given bundle./*  ww  w . j a  va 2s. c om*/
 * 
 * @param pageContext
 *            Search the context's scopes for the resources.
 * @param bundle
 *            The bundle name to look for. If this is <code>null</code>, the
 *            default bundle name is used.
 * @param checkPageScope
 *            Whether to check page scope
 * @return MessageResources The bundle's resources stored in some scope.
 * @throws JspException
 *             if the MessageResources object could not be found.
 */
public MessageResources retrieveMessageResources(PageContext pageContext, String bundle, boolean checkPageScope)
        throws JspException {
    MessageResources resources = null;

    if (bundle == null) {
        bundle = conf.get("i18n.messages_key");
    }

    if (bundle == null) {
        bundle = Globals.MESSAGES_KEY;
    }

    if (checkPageScope) {
        resources = (MessageResources) pageContext.getAttribute(bundle, PageContext.PAGE_SCOPE);
    }

    if (resources == null) {
        resources = (MessageResources) pageContext.getAttribute(bundle, PageContext.REQUEST_SCOPE);
    }

    if (resources == null) {
        resources = (MessageResources) pageContext.getAttribute(bundle, PageContext.APPLICATION_SCOPE);
    }

    if (resources == null) {
        resources = (MessageResources) pageContext.getAttribute(Globals.DEFAULT_RESOURCE_NAME,
                PageContext.APPLICATION_SCOPE);
        if (resources == null) {
            resources = PropertyMessageResourcesFactory.createFactory()
                    .createResources(Globals.DEFAULT_RESOURCE_NAME);
            pageContext.setAttribute(Globals.DEFAULT_RESOURCE_NAME, resources, PageContext.APPLICATION_SCOPE);
        }
    }

    if (resources == null) {
        JspException e = new JspException(messages.getMessage("message.bundle", bundle));

        saveException(pageContext, e);
        throw e;
    }

    return resources;
}

From source file:com.ultrapower.eoms.common.plugin.ecside.tag.ColumnTag.java

    @Override
   public int doEndTag() throws JspException {
       //from  ww w.  j a v  a 2 s . co  m
        boolean isExported = ExportFilterUtils.isExported( model.getContext());
      boolean isPrint="_print_".equals(ExportFilterUtils.getExportFileName( model.getContext()));

      Column column=null;
        try {
            if (!TagUtils.isIteratingBody(this)) {
               column = new Column(model);
               
                
                
                column.setAlias(TagUtils.evaluateExpressionAsString("alias", this.alias, this, pageContext));
                column.setProperty(TagUtils.evaluateExpressionAsString("property", this.property, this, pageContext) );
                
                column.setCalc(TagUtils.evaluateExpressionAsString("calc", this.calc, this, pageContext));
                column.setCalcTitle(TagUtils.evaluateExpressionAsString("calcTitle", calcTitle, this, pageContext));
                column.setCell(TagUtils.evaluateExpressionAsString("cell", this.cell, this, pageContext));
                column.setEscapeAutoFormat(TagUtils.evaluateExpressionAsBoolean("escapeAutoFormat", this.escapeAutoFormat, this, pageContext));
                column.setFormat(TagUtils.evaluateExpressionAsString("format", this.format, this, pageContext));
                column.setInterceptor(TagUtils.evaluateExpressionAsString("interceptor", this.interceptor, this, pageContext));
                column.setParse(TagUtils.evaluateExpressionAsString("parse", this.parse, this, pageContext));
                column.setTitle(TagUtils.evaluateExpressionAsString("title", this.title, this, pageContext));
                
                
                

                //TODO:
                TagUtils.initExpression("cellValue",ECSideUtils.convertString(getColumnValue(),null), column);
                
                column.setStyle(TagUtils.evaluateExpressionAsString("style", this.style, this, pageContext));
                TagUtils.initExpression("style",column.getStyle(), column);
                
                
                column.setViewsAllowed(TagUtils.evaluateExpressionAsString("viewsToAllow", this.viewsAllowed, this, pageContext));
                column.setViewsDenied(TagUtils.evaluateExpressionAsString("viewsToDeny", this.viewsDenied, this, pageContext));

                
                column.setFilterable(TagUtils.evaluateExpressionAsBoolean("filterable", this.filterable, this, pageContext));
                column.setFilterCell(TagUtils.evaluateExpressionAsString("filterCell", this.filterCell, this, pageContext));
                column.setFilterClass(TagUtils.evaluateExpressionAsString("filterClass", this.filterClass, this, pageContext));
                column.setFilterOptions(TagUtils.evaluateExpressionAsObject("filterOptions", this.filterOptions, this, pageContext));
                column.setFilterStyle(TagUtils.evaluateExpressionAsString("filterStyle", this.filterStyle, this, pageContext));

                column.setHeaderCell(TagUtils.evaluateExpressionAsString("headerCell", this.headerCell, this, pageContext));
                column.setHeaderClass(TagUtils.evaluateExpressionAsString("headerClass", this.headerClass, this, pageContext));
                column.setHeaderStyle(TagUtils.evaluateExpressionAsString("headerStyle", this.headerStyle, this, pageContext));
                column.setHeaderStyleClass(TagUtils.evaluateExpressionAsString("headerStyleClass", this.headerStyleClass, this, pageContext));
                column.setSortable(TagUtils.evaluateExpressionAsBoolean("sortable", this.sortable, this, pageContext));
                column.setEditable(TagUtils.evaluateExpressionAsBoolean("editable", this.editable, this, pageContext));
                
                
                String widthT=TagUtils.evaluateExpressionAsString("width", this.width, this, pageContext);
                
               
                
                if (!model.getTable().isClassic()) {
                   int tempWidth=0;
                   if (StringUtils.isBlank(widthT)){
                      widthT=""+ECSideConstants.DEFAULT_COLUMNWIDTH;
                      //widthT="";
                      tempWidth=ECSideConstants.DEFAULT_COLUMNWIDTH;
                   }else{
                      try{
                         if (widthT.indexOf("%")>0){
                            tempWidth=ECSideConstants.DEFAULT_COLUMNWIDTH;
                         }else if(widthT.toLowerCase().endsWith("px")){
                            tempWidth=Integer.parseInt(widthT.substring(0,widthT.length()-2));
                         }else{
                            tempWidth=Integer.parseInt(widthT);
                         }
                      }catch(Exception e){
                         tempWidth=ECSideConstants.DEFAULT_COLUMNWIDTH;
                      }
                      
                   }
                   model.getTable().addTotalWidth(tempWidth);
                }
                
                column.setWidth(widthT);
                column.setEllipsis(TagUtils.evaluateExpressionAsBoolean("ellipsis", this.ellipsis, this, pageContext));
                
                column.setResizeColWidth(TagUtils.evaluateExpressionAsBoolean("resizeColWidth", this.resizeColWidth, this, pageContext));
                column.setMinWidth(TagUtils.evaluateExpressionAsInt("minWidth", this.minWidth, this, pageContext));
                
                
                column.setEditEvent(TagUtils.evaluateExpressionAsString("editEvent", this.editEvent, this, pageContext));
                column.setEditTemplate(TagUtils.evaluateExpressionAsString("editTemplate", this.editTemplate, this, pageContext));
//                column.setCellName(TagUtils.evaluateExpressionAsString("cellName", this.cellName, this, pageContext));

                column.setNowrap(TagUtils.evaluateExpressionAsString("nowrap", this.nowrap, this, pageContext));

                column.setGroup(TagUtils.evaluateExpressionAsString("group", this.group, this, pageContext));
                
                
                
                
                if (StringUtils.isBlank(this.headerSpan)){
                   column.setHeaderSpan(-1);
                }else{
                   column.setHeaderSpan(TagUtils.evaluateExpressionAsInt("headerSpan", this.headerSpan, this, pageContext));
                }
                
                if (StringUtils.isNotBlank(this.calcSpan)){
                   Column fcolumn;
                   List columns=TagUtils.getModel(this).getColumnHandler().getColumns();
                   if (columns==null || columns.size()<1 || columns.get(0)==null){
                      fcolumn=column;
                   }else{
                      fcolumn=(Column)columns.get(0);
                   }

                   fcolumn.setCalcSpan(TagUtils.evaluateExpressionAsInt("calcSpan", this.calcSpan, this, pageContext));
                }
                
                column.setTagAttributes(TagUtils.evaluateExpressionAsString(TableConstants.TAG_ATTRIBUTES, this.tagAttributes, this, pageContext));
                
//               column.setAttribute(TDTableConstants.EXTEND_ATTRIBUTES,getExtendAttributesAsString());
//               resetExtendAttribute();
               
                
                addColumnAttributes(model, column);
                model.getColumnHandler().addColumn(column);
                
            } else {

                column = model.getColumnHandler().getColumnByAlias(TableModelUtils.getAlias(alias, property));
                
                if (column != null) { // null if view not allowed
                    Object currentBean = TagUtils.getModel(this).getCurrentRowBean();
//                    Object previousBean = TagUtils.getModel(this).getPreviousRowBean();
                   
                    
                    Object propertyValue = TableModelUtils.getColumnPropertyValue(currentBean, property);
                    Object cellValue;
                    
//                    column.setCellValue(TagUtils.evaluateExpressionAsString("cellValue", this.cellValue, this, pageContext));

                    
                    column.setCellValue(TagUtils.evaluateExpressionAsString("cellValue", this.cellValue, this, pageContext));
                    
                    
                    cellValue=TagUtils.runExpression("cellValue",column,currentBean);
                    
//                    column.setCellValue(propertyValue==null?null:String.valueOf(propertyValue));
                    

                    
                    if (cellValue==null){
                       cellValue=getColumnValue(propertyValue);
                    }
                   if (propertyValue==null){
                      propertyValue=cellValue;
                   }
                   
//                    Object[] expressionPropertys=column.getExpressionPropertys("cellValue");
//                    if (expressionPropertys!=null){
//                       GirdExpression expression=column.getExpression("cellValue");
//                       for (int i=0;i<expressionPropertys.length;i++){
//                          String ep=(String)expressionPropertys[i];
//                          expression.setArgument(ep, TableModelUtils.getColumnPropertyValue(currentBean, ep));
//                       }
//                       cellValue=expression.call();
//                       if (propertyValue==null){
//                          propertyValue=cellValue;
//                       }
//                    }else{
//                       cellValue=getColumnValue(propertyValue);
//                    }
                    
                    column.setTipTitle(TagUtils.evaluateExpressionAsString("tipTitle", this.tipTitle, this, pageContext));
                    
                    Object preCellValue=column.getPreCellValue();
//                    if (previousBean!=null){
//                       prePropertyValue=TableModelUtils.getColumnPropertyValue(previousBean, property);
//                       
//                        if ("hide".equalsIgnoreCase(column.getGroup())){
//                           if (propertyValue!=null && propertyValue.equals(prePropertyValue)){
//                              cellValue="";
//                           }
//                        }
//                    }
                    
                    boolean hideCell=false;
                    boolean isGroup=false;
                   if ("true".equalsIgnoreCase(column.getGroup())){
                     isGroup=true;
                   }
                   

                   if (isGroup){
                   column.setPreCellValue(cellValue);
                      if (cellValue!=null && cellValue.equals(preCellValue)){
                      cellValue="";
                      column.setStyle("display:none;");
                      hideCell=true;
//                      column.setStyle(column.getStyle()+";display:none;");
                   }

                }
                   
                    column.setValue(cellValue);
                    column.setPropertyValue(propertyValue);
                    
                  if (!hideCell){
                    column.setOnclick(TagUtils.evaluateExpressionAsString(TableConstants.ON_CLICK, this.onclick, this, pageContext));
                    column.setOndblclick(TagUtils.evaluateExpressionAsString(TableConstants.ON_DOUBLE_CLICK, this.ondblclick, this, pageContext));
                    
                    column.setOnmouseover(TagUtils.evaluateExpressionAsString(TableConstants.ON_MOUSE_OVER, this.onmouseover, this, pageContext));
                    column.setOnmouseout(TagUtils.evaluateExpressionAsString(TableConstants.ON_MOUSE_OUT, this.onmouseout, this, pageContext));
      
                    String styleClassName=TagUtils.evaluateExpressionAsString("styleClass", this.styleClass, this, pageContext);
                    if (isGroup){
                       styleClassName= "groupColumn " +ECSideUtils.convertString(styleClassName, "");
                    }
                   
                    column.setStyleClass(styleClassName);
                    
                    String style=ECSideUtils.convertString(TagUtils.runExpression("style",column,currentBean),null);
                    if (style==null) {
                       column.setStyle(TagUtils.evaluateExpressionAsString("style", this.style, this, pageContext));
                    }else{
                       column.setStyle(style);
                    }

                  
                  }
//                column.setCellValue(TagUtils.evaluateExpressionAsString("cellValue", this.cellValue, this, pageContext));
                column.setTagAttributes(TagUtils.evaluateExpressionAsString(TableConstants.TAG_ATTRIBUTES, this.tagAttributes, this, pageContext));
                column.setId(TagUtils.evaluateExpressionAsString("columnId", columnId, this, pageContext));
                    
                   
                    modifyColumnAttributes(model, column);
                    model.getColumnHandler().modifyColumnAttributes(column);
                    model.getViewHandler().addColumnValueToView(column);
//                    model.setPreviousRowBean(currentBean);

                }
//               
                

            }

            if (bodyContent != null) {
                bodyContent.clearBody();
            }
//            column.setAttribute(TDTableConstants.EXTEND_ATTRIBUTES,"");
        } catch (Exception e) {
            throw new JspException("ColumnTag.doEndTag() Problem: " + ExceptionUtils.formatStackTrace(e));
        }finally{
           doFinally();
        }
        return EVAL_PAGE;
    }

From source file:com.googlecode.jtiger.modules.ecside.tag.ColumnTag.java

public int doEndTag() throws JspException {

    // boolean isExported = ExportFilterUtils.isExported(
    // model.getContext());
    // boolean isPrint="_print_".equals(ExportFilterUtils.getExportFileName(
    // model.getContext()));

    Column column = null;/*from w  w w .  java2s  .com*/
    try {
        if (!TagUtils.isIteratingBody(this)) {
            column = new Column(model);

            column.setAlias(TagUtils.evaluateExpressionAsString("alias", this.alias, this, pageContext));
            column.setProperty(
                    TagUtils.evaluateExpressionAsString("property", this.property, this, pageContext));

            column.setCalc(TagUtils.evaluateExpressionAsString("calc", this.calc, this, pageContext));
            column.setCalcTitle(TagUtils.evaluateExpressionAsString("calcTitle", calcTitle, this, pageContext));
            column.setCell(TagUtils.evaluateExpressionAsString("cell", this.cell, this, pageContext));
            column.setEscapeAutoFormat(TagUtils.evaluateExpressionAsBoolean("escapeAutoFormat",
                    this.escapeAutoFormat, this, pageContext));
            column.setFormat(TagUtils.evaluateExpressionAsString("format", this.format, this, pageContext));
            column.setInterceptor(
                    TagUtils.evaluateExpressionAsString("interceptor", this.interceptor, this, pageContext));
            column.setParse(TagUtils.evaluateExpressionAsString("parse", this.parse, this, pageContext));
            column.setTitle(TagUtils.evaluateExpressionAsString("title", this.title, this, pageContext));

            // TODO:
            TagUtils.initExpression("cellValue", ECSideUtils.convertString(getColumnValue(), null), column);

            column.setStyle(TagUtils.evaluateExpressionAsString("style", this.style, this, pageContext));
            TagUtils.initExpression("style", column.getStyle(), column);

            column.setViewsAllowed(
                    TagUtils.evaluateExpressionAsString("viewsToAllow", this.viewsAllowed, this, pageContext));
            column.setViewsDenied(
                    TagUtils.evaluateExpressionAsString("viewsToDeny", this.viewsDenied, this, pageContext));

            column.setFilterable(
                    TagUtils.evaluateExpressionAsBoolean("filterable", this.filterable, this, pageContext));
            column.setFilterCell(
                    TagUtils.evaluateExpressionAsString("filterCell", this.filterCell, this, pageContext));
            column.setFilterClass(
                    TagUtils.evaluateExpressionAsString("filterClass", this.filterClass, this, pageContext));
            column.setFilterOptions(TagUtils.evaluateExpressionAsObject("filterOptions", this.filterOptions,
                    this, pageContext));
            column.setFilterStyle(
                    TagUtils.evaluateExpressionAsString("filterStyle", this.filterStyle, this, pageContext));

            column.setHeaderCell(
                    TagUtils.evaluateExpressionAsString("headerCell", this.headerCell, this, pageContext));
            column.setHeaderClass(
                    TagUtils.evaluateExpressionAsString("headerClass", this.headerClass, this, pageContext));
            column.setHeaderStyle(
                    TagUtils.evaluateExpressionAsString("headerStyle", this.headerStyle, this, pageContext));
            column.setHeaderStyleClass(TagUtils.evaluateExpressionAsString("headerStyleClass",
                    this.headerStyleClass, this, pageContext));
            column.setSortable(
                    TagUtils.evaluateExpressionAsBoolean("sortable", this.sortable, this, pageContext));
            column.setEditable(
                    TagUtils.evaluateExpressionAsBoolean("editable", this.editable, this, pageContext));

            String widthT = TagUtils.evaluateExpressionAsString("width", this.width, this, pageContext);

            if (!model.getTable().isClassic()) {
                int tempWidth = 0;
                if (StringUtils.isBlank(widthT)) {
                    widthT = "" + ECSideConstants.DEFAULT_COLUMNWIDTH;
                    // widthT="";
                    tempWidth = ECSideConstants.DEFAULT_COLUMNWIDTH;
                } else {
                    try {
                        if (widthT.indexOf("%") > 0) {
                            tempWidth = ECSideConstants.DEFAULT_COLUMNWIDTH;
                        } else if (widthT.toLowerCase().endsWith("px")) {
                            tempWidth = Integer.parseInt(widthT.substring(0, widthT.length() - 2));
                        } else {
                            tempWidth = Integer.parseInt(widthT);
                        }
                    } catch (Exception e) {
                        tempWidth = ECSideConstants.DEFAULT_COLUMNWIDTH;
                    }

                }
                model.getTable().addTotalWidth(tempWidth);
            }

            column.setWidth(widthT);
            column.setEllipsis(
                    TagUtils.evaluateExpressionAsBoolean("ellipsis", this.ellipsis, this, pageContext));

            column.setResizeColWidth(TagUtils.evaluateExpressionAsBoolean("resizeColWidth", this.resizeColWidth,
                    this, pageContext));
            column.setMinWidth(TagUtils.evaluateExpressionAsInt("minWidth", this.minWidth, this, pageContext));

            column.setEditEvent(
                    TagUtils.evaluateExpressionAsString("editEvent", this.editEvent, this, pageContext));
            column.setEditTemplate(
                    TagUtils.evaluateExpressionAsString("editTemplate", this.editTemplate, this, pageContext));
            // column.setCellName(TagUtils.evaluateExpressionAsString("cellName",
            // this.cellName, this, pageContext));

            column.setNowrap(TagUtils.evaluateExpressionAsString("nowrap", this.nowrap, this, pageContext));

            column.setGroup(TagUtils.evaluateExpressionAsString("group", this.group, this, pageContext));

            if (StringUtils.isBlank(this.headerSpan)) {
                column.setHeaderSpan(-1);
            } else {
                column.setHeaderSpan(
                        TagUtils.evaluateExpressionAsInt("headerSpan", this.headerSpan, this, pageContext));
            }

            if (StringUtils.isNotBlank(this.calcSpan)) {
                Column fcolumn;
                List columns = TagUtils.getModel(this).getColumnHandler().getColumns();
                if (columns == null || columns.size() < 1 || columns.get(0) == null) {
                    fcolumn = column;
                } else {
                    fcolumn = (Column) columns.get(0);
                }

                fcolumn.setCalcSpan(
                        TagUtils.evaluateExpressionAsInt("calcSpan", this.calcSpan, this, pageContext));
            }

            column.setTagAttributes(TagUtils.evaluateExpressionAsString(TableConstants.TAG_ATTRIBUTES,
                    this.tagAttributes, this, pageContext));

            // column.setAttribute(TDTableConstants.EXTEND_ATTRIBUTES,getExtendAttributesAsString());
            // resetExtendAttribute();

            addColumnAttributes(model, column);
            model.getColumnHandler().addColumn(column);

        } else {

            column = model.getColumnHandler().getColumnByAlias(TableModelUtils.getAlias(alias, property));

            if (column != null) { // null if view not allowed
                Object currentBean = TagUtils.getModel(this).getCurrentRowBean();
                // Object previousBean =
                // TagUtils.getModel(this).getPreviousRowBean();

                Object propertyValue = TableModelUtils.getColumnPropertyValue(currentBean, property);
                Object cellValue;

                // column.setCellValue(TagUtils.evaluateExpressionAsString("cellValue",
                // this.cellValue, this, pageContext));

                column.setCellValue(
                        TagUtils.evaluateExpressionAsString("cellValue", this.cellValue, this, pageContext));

                cellValue = TagUtils.runExpression("cellValue", column, currentBean);

                // column.setCellValue(propertyValue==null?null:String.valueOf(propertyValue));

                if (cellValue == null) {
                    cellValue = getColumnValue(propertyValue);
                }
                if (propertyValue == null) {
                    propertyValue = cellValue;
                }

                // Object[]
                // expressionPropertys=column.getExpressionPropertys("cellValue");
                // if (expressionPropertys!=null){
                // GirdExpression
                // expression=column.getExpression("cellValue");
                // for (int i=0;i<expressionPropertys.length;i++){
                // String ep=(String)expressionPropertys[i];
                // expression.setArgument(ep,
                // TableModelUtils.getColumnPropertyValue(currentBean, ep));
                // }
                // cellValue=expression.call();
                // if (propertyValue==null){
                // propertyValue=cellValue;
                // }
                // }else{
                // cellValue=getColumnValue(propertyValue);
                // }

                column.setTipTitle(
                        TagUtils.evaluateExpressionAsString("tipTitle", this.tipTitle, this, pageContext));

                Object preCellValue = column.getPreCellValue();
                // if (previousBean!=null){
                // prePropertyValue=TableModelUtils.getColumnPropertyValue(previousBean,
                // property);
                //                       
                // if ("hide".equalsIgnoreCase(column.getGroup())){
                // if (propertyValue!=null &&
                // propertyValue.equals(prePropertyValue)){
                // cellValue="";
                // }
                // }
                // }

                boolean hideCell = false;
                boolean isGroup = false;
                if ("true".equalsIgnoreCase(column.getGroup())) {
                    isGroup = true;
                }

                if (isGroup) {
                    column.setPreCellValue(cellValue);
                    if (cellValue != null && cellValue.equals(preCellValue)) {
                        cellValue = "";
                        column.setStyle("display:none;");
                        hideCell = true;
                        // column.setStyle(column.getStyle()+";display:none;");
                    }

                }

                column.setValue(cellValue);
                column.setPropertyValue(propertyValue);

                if (!hideCell) {
                    column.setOnclick(TagUtils.evaluateExpressionAsString(TableConstants.ON_CLICK, this.onclick,
                            this, pageContext));
                    column.setOndblclick(TagUtils.evaluateExpressionAsString(TableConstants.ON_DOUBLE_CLICK,
                            this.ondblclick, this, pageContext));

                    column.setOnmouseover(TagUtils.evaluateExpressionAsString(TableConstants.ON_MOUSE_OVER,
                            this.onmouseover, this, pageContext));
                    column.setOnmouseout(TagUtils.evaluateExpressionAsString(TableConstants.ON_MOUSE_OUT,
                            this.onmouseout, this, pageContext));

                    String styleClassName = TagUtils.evaluateExpressionAsString("styleClass", this.styleClass,
                            this, pageContext);
                    if (isGroup) {
                        styleClassName = "groupColumn " + ECSideUtils.convertString(styleClassName, "");
                    }

                    column.setStyleClass(styleClassName);

                    String style = ECSideUtils
                            .convertString(TagUtils.runExpression("style", column, currentBean), null);
                    if (style == null) {
                        column.setStyle(
                                TagUtils.evaluateExpressionAsString("style", this.style, this, pageContext));
                    } else {
                        column.setStyle(style);
                    }

                }
                // column.setCellValue(TagUtils.evaluateExpressionAsString("cellValue",
                // this.cellValue, this, pageContext));
                column.setTagAttributes(TagUtils.evaluateExpressionAsString(TableConstants.TAG_ATTRIBUTES,
                        this.tagAttributes, this, pageContext));
                column.setId(TagUtils.evaluateExpressionAsString("columnId", columnId, this, pageContext));

                modifyColumnAttributes(model, column);
                model.getColumnHandler().modifyColumnAttributes(column);
                model.getViewHandler().addColumnValueToView(column);
                // model.setPreviousRowBean(currentBean);

            }
            //               

        }

        if (bodyContent != null) {
            bodyContent.clearBody();
        }
        // column.setAttribute(TDTableConstants.EXTEND_ATTRIBUTES,"");
    } catch (Exception e) {
        throw new JspException("ColumnTag.doEndTag() Problem: " + ExceptionUtils.formatStackTrace(e));
    } finally {
        doFinally();
    }
    return EVAL_PAGE;
}

From source file:com.ultrapower.eoms.common.plugin.ecside.tag.TableTag.java

    @Override
   public int doStartTag() throws JspException {
        try {/* ww w  .  j  ava 2 s  .  c om*/
            // initialize the attributes
            iterator = null;
            pageContext.setAttribute(TableConstants.ROWCOUNT, "0");
//          pageContext.setAttribute(ECSideConstants.TABLEMODEL_KEY, model);
            
            // fire up the model with the context, preferences and messages
            model = new TableModelImpl(new JspPageContext(pageContext), TagUtils.evaluateExpressionAsString("locale", this.locale, this, pageContext));
           
            boolean isExported = ExportFilterUtils.isExported( model.getContext());
          boolean isPrint="_print_".equals(ExportFilterUtils.getExportFileName( model.getContext()));
          
            table = new Table(model);
            table.setView(TagUtils.evaluateExpressionAsString("view", this.view, this, pageContext));
            
            
//            if (!isExported || isPrint ) {
            // make the table
            table.setGenerateScript(TagUtils.evaluateExpressionAsBoolean("generateScript", this.generateScript, this, pageContext));
            table.setUseAjax(TagUtils.evaluateExpressionAsBoolean("useAjax", this.useAjax, this, pageContext));
            table.setDoPreload(TagUtils.evaluateExpressionAsBoolean("doPreload", this.doPreload, this, pageContext));
            table.setClassic(TagUtils.evaluateExpressionAsBoolean("classic", this.classic, this, pageContext));
            
            table.setAction(TagUtils.evaluateExpressionAsString("action", action, this, pageContext));
            table.setEnctype(TagUtils.evaluateExpressionAsString("enctype", enctype, this, pageContext));
            
            
            table.setInsertAction(TagUtils.evaluateExpressionAsString("insertAction", insertAction, this, pageContext));
            table.setUpdateAction(TagUtils.evaluateExpressionAsString("updateAction", updateAction, this, pageContext));
            table.setDeleteAction(TagUtils.evaluateExpressionAsString("deleteAction", deleteAction, this, pageContext));
            table.setShadowRowAction(TagUtils.evaluateExpressionAsString("shadowRowAction", shadowRowAction, this, pageContext));

            
            table.setBatchUpdate(TagUtils.evaluateExpressionAsBoolean("batchUpdate", this.batchUpdate, this, pageContext));
            table.setAutoIncludeParameters(TagUtils.evaluateExpressionAsBoolean("autoIncludeParameters", this.autoIncludeParameters, this, pageContext));
            table.setBorder(TagUtils.evaluateExpressionAsString("border", this.border, this, pageContext));
            table.setBufferView(TagUtils.evaluateExpressionAsBoolean("bufferView", this.bufferView, this, pageContext));
            table.setCellpadding(TagUtils.evaluateExpressionAsString("cellpadding", this.cellpadding, this, pageContext));
            table.setCellspacing(TagUtils.evaluateExpressionAsString("cellspacing", this.cellspacing, this, pageContext));
            table.setFilterable(TagUtils.evaluateExpressionAsBoolean("filterable", this.filterable, this, pageContext));
            table.setFilterRowsCallback(TagUtils.evaluateExpressionAsString("filterRowsCallback", this.filterRowsCallback, this, pageContext));
            table.setForm(TagUtils.evaluateExpressionAsString("form", this.form, this, pageContext));
            table.setInterceptor(TagUtils.evaluateExpressionAsString("interceptor", this.interceptor, this, pageContext));
            table.setItems(TagUtils.evaluateExpressionAsObject("items", this.items, this, pageContext));
            table.setLocale(TagUtils.evaluateExpressionAsString("locale", this.locale, this, pageContext));
            table.setMethod(TagUtils.evaluateExpressionAsString("method", this.method, this, pageContext));
            table.setOnInvokeAction(TagUtils.evaluateExpressionAsString("onInvokeAction", this.onInvokeAction, this, pageContext));
            table.setRetrieveRowsCallback(TagUtils.evaluateExpressionAsString("retrieveRowsCallback", this.retrieveRowsCallback, this, pageContext));
            table.setRowsDisplayed(TagUtils.evaluateExpressionAsInt("rowsDisplayed", this.rowsDisplayed, this, pageContext));
            table.setScope(TagUtils.evaluateExpressionAsString("scope", scope, this, pageContext));
            table.setShowTitle(TagUtils.evaluateExpressionAsBoolean("showTitle", this.showTitle, this, pageContext));
            table.setShowTooltips(TagUtils.evaluateExpressionAsBoolean("showTooltips", this.showTooltips, this, pageContext));
            table.setSortRowsCallback(TagUtils.evaluateExpressionAsString("sortRowsCallback", this.sortRowsCallback, this, pageContext));
            table.setSortable(TagUtils.evaluateExpressionAsBoolean("sortable", this.sortable, this, pageContext));
            table.setState(TagUtils.evaluateExpressionAsString("state", this.state, this, pageContext));
            table.setStateAttr(TagUtils.evaluateExpressionAsString("stateAttr", this.stateAttr, this, pageContext));
            table.setStyle(TagUtils.evaluateExpressionAsString("style", style, this, pageContext));
            table.setStyleClass(TagUtils.evaluateExpressionAsString("styleClass", this.styleClass, this, pageContext));
            table.setTableId(TagUtils.evaluateExpressionAsString("tableId", getTableId(), this, pageContext));
            table.setTheme(TagUtils.evaluateExpressionAsString("theme", this.theme, this, pageContext));
            table.setTitle(TagUtils.evaluateExpressionAsString("title", this.title, this, pageContext));
            table.setVar(TagUtils.evaluateExpressionAsString("var", this.var, this, pageContext));

            table.setWidth(TagUtils.evaluateExpressionAsString("width", this.width, this, pageContext));
           
            table.setExcludeTool(TagUtils.evaluateExpressionAsString("excludeTool", this.excludeTool, this, pageContext));

            
            
            table.setOddRowBgColor(TagUtils.evaluateExpressionAsString("oddRowBgColor", this.oddRowBgColor, this, pageContext));
            table.setEvenRowBgColor(TagUtils.evaluateExpressionAsString("evenRowBgColor", this.evenRowBgColor, this, pageContext));
           
            table.setHeight(TagUtils.evaluateExpressionAsString("height", this.height, this, pageContext));    
            if (StringUtils.isBlank( table.getHeight()) ){
                table.setHeight(TagUtils.evaluateExpressionAsString("listHeight", this.listHeight, this, pageContext));
            }
            table.setMinHeight(TagUtils.evaluateExpressionAsString("minHeight", this.minHeight, this, pageContext));
    
            table.setListWidth(TagUtils.evaluateExpressionAsString("listWidth", this.listWidth, this, pageContext));

            table.setScrollList(TagUtils.evaluateExpressionAsBoolean("scrollList", this.scrollList, this, pageContext));

            table.setResizeColWidth(TagUtils.evaluateExpressionAsBoolean("resizeColWidth", this.resizeColWidth, this, pageContext));
            table.setMinColWidth(TagUtils.evaluateExpressionAsInt("minColWidth", this.minColWidth, this, pageContext));
            
            table.setNearPageNum(TagUtils.evaluateExpressionAsString("nearPageNum", this.nearPageNum, this, pageContext));
            table.setMaxRowsExported(TagUtils.evaluateExpressionAsString("maxRowsExported", this.maxRowsExported, this, pageContext));
            
            table.setToolbarContent( TagUtils.evaluateExpressionAsString("toolbarContent", this.toolbarContent, this, pageContext) );
            table.setToolbarLocation( TagUtils.evaluateExpressionAsString("toolbarLocation", this.toolbarLocation, this, pageContext) );
            table.setAlwaysShowExtend(TagUtils.evaluateExpressionAsString("alwaysShowExtend", this.alwaysShowExtend, this, pageContext));
            
            table.setTagAttributes(TagUtils.evaluateExpressionAsString(TableConstants.TAG_ATTRIBUTES, this.tagAttributes, this, pageContext));
          
            
            table.setIncludeParameters(TagUtils.evaluateExpressionAsString("includeParameters",this.includeParameters,this,pageContext));
            table.setExcludeParameters(TagUtils.evaluateExpressionAsString("excludeParameters",this.excludeParameters,this,pageContext));
            
            table.setShowHeader(TagUtils.evaluateExpressionAsBoolean("showHeader",this.showHeader,this,pageContext));
            table.setPageSizeList(TagUtils.evaluateExpressionAsString("pageSizeList",this.pageSizeList,this,pageContext));
            
            table.setMinWidth(TagUtils.evaluateExpressionAsString("minWidth", this.minWidth, this, pageContext));
            
            table.setEditable(TagUtils.evaluateExpressionAsBoolean("editable", this.editable, this, pageContext));
          if ( StringUtils.isBlank(table.getAction()) ) {
             table.setAction(((HttpServletRequest)pageContext.getRequest()).getRequestURL().toString());
          }

          table.setAttribute(TableConstants.XLS_FILE, TagUtils
                .evaluateExpressionAsString(TableConstants.XLS_FILE,
                      this.xlsFileName, this, pageContext));

          table.setAttribute(TableConstants.CSV_FILE, TagUtils
                .evaluateExpressionAsString(TableConstants.CSV_FILE,
                      this.csvFileName, this, pageContext));

          table.setAttribute(TableConstants.PDF_FILE, TagUtils
                .evaluateExpressionAsString(TableConstants.PDF_FILE,
                      this.pdfFileName, this, pageContext));

          table.setAttribute(TableConstants.SHOW_PRINT, TagUtils
                .evaluateExpressionAsString(TableConstants.SHOW_PRINT,
                      this.showPrint, this, pageContext));

          exportsMaker(model,table);
          
//            }
           
            addTableAttributes(model, table);
            
            model.addTable(table);
            
            Object tempQueryResult=pageContext.findAttribute(String.valueOf(table.getItems()));
            if (tempQueryResult instanceof QueryResult){
               queryResult=(QueryResult)tempQueryResult;
            }else{
               queryResult=null;
               tempQueryResult=null;
            }
            table.beforeBody();
        } catch (Exception e) {
            throw new JspException("TableTag.doStartTag() Problem: " + ExceptionUtils.formatStackTrace(e));
        }

        return EVAL_BODY_INCLUDE;
    }