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.glaf.core.tag.TagUtils.java

/**
 * Write the specified text as the response to the writer associated with
 * this page. <strong>WARNING</strong> - If you are writing body content
 * from the <code>doAfterBody()</code> method of a custom tag class that
 * implements <code>BodyTag</code>, you should be calling
 * <code>writePrevious()</code> instead.
 * //from  w w  w .j a  v  a2  s .com
 * @param pageContext
 *            The PageContext object for this page
 * @param text
 *            The text to be written
 * @throws JspException
 *             if an input/output error occurs (already saved)
 */
public void write(PageContext pageContext, String text) throws JspException {
    JspWriter writer = pageContext.getOut();

    try {
        writer.print(text);
    } catch (IOException e) {
        saveException(pageContext, e);
        throw new JspException(messages.getMessage("write.io", e.toString()));
    }
}

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

/**
 * Write the specified text as the response to the writer associated with
 * the body content for the tag within which we are currently nested.
 * //from  ww  w.  j  ava  2  s  .  c  o  m
 * @param pageContext
 *            The PageContext object for this page
 * @param text
 *            The text to be written
 * @throws JspException
 *             if an input/output error occurs (already saved)
 */
public void writePrevious(PageContext pageContext, String text) throws JspException {
    JspWriter writer = pageContext.getOut();

    if (writer instanceof BodyContent) {
        writer = ((BodyContent) writer).getEnclosingWriter();
    }

    try {
        writer.print(text);
    } catch (IOException e) {
        saveException(pageContext, e);
        throw new JspException(messages.getMessage("write.io", e.toString()));
    }
}

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

/**
 * Renders the filter UI//from  ww w  . ja va2 s  . co  m
 * @param pageContext caller's page context
 * @param filter ListFilter instance
 * @param uniqueName name of the list
 * @param width width of the list
 * @param columnCount list's column count
 * @param searchParent true if list tag allows searching of parent
 * @param searchChild true if the list tag allows searching of child
 * @throws JspException if something bad happens writing to the page
 */
public static void renderFilterUI(PageContext pageContext, ListFilter filter, String uniqueName, String width,
        int columnCount, boolean searchParent, boolean searchChild) throws JspException {
    LocalizationService ls = LocalizationService.getInstance();
    HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
    String filterByKey = makeFilterByLabel(uniqueName);
    String filterBy = request.getParameter(filterByKey);
    String filterValueKey = makeFilterValueByLabel(uniqueName);
    String filterName = makeFilterNameByLabel(uniqueName);
    String filterValue = ListTagHelper.getFilterValue(pageContext.getRequest(), uniqueName);

    //We set this so we know next time around what the old filter value was
    ListTagUtil.write(pageContext, String.format(HIDDEN_TEXT, makeOldFilterValueByLabel(uniqueName),
            StringEscapeUtils.escapeHtml(filterValue)));

    List fields = filter.getFieldNames();
    if (fields == null || fields.size() == 0) {
        throw new JspException("ListFilter.getFieldNames() returned no field names");
    } else if (fields.size() == 1) {
        ListTagUtil.write(pageContext, "<input type=\"hidden\" name=\"");
        ListTagUtil.write(pageContext, filterByKey);
        ListTagUtil.write(pageContext, "\" value=\"");
        ListTagUtil.write(pageContext, fields.get(0).toString());
        ListTagUtil.write(pageContext, "\" />");
    } else {
        ListTagUtil.write(pageContext, ls.getMessage("message.filterby.multiple"));
        ListTagUtil.write(pageContext, "<select name=\"");
        ListTagUtil.write(pageContext, filterByKey);
        ListTagUtil.write(pageContext, "\">");
        for (Iterator iter = fields.iterator(); iter.hasNext();) {
            String field = (String) iter.next();
            ListTagUtil.write(pageContext, "<option value=\"");
            ListTagUtil.write(pageContext, field);
            ListTagUtil.write(pageContext, "\" ");
            if (field.equals(filterBy)) {
                ListTagUtil.write(pageContext, "selected");
            }
            ListTagUtil.write(pageContext, ">");
            ListTagUtil.write(pageContext, field);
            ListTagUtil.write(pageContext, "</option>");
        }
        ListTagUtil.write(pageContext, "</select>");
    }

    filterValue = StringUtil.nullOrValue(filterValue);
    StringBuilder sb = new StringBuilder();

    // create a new row
    sb.append("<div class=\"input-group input-group-sm\">");

    String placeHolder = StringUtils.defaultString(ls.getMessage("message.filterby", fields.get(0).toString()));
    sb.append(String.format(
            "<input autofocus=\"autofocus\" type=\"text\" "
                    + " name=\"%s\" value=\"%s\" class=\"form-control\" placeholder=\"%s\"/>",
            filterValueKey, (filterValue != null ? StringEscapeUtils.escapeHtml(filterValue) : ""),
            StringEscapeUtils.escapeHtml(placeHolder)));
    sb.append("<span class=\"input-group-btn\">");
    sb.append(String.format(
            "<button value=\"%s\" type=\"submit\" name=\"%s\" "
                    + " class=\"btn btn-default spacewalk-button-filter\"><i class=\"fa fa-eye\"></i>",
            ls.getMessage(RequestContext.FILTER_KEY), filterName));
    sb.append("</button>");
    sb.append("</span>");

    sb.append("</div>");

    ListTagUtil.write(pageContext, sb.toString());

}

