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:org.gvnix.datatables.tags.RooTableTag.java

/**
 * Gets Id content/*from w  w  w.j  a  va  2  s . c  o m*/
 * 
 * @return
 * @throws JspException
 */
protected String getIdContent() throws JspException {
    ExpressionParser parser = new SpelExpressionParser();
    Expression exp = parser.parseExpression(this.rowIdBase);
    EvaluationContext context = new StandardEvaluationContext(currentObject);

    Object value = exp.getValue(context);
    String result = "";

    if (value == null) {
        // Use AbstractTablaTag standard behavior
        try {
            value = PropertyUtils.getNestedProperty(this.currentObject, this.rowIdBase);

        } catch (IllegalAccessException e) {
            LOGGER.error("Unable to get the value for the given rowIdBase {}", this.rowIdBase);
            throw new JspException(e);
        } catch (InvocationTargetException e) {
            LOGGER.error("Unable to get the value for the given rowIdBase {}", this.rowIdBase);
            throw new JspException(e);
        } catch (NoSuchMethodException e) {
            LOGGER.error("Unable to get the value for the given rowIdBase {}", this.rowIdBase);
            throw new JspException(e);
        }
    }

    if (value != null) {
        // TODO manage exceptions to log it
        ConversionService conversionService = (ConversionService) helper.getBean(this.pageContext,
                getConversionServiceId());
        if (conversionService != null && conversionService.canConvert(value.getClass(), String.class)) {
            result = conversionService.convert(value, String.class);
        } else {
            result = ObjectUtils.getDisplayString(value);
        }
        result = HtmlUtils.htmlEscape(result);
    }

    return result;
}

From source file:net.naijatek.myalumni.util.taglib.BirthdayListTag.java

/**
 * Process the end of this tag./*  w w  w.ja  v a  2s  .co  m*/
 * 
 * @throws JspException
 *             if a JSP exception has occurred
 * @return int
 */
@Override
public final int doEndTag() throws JspException {

    request = (HttpServletRequest) pageContext.getRequest();
    StringBuffer sb = new StringBuffer();
    Calendar now = new GregorianCalendar();
    String seperator = "/";
    MemberVO user = new MemberVO();
    List<MemberVO> bdays = new ArrayList<MemberVO>();
    int today = now.get(Calendar.DATE);
    String rowCss = new String();
    String rootContext = request.getContextPath();
    String rootContextName = StringUtil.trimRootContext(request.getContextPath());

    try {
        bdays = memService.getBirthdayListOfTheMonth(String.valueOf((now.get(Calendar.MONTH) + 1)));

        sb.append("<table width=\"" + this.getTableWidth()
                + "\" border=\"0\" cellspacing=\"1\" cellpadding=\"3\" align=\"center\"  class=\"tborder\">");
        sb.append("<tr>");
        sb.append("<td height=\"30\" class=\"bg0\" colspan=\"3\">Happy Birthday this month of "
                + StringUtil.convertToAlphaMonth(now.get(Calendar.MONTH) + 1)
                + " to the following Alumni's.</td>");
        sb.append("</tr>");
        sb.append("<tr  class=\"portlet-section-body\">");
        sb.append("<td height=\"30\" class=\"bg0\">Alumni Name</td>");
        sb.append("<td height=\"30\" class=\"bg0\">Departure Year</td>");
        sb.append("<td height=\"30\" class=\"bg0\">Birthday</td>");
        sb.append("</tr>");

        int size = bdays.size();
        for (int i = 0; i < size; i++) {
            user = (MemberVO) bdays.get(i);
            DateTime dt = new DateTime(user.getDob());
            if (today == dt.getDayOfMonth()) {
                rowCss = "bgH";
            } else {
                rowCss = "portlet-section-body";
            }
            // sb.append("<tr bgcolor=\" + rowCss + \">");
            sb.append("<tr class=\"");
            sb.append(rowCss);
            sb.append("\">");
            sb.append("<td>");

            if (today == dt.getDayOfMonth()) {
                sb.append("<img src=\"" + rootContext.trim() + seperator
                        + "/images/icon/bday.jpg\" align=\"absmiddle\">");
            }
            sb.append("<a href=\"/");
            sb.append(rootContextName);
            sb.append("/action/member/displayMiniProfile?action=displayMiniProfile&memberUserName="
                    + user.getMemberUserName()
                    + "\" + onclick=\"newPopup(this.href,'name');return false\" title=\"View "
                    + user.getFirstName() + " " + user.getLastName() + " details\">" + user.getFirstName() + " "
                    + user.getLastName() + "</td>");
            sb.append("<td>" + user.getYearOut() + "</td>");
            sb.append("<td> " + StringUtil.dobPostfix(dt.getDayOfMonth()) + " of "
                    + StringUtil.convertToAlphaMonth(now.get(Calendar.MONTH) + 1) + " </td>");
            sb.append("</tr>");
        }
        if (size == 0) {
            rowCss = "portlet-section-body";
            sb.append("<tr class=\"");
            sb.append(rowCss);
            sb.append("\">");
            sb.append("<td class=\"fieldlabel\" colspan=\"3\">None.</td>");
            sb.append("</tr>");
        }
        sb.append("</table>");
    } catch (Exception ex) {
        logger.error(ex.getMessage());
        throw new JspException("IO Problem in BirthdayListTag " + ex.getMessage());
    }

    try {
        pageContext.getOut().print(sb.toString());
    } catch (Exception e) {
        logger.debug(e.getMessage());
        throw new JspException("IO Problem in BirthdayListTag " + e.getMessage());
    }

    return EVAL_PAGE;
}