From source file:com.sun.faces.taglib.BaseComponentTag.java

public int doStartTag() throws JspException {
    int rc = 0;/*from   ww  w  . j a v  a2s . c o m*/
    try {
        rc = super.doStartTag();
    } catch (JspException e) {
        if (log.isDebugEnabled()) {
            log.debug(getDebugString(), e);
        }
        throw e;
    } catch (Throwable t) {
        if (log.isDebugEnabled()) {
            log.debug(getDebugString(), t);
        }
        throw new JspException(t);
    }
    return rc;
}

From source file:com.sun.faces.taglib.BaseComponentTag.java

public int doEndTag() throws JspException {
    int rc = 0;//from w  w  w.j a  v  a2 s.co  m
    try {
        rc = super.doEndTag();
    } catch (JspException e) {
        if (log.isDebugEnabled()) {
            log.debug(getDebugString(), e);
        }
        throw e;
    } catch (Throwable t) {
        if (log.isDebugEnabled()) {
            log.debug(getDebugString(), t);
        }
        throw new JspException(t);
    }
    return rc;
}

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

private void setupPageData() throws JspException {
    Object d = pageContext.getAttribute(dataSetName);
    if (d == null) {
        d = pageContext.getRequest().getAttribute(dataSetName);
    }// w  w  w  .  j  a v  a2 s  .  c o  m
    if (d == null) {
        HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
        d = request.getSession(true).getAttribute(dataSetName);
    }
    if (d != null) {
        if (d instanceof List) {
            pageData = (List) d;
        } else {
            throw new JspException("Dataset named \'" + dataSetName + "\' is incompatible."
                    + " Must be an an instance of java.util.List.");
        }
    } else {
        pageData = Collections.EMPTY_LIST;
    }
}

From source file:jp.terasoluna.fw.web.struts.taglib.PageLinksTag.java

/**
 * ^O]Jn?\bh?B/*from   w w w  . j  a  v  a2s .c om*/
 *
 * @return ???w
 * @throws JspException JSPO
 */
@Override
public int doStartTag() throws JspException {

    //?`FbN
    if (!submit && (action == null || "".equals(action))) {
        log.error(ERROR_MESSAGE_ACTION_REQUIRED);
        throw new JspException(ERROR_MESSAGE_ACTION_REQUIRED);
    }

    // v?peBt@Cy?[WWvpN^O?
    getLinkProperty();

    //\?s?
    Object objRow = lookup(pageContext, name, rowProperty, scope);
    int row = getInt(objRow);

    //\?s?0?????I?B
    if (row <= 0) {
        if (log.isWarnEnabled()) {
            log.warn(WARN_MESSAGE_ILLEGAL_ROW);
        }
        return EVAL_BODY_INCLUDE;
    }

    //Jn?sCfbNX
    Object objIndex = lookup(pageContext, name, indexProperty, scope);
    int startIndex = getInt(objIndex);

    //S??
    Object objTotal = lookup(pageContext, name, totalProperty, scope);
    int totalCount = getInt(objTotal);

    //StringBuilder??
    StringBuilder sb = new StringBuilder();

    //?y?[W??A?y?[W???B
    attributePageCount(getPageIndex(row, startIndex), getPageCount(row, totalCount));

    if (submit) {
        //submit?true?ATu~bg?sy?[WN?o?B

        //\?s??AJnCfbNX^O?o
        defineHtml(row, startIndex, totalCount);

        //Oy?[WN?
        addPrevSubmit(sb, row, startIndex, totalCount);

        //y?[W?N?
        addDirectSubmit(sb, row, startIndex, totalCount);

        //y?[WN?
        addNextSubmit(sb, row, startIndex, totalCount);

    } else {
        //submit?false??

        //Oy?[WN?
        addPrevLink(sb, row, startIndex, totalCount);

        //y?[W?N?
        addDirectLink(sb, row, startIndex, totalCount);

        //y?[WN?
        addNextLink(sb, row, startIndex, totalCount);
    }

    //StringBuildere?o?B
    if (id == null || "".equals(id)) {
        try {
            JspWriter writer = pageContext.getOut();
            writer.println(sb.toString());
        } catch (IOException e) {
            log.error(e.getMessage());
            throw new JspTagException(e.toString());
        }
    } else {
        pageContext.setAttribute(id, sb.toString());
    }

    return EVAL_BODY_INCLUDE;
}

From source file:com.redhat.rhn.frontend.taglibs.ListDisplayTag.java