From source file:com.sun.faces.taglib.jsf_core.ViewTag.java

public int doEndTag() throws JspException {
    int rc = super.doEndTag();
    // PENDING(): remove these getCurrentInstance calls, since we
    // have a facesContext ivar.
    FacesContext context = FacesContext.getCurrentInstance();
    ResponseWriter writer = context.getResponseWriter();
    Util.doAssert(writer != null);
    try {//from   w  w  w.  j av a  2s  . c  o  m
        writer.endDocument();
    } catch (IOException e) {
        throw new JspException(e.getMessage());
    }

    // store the response character encoding
    HttpSession session = null;

    if (null != (session = pageContext.getSession())) {
        session.setAttribute(ViewHandler.CHARACTER_ENCODING_KEY,
                pageContext.getResponse().getCharacterEncoding());
    }
    return rc;
}

From source file:org.openmrs.module.web.taglib.ExtensionPopupMenuTag.java

public int doStartTag() throws JspException {
    if (showLabelIfNoExtensions == null) {
        showLabelIfNoExtensions = true;/*ww  w. ja  va  2  s . c o  m*/
    }
    // using this as we'd use MessageSourceAccessor
    RequestContext context = new RequestContext((HttpServletRequest) this.pageContext.getRequest());

    boolean below = !"above".equals(position);
    Map<String, String> parameters = new HashMap<String, String>();
    if (this.parameters != null) {
        parameters.putAll(OpenmrsUtil.parseParameterList(this.parameters));
    }

    StringBuilder sb = new StringBuilder();
    sb.append("<span style=\"position: relative\">");
    if (below) {
        sb.append("<div id=\"" + popupDivId
                + "\" style=\"width: 35em; border: 1px solid black; background-color: #f0f0a0; position: absolute; top: 0px; padding-right: 1.2em; z-index: 1; display: none\">");
    } else {
        sb.append("<div id=\"" + popupDivId
                + "\" style=\"width: 35em; border: 1px solid black; background-color: #f0f0a0; position: absolute; bottom: 0px; padding-right: 1.2em; z-index: 1; display: none\">");
    }

    sb.append("<div style=\"float: right\"><a href=\"javascript:hideLayer('" + popupDivId + "');\" >["
            + context.getMessage("general.close") + "]</a></div>");
    sb.append("<ul>");
    boolean anyExtensionsFound = false;
    List<Extension> extensions = ModuleFactory.getExtensions(pointId, Extension.MEDIA_TYPE.html);
    for (Extension e : extensions) {
        if (e instanceof LinkProviderExtension) {
            anyExtensionsFound = true;
            LinkProviderExtension extension = (LinkProviderExtension) e;
            List<Link> links = extension.getLinks();
            log.debug("extension of class " + e.getClass() + " provides " + links.size() + " links");
            for (Link link : links) {
                String url = link.getUrl();
                log.debug("url = " + url);
                StringBuilder hiddenVars = new StringBuilder();
                Map<String, String> javascriptSubstitutions = new HashMap<String, String>();
                for (Map.Entry<String, String> entry : link.getQueryParameters().entrySet()) {
                    hiddenVars.append("<input type=\"hidden\" name=\"" + entry.getKey() + "\" value=\""
                            + entry.getValue() + "\"/>\n");
                }
                for (Map.Entry<String, String> entry : parameters.entrySet()) {
                    hiddenVars.append("<input type=\"hidden\" name=\"" + entry.getKey() + "\" ");
                    if (entry.getValue().startsWith("javascript:")) {
                        String function = entry.getValue();
                        function = function.substring(function.indexOf(":") + 1);
                        String random = randomString();
                        javascriptSubstitutions.put(random, function);
                        hiddenVars.append("id=\"" + random + "\" value=\"\"");
                    } else {
                        hiddenVars.append("value=\"" + entry.getValue() + "\"");
                    }
                    hiddenVars.append("/>\n");
                }
                String formId = randomString();

                StringBuilder onClick = new StringBuilder();
                if (javascriptSubstitutions.size() > 0) {
                    onClick.append(" var _popup_tmp = ''; ");
                }
                for (Map.Entry<String, String> entry : javascriptSubstitutions.entrySet()) {
                    String id = entry.getKey();
                    String function = entry.getValue();
                    onClick.append(" _popup_tmp = " + function
                            + "; if (_popup_tmp == null) return; document.getElementById('" + id
                            + "').value = _popup_tmp; ");
                }
                onClick.append("document.getElementById('" + formId + "').submit();");

                sb.append("<li>");
                sb.append("<form id=\"" + formId + "\" method=\"post\" action=\"" + url + "\">\n");
                sb.append(hiddenVars);
                sb.append("\n<a href=\"#\" onClick=\"javascript:" + onClick + "\">"
                        + context.getMessage(link.getLabel(), link.getLabel()) + "</a>");
                if (link.getDescription() != null) {
                    sb.append("<br/><small>" + context.getMessage(link.getDescription(), link.getDescription())
                            + "</small>");
                }
                sb.append("</form>");
                sb.append("</li>");
            }
        }
    }
    if (!anyExtensionsFound) {
        sb.append("<li>" + context.getMessage("general.none") + "</li>");
    }

    sb.append("</ul>");
    sb.append("</div>");
    sb.append("</span>");
    sb.append("<a href=\"#\" onClick=\"toggleLayer('" + popupDivId + "')\" style=\"border: 1px black solid\">"
            + context.getMessage(label, label) + "</a>");

    try {
        if (anyExtensionsFound || showLabelIfNoExtensions) {
            pageContext.getOut().print(sb);
        }
    } catch (IOException ex) {
        throw new JspException(ex);
    }

    resetValues();
    return SKIP_BODY;
}

From source file:alpha.portal.webapp.taglib.LabelTag.java

@Override
public int doStartTag() throws JspException {

    try {/* w  w  w .  j a v  a2s  . c  o m*/
        this.requestContext = new RequestContext((HttpServletRequest) this.pageContext.getRequest());
    } catch (final RuntimeException ex) {
        throw ex;
    } catch (final Exception ex) {
        this.pageContext.getServletContext().log("Exception in custom tag", ex);
    }

    // Look up this key to see if its a field of the current form
    boolean requiredField = false;
    boolean validationError = false;

    final ValidatorResources resources = this.getValidatorResources();

    Locale locale = this.pageContext.getRequest().getLocale();

    if (locale == null) {
        locale = Locale.getDefault();
    }

    // get the name of the bean from the key
    final String formName = this.key.substring(0, this.key.indexOf('.'));
    final String fieldName = this.key.substring(formName.length() + 1);

    if (resources != null) {
        final Form form = resources.getForm(locale, formName);

        if (form != null) {
            final Field field = form.getField(fieldName);

            if (field != null) {
                if (field.isDependency("required") || field.isDependency("validwhen")) {
                    requiredField = true;
                }
            }
        }
    }

    final Errors errors = this.requestContext.getErrors(formName, false);
    List fes = null;
    if (errors != null) {
        fes = errors.getFieldErrors(fieldName);
        // String errorMsg = getErrorMessages(fes);
    }

    if ((fes != null) && (fes.size() > 0)) {
        validationError = true;
    }

    // Retrieve the message string we are looking for
    String message = null;
    try {
        message = this.getMessageSource().getMessage(this.key, null, locale);
    } catch (final NoSuchMessageException nsm) {
        message = "???" + this.key + "???";
    }

    String cssClass = null;
    if (this.styleClass != null) {
        cssClass = this.styleClass;
    } else if (requiredField) {
        cssClass = "required";
    }

    final String cssErrorClass = (this.errorClass != null) ? this.errorClass : "error";
    final StringBuffer label = new StringBuffer();

    if ((message == null) || "".equals(message.trim())) {
        label.append("");
    } else {
        label.append("<label for=\"").append(fieldName).append("\"");

        if (validationError) {
            label.append(" class=\"").append(cssErrorClass).append("\"");
        } else if (cssClass != null) {
            label.append(" class=\"").append(cssClass).append("\"");
        }

        label.append(">").append(message);
        label.append((requiredField) ? " <span class=\"req\">*</span>" : "");
        label.append((this.colon) ? ":" : "");
        label.append("</label>");

        if (validationError) {
            label.append("<img class=\"validationWarning\" alt=\"");
            label.append(this.getMessageSource().getMessage("icon.warning", null, locale));
            label.append("\"");

            final String context = ((HttpServletRequest) this.pageContext.getRequest()).getContextPath();

            label.append(" src=\"").append(context);
            label.append(this.getMessageSource().getMessage("icon.warning.img", null, locale));
            label.append("\" />");
        }
    }

    // Print the retrieved message to our output writer
    try {
        this.writeMessage(label.toString());
    } catch (final IOException io) {
        io.printStackTrace();
        throw new JspException("Error writing label: " + io.getMessage());
    }

    // Continue processing this page
    return (Tag.SKIP_BODY);
}