/** {@inheritDoc} */
@Override//from   w w w .  j  a  va2  s.com
public int doEndTag() throws JspException {
    JspWriter out = null;
    try {
        if (getPageList().isEmpty()) {
            return EVAL_PAGE;
        }

        if (isExport()) {
            ExportWriter eh = createExportWriter();
            String[] columns = StringUtils.split(this.getExportColumns(), ',');
            eh.setColumns(Arrays.asList(columns));
            ServletExportHandler seh = new ServletExportHandler(eh);
            pageContext.getOut().clear();
            pageContext.getOut().clearBuffer();
            pageContext.getResponse().reset();
            seh.writeExporterToOutput((HttpServletResponse) pageContext.getResponse(), getPageList());
            return SKIP_PAGE;
        }

        // Get the JSPWriter that the body used, then pop the
        // bodyContent, so that we can get the real JspWriter with getOut.
        BodyContent body = getBodyContent();
        pageContext.popBody();
        out = pageContext.getOut();

        if (body != null) {
            String bodyString = body.getString();
            // The toReplace string is kind of odd, but it is because
            // HtmlTag doesn't understand adding a property to be replaced.
            if (numItemsChecked == getPageList().size()) {
                bodyString = bodyString.replaceFirst("@@CHECKED@@=\"\"", "checked=\"1\"");
            } else {
                bodyString = bodyString.replaceFirst("@@CHECKED@@=\"\"", "");
            }
            out.println(bodyString);
        }
        out.println("</tbody>");

        out.println("</table>");

        /* If the type is a half-table, we must draw an extra row on the
         * end of the table if the reflink has been set
         */
        out.println("<div class=\"panel-footer\">");
        out.println("<div class=\"spacewalk-list-footer-addons\">");
        out.println("<div class=\"spacewalk-list-footer-addons-extra\">");
        renderSetButtons(out);
        out.println("</div>");
        out.println("<div class=\"spacewalk-list-reflinks\">");
        if (reflink != null) {
            setColumnCount(0);
            out.println("<a href=\"" + reflink + "\" >");

            /*
             * Here we render the reflink and its key. If the key hasn't
             * been set we just display the link address itself.
             */
            if (reflinkkey != null) {
                Object[] args = new Object[2];

                args[0] = new Integer(getPageList().getTotalSize());
                args[1] = reflinkkeyarg0;

                String message = LocalizationService.getInstance().getMessage(reflinkkey, args);
                out.println(message);
            } else {
                out.println(reflink);
            }

            out.println("</a>");
        }
        out.println("</div>");
        out.println("</div>");

        // close footer
        out.println("</div>");

        // close panel
        out.println("</div>");

        out.println("<div class=\"spacewalk-list-bottom-addons\">");
        out.println("<div class=\"spacewalk-list-pagination\">");
        /* If paging is on, we render the pagination */
        if (isPaging()) {
            renderPagination(out, false);
        }
        /* If paging is off and we are rendering a normal list,
         * we show a count of the results in the lower left corner
         * of the list
         */
        else if (type.equals("list")) {

            int finalResult = getPageList().getEnd();
            if (finalResult > getPageList().getTotalSize()) {
                finalResult = getPageList().getTotalSize();
            }

            Object[] args = new Object[4];
            args[0] = new Integer(getPageList().getStart());
            args[1] = new Integer(finalResult);
            args[2] = new Integer(getPageList().getTotalSize());
            args[3] = LocalizationService.getInstance().getMessage(description);

            out.print("<span class=\"text-right\">\n");
            out.print(LocalizationService.getInstance().getMessage("message.range.withtypedescription", args));
            out.println("</span>");
        }
        out.println("</div>");
        if (isPaging()) {
            out.print("<div class=\"row-0\">\n");
            renderActionButtons(out);
            out.println("</div>");
        }
        out.println("</div>");

        // close list
        out.println("</div>");

        // export button goes outside of the list because in the new
        // implementation it is data-set dependent and not list dependent
        if (getExportColumns() != null) {
            renderExport(out);
        }

        setColumnCount(0);
        setNumberOfColumns(0);
    } catch (IOException e) {
        throw new JspException("IO error" + e.getMessage());
    } finally {
        pageContext.setAttribute("current", null);
    }

    return EVAL_PAGE;
}

From source file:com.redhat.rhn.frontend.taglibs.ListDisplayTag.java

/** {@inheritDoc} */
@Override//from  w ww .  j  ava 2  s .c o m
public int doAfterBody() throws JspException {
    JspWriter out = null;
    try {
        out = pageContext.getOut();

        if (pageContext.getAttribute("current") == null) {
            out.println("</tr>");
            out.println("</thead>");
            out.println("<tbody>");
        } else {
            out.println("</tr>");
        }

        if (getIterator().hasNext()) {
            setColumnCount(0);
            Object next = getIterator().next();
            out.println(getTrElement(next));
            pageContext.setAttribute("current", next);
            return EVAL_BODY_AGAIN;
        }

    } catch (IOException e) {
        throw new JspException("Error while writing to JSP: " + e.getMessage());
    }

    return SKIP_BODY;
}

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

private void verifyEnvironment() throws JspException {
    if (BodyTagSupport.findAncestorWithClass(this, ListSetTag.class) == null) {
        throw new JspException("List must be enclosed by a ListSetTag");
    }// w w w .ja v  a2 s . c  o  m
}