From source file:com.xhsoft.framework.common.page.PageTag.java

/**
 * <p>Description:buildRefresh</p>
 * @param request   //w w w. j a v a2s  . c  o m
 * @param pageNo 
 * @return void
 * @author wenzhi
 * @version 1.0
 * @exception JspException
 */
@SuppressWarnings("unused")
private void buildRefresh(HttpServletRequest request, int pageNo) throws JspException {
    try {
        JspWriter out = pageContext.getOut();
        StringBuffer outString = new StringBuffer(50);
        outString.append("<a href=\"javascript:setPage('" + pageNo + "','" + targets + "');\">");
        outString.append("</a>");
        out.print(outString.toString());
    } catch (Exception e) {
        throw new JspException(e);
    }
}

From source file:gov.nih.nci.ncicb.cadsr.common.jsp.tag.handler.SecureIconDisplay.java

private String getParamValue(Form form, String paramProperty) throws JspException {
    String paramValue = null;/*ww  w  .ja v a 2  s.  c  om*/
    try {
        PropertyUtils beanPropertyUtil = new PropertyUtils();
        paramValue = (String) beanPropertyUtil.getProperty(form, paramProperty);

    } catch (Exception ex) {
        throw new JspException(ex.toString());
    }
    return paramValue;
}

From source file:de.iteratec.iteraplan.presentation.tags.TagUtils.java

/**
 * Converts the scope name into its corresponding PageContext constant value.
 * // w ww. jav a2 s .c o  m
 * @param scopeName
 *          Can be "page", "request", "session", or "application" in any case.
 * @return The constant representing the scope (ie. PageContext.REQUEST_SCOPE).
 * @throws JspException
 *           if the scopeName is not a valid name.
 */
public static int getScope(String scopeName) throws JspException {

    Integer scope = SCOPES.get(scopeName.toLowerCase());
    if (scope == null) {
        throw new JspException("An invalid scope identifier was encountered: " + scopeName);
    }

    return scope.intValue();
}

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

 @Override
public int doAfterBody() throws JspException {

   Table table = model.getTable();//w  w w.j a  va 2  s.  c om

      
      
   table.setAttribute(TableConstants.EXTEND_ATTRIBUTES,getExtendAttributesAsString());
    resetExtendAttribute();

    table.afterBody();
       
   try {
         
         if (queryResult!=null){
               
          if (queryResult.getResultSet()!=null && queryResult.getResultSet().next()) {
             
                model.queryResultExecute();

             Object bean = DataAccessUtil.resultSetToMap(queryResult.getResultSet());
             model.setCurrentRowBean(bean);
             return EVAL_BODY_AGAIN;
          }
             
         }else{
            
         
         if (iterator == null) {
            iterator = model.execute().iterator();
         }
         if (iterator!=null && iterator.hasNext()) {
            Object bean = iterator.next();
            model.setCurrentRowBean(bean);
            return EVAL_BODY_AGAIN;
         }
         }
   } catch (Exception e) {
      throw new JspException("TableTag.doAfterBody() Problem: "
            + ExceptionUtils.formatStackTrace(e));
   }

   return SKIP_BODY;
}

From source file:com.rsmart.certification.tool.tag.RsmartListScrollTag.java

/**
 * Default processing of the start tag returning EVAL_BODY_BUFFERED.
 *
 * @return EVAL_BODY_BUFFERED/*from  w w  w. j  a  va  2  s  . c om*/
 * @throws javax.servlet.jsp.JspException if an error occurred while processing this tag
 * @see javax.servlet.jsp.tagext.BodyTag#doStartTag
 */
protected int doStartTagInternal() throws Exception {
    JspWriter writer = pageContext.getOut();

    try {
        if (listScroll == null) {
            listScroll = (ListScroll) pageContext.getRequest().getAttribute("listScroll");
        }

        // don't print page if no items in list
        if (listScroll.getTotal() == 0) {
            LOG.debug("nothing in list, nothing to render...");
            return EVAL_PAGE;
        }

        writer.write("<div ");

        if (className != null) {
            writer.write("class=\"" + className + "\"");
        }

        writer.write(">");
        writer.write("<form name=\"listScrollForm\" >");

        String htmlOptions = "&nbsp";
        if (showDropdown) {
            if (dropdownOptions != null) {
                String[] vals = dropdownOptions.split(";");
                htmlOptions = "\n<select name=\"" + SCROLL_SIZE + "\" onchange=\"window.document.location=\'"
                        + listUrl + "&" + ListScroll.STARTING_INDEX_TAG + "="
                        + (listScroll.getNextIndex() - listScroll.getPerPage());
                htmlOptions += "&" + SCROLL_SIZE + "='+this.options[this.selectedIndex].value\">\n";
                if (vals != null && vals.length > 0) {
                    if (listScroll.getPerPage() == -1) {
                        listScroll.setPerPage(getMinIntValue(vals));
                    }

                    for (String val : vals) {
                        if (val != null && ((val.trim().length()) > 0)) {
                            int value = Integer.parseInt(val.trim());
                            String displayValue = String.valueOf(value);
                            if (value == Integer.MAX_VALUE) {
                                displayValue = resolveMessage(ALL_KEY);
                            }

                            htmlOptions += "<option value=\"" + value + "\" "
                                    + ((String.valueOf(listScroll.getPerPage())
                                            .equalsIgnoreCase(String.valueOf(value))) ? ("selected") : (""))
                                    + ">" + resolveMessage(SHOW_KEY) + " " + displayValue + "</option>\n";
                        }
                    }

                    htmlOptions += "</select>";
                }
            }
        }

        int lastIndex = listScroll.getFirstItem() + listScroll.getPerPage() - 1;
        writer.write("&nbsp;");
        writer.write(
                resolveMessage(VIEWING_KEY,
                        new String[] { String.valueOf(listScroll.getFirstItem()), String.valueOf(
                                (lastIndex <= listScroll.getTotal()) ? (lastIndex) : (listScroll.getTotal())),
                                String.valueOf(listScroll.getTotal()), }));

        writer.write("&nbsp;");
        writer.write("<br>");
        writer.write("<input type=\"button\" value=\"" + resolveMessage("listscroll_first")
                + "\" onclick=\"window.document.location=\'");
        writer.write(listUrl + "&" + ListScroll.STARTING_INDEX_TAG + "=0");
        writer.write("\'\"");
        if (listScroll.getPrevIndex() == -1) {
            writer.write(" disabled=\"disabled\" ");
        }

        writer.write(" >");
        writer.write("<input type=\"button\" value=\"" + resolveMessage("listscroll_previous")
                + "\" onclick=\"window.document.location=\'");
        writer.write(listUrl + "&" + ListScroll.STARTING_INDEX_TAG + "=" + listScroll.getPrevIndex());
        writer.write("\'\"");
        if (listScroll.getPrevIndex() == -1) {
            writer.write(" disabled=\"disabled\" ");
        }

        writer.write(" >");
        writer.write("&nbsp;");
        writer.write(htmlOptions);
        writer.write("&nbsp;");
        writer.write("<input type=\"button\" value=\"" + resolveMessage("listscroll_next")
                + "\" onclick=\"window.document.location=\'");
        writer.write(listUrl + "&" + ListScroll.STARTING_INDEX_TAG + "=" + listScroll.getNextIndex());
        writer.write("\'\"");
        if (listScroll.getNextIndex() == -1) {
            writer.write(" disabled=\"disabled\" ");
        }

        writer.write(" >");
        writer.write("<input type=\"button\" value=\"" + resolveMessage("listscroll_last")
                + "\" onclick=\"window.document.location=\'");
        writer.write(listUrl + "&" + ListScroll.STARTING_INDEX_TAG + "=" + Integer.MAX_VALUE);
        writer.write("\'\"");
        if (listScroll.getNextIndex() == -1) {
            writer.write(" disabled=\"disabled\" ");
        }

        writer.write(" >");
        writer.write("</form >");
        writer.write("</div>");
        writer.write("<br />");

        // make the begin, end, and total available to the jsp page
        pageContext.setAttribute("list_scroll_begin_index", listScroll.getFirstItem());
        pageContext.setAttribute("list_scroll_end_index", listScroll.getLastItem());
        pageContext.setAttribute("list_scroll_total_index", listScroll.getTotal());
        pageContext.setAttribute("list_scroll_page_size", listScroll.getPerPage());
    } catch (IOException e) {
        LOG.error("", e);
        throw new JspException(e);
    }

    return EVAL_PAGE;
}