Search in sources :

Example 1 with ActionMessages

use of org.apache.struts.action.ActionMessages in project sonarqube by SonarSource.

the class MessagesTag method doStartTag.

/**
     * Construct an iterator for the specified collection, and begin looping
     * through the body once per element.
     *
     * @throws JspException if a JSP exception has occurred
     */
public int doStartTag() throws JspException {
    // Initialize for a new request.
    processed = false;
    // Were any messages specified?
    ActionMessages messages = null;
    // Make a local copy of the name attribute that we can modify.
    String name = this.name;
    if ((message != null) && "true".equalsIgnoreCase(message)) {
        name = Globals.MESSAGE_KEY;
    }
    try {
        messages = TagUtils.getInstance().getActionMessages(pageContext, name);
    } catch (JspException e) {
        TagUtils.getInstance().saveException(pageContext, e);
        throw e;
    }
    // Acquire the collection we are going to iterate over
    this.iterator = (property == null) ? messages.get() : messages.get(property);
    // Store the first value and evaluate, or skip the body if none
    if (!this.iterator.hasNext()) {
        return SKIP_BODY;
    }
    // process the first message
    processMessage((ActionMessage) iterator.next());
    if ((header != null) && (header.length() > 0)) {
        String headerMessage = TagUtils.getInstance().message(pageContext, bundle, locale, header);
        if (headerMessage != null) {
            TagUtils.getInstance().write(pageContext, headerMessage);
        }
    }
    // Set the processed variable to true so the
    // doEndTag() knows processing took place
    processed = true;
    return (EVAL_BODY_TAG);
}
Also used : JspException(javax.servlet.jsp.JspException) ActionMessages(org.apache.struts.action.ActionMessages)

Example 2 with ActionMessages

use of org.apache.struts.action.ActionMessages in project sonarqube by SonarSource.

the class BaseHandlerTag method doErrorsExist.

/**
     * Determine if there are errors for the component.
     *
     * @return Whether errors exist.
     */
protected boolean doErrorsExist() throws JspException {
    boolean errorsExist = false;
    if ((getErrorStyleId() != null) || (getErrorStyle() != null) || (getErrorStyleClass() != null)) {
        String actualName = prepareName();
        if (actualName != null) {
            ActionMessages errors = TagUtils.getInstance().getActionMessages(pageContext, errorKey);
            errorsExist = ((errors != null) && (errors.size(actualName) > 0));
        }
    }
    return errorsExist;
}
Also used : ActionMessages(org.apache.struts.action.ActionMessages)

Example 3 with ActionMessages

use of org.apache.struts.action.ActionMessages in project sonarqube by SonarSource.

the class ErrorsTag method doStartTag.

// ------------------------------------------------------- Public Methods
/**
     * Render the specified error messages if there are any.
     *
     * @throws JspException if a JSP exception has occurred
     */
public int doStartTag() throws JspException {
    // Were any error messages specified?
    ActionMessages errors = null;
    try {
        errors = TagUtils.getInstance().getActionMessages(pageContext, name);
    } catch (JspException e) {
        TagUtils.getInstance().saveException(pageContext, e);
        throw e;
    }
    if ((errors == null) || errors.isEmpty()) {
        return (EVAL_BODY_INCLUDE);
    }
    boolean headerPresent = TagUtils.getInstance().present(pageContext, bundle, locale, getHeader());
    boolean footerPresent = TagUtils.getInstance().present(pageContext, bundle, locale, getFooter());
    boolean prefixPresent = TagUtils.getInstance().present(pageContext, bundle, locale, getPrefix());
    boolean suffixPresent = TagUtils.getInstance().present(pageContext, bundle, locale, getSuffix());
    // Render the error messages appropriately
    StringBuffer results = new StringBuffer();
    boolean headerDone = false;
    String message = null;
    Iterator reports = (property == null) ? errors.get() : errors.get(property);
    while (reports.hasNext()) {
        ActionMessage report = (ActionMessage) reports.next();
        if (!headerDone) {
            if (headerPresent) {
                message = TagUtils.getInstance().message(pageContext, bundle, locale, getHeader());
                results.append(message);
            }
            headerDone = true;
        }
        if (prefixPresent) {
            message = TagUtils.getInstance().message(pageContext, bundle, locale, getPrefix());
            results.append(message);
        }
        if (report.isResource()) {
            message = TagUtils.getInstance().message(pageContext, bundle, locale, report.getKey(), report.getValues());
        } else {
            message = report.getKey();
        }
        if (message != null) {
            results.append(message);
        }
        if (suffixPresent) {
            message = TagUtils.getInstance().message(pageContext, bundle, locale, getSuffix());
            results.append(message);
        }
    }
    if (headerDone && footerPresent) {
        message = TagUtils.getInstance().message(pageContext, bundle, locale, getFooter());
        results.append(message);
    }
    TagUtils.getInstance().write(pageContext, results.toString());
    return (EVAL_BODY_INCLUDE);
}
Also used : JspException(javax.servlet.jsp.JspException) ActionMessages(org.apache.struts.action.ActionMessages) Iterator(java.util.Iterator) ActionMessage(org.apache.struts.action.ActionMessage)

Example 4 with ActionMessages

use of org.apache.struts.action.ActionMessages in project sonarqube by SonarSource.

the class TestTagUtils method testGetActionErrors1a.

// ------------------------------------------ getActionErrors()
// ActionErrors
public void testGetActionErrors1a() {
    ActionMessages actionErrors = new ActionMessages();
    actionErrors.add("prop", new ActionMessage("key.key"));
    request.setAttribute("errors", actionErrors);
    try {
        ActionMessages errors = tagutils.getActionMessages(pageContext, "errors");
        assertNotNull("errors should not be null", errors);
        assertNotNull("errors prop should not be null", errors.get("prop"));
        String val = null;
        int i = 0;
        for (Iterator iter = errors.get("prop"); iter.hasNext(); ) {
            ActionMessage error = (ActionMessage) iter.next();
            val = error.getKey();
            i++;
        }
        assertEquals("only 1 error", i, 1);
        assertEquals("errors prop should match", val, "key.key");
    } catch (JspException e) {
        fail(e.getMessage());
    }
}
Also used : JspException(javax.servlet.jsp.JspException) ActionMessages(org.apache.struts.action.ActionMessages) ActionMessage(org.apache.struts.action.ActionMessage) Iterator(java.util.Iterator)

Example 5 with ActionMessages

use of org.apache.struts.action.ActionMessages in project sonarqube by SonarSource.

the class TestTagUtils method testActionMessages_getActionMessages_PageContext_String4.

// -- using String Array
public void testActionMessages_getActionMessages_PageContext_String4() {
    String[] vals = new String[] { "bar", "baz" };
    request.setAttribute("foo", vals);
    try {
        ActionMessages messages = tagutils.getActionMessages(pageContext, "foo");
        assertNotNull("messages should not be null", messages);
        assertNotNull("messages prop should not be null", messages.get("prop"));
        String key = null;
        int i = 0;
        for (Iterator iter = messages.get(ActionMessages.GLOBAL_MESSAGE); iter.hasNext(); ) {
            ActionMessage message = (ActionMessage) iter.next();
            key = message.getKey();
            Object[] values = message.getValues();
            assertNull((values));
            assertEquals("1st key should match", key, vals[i]);
            i++;
        }
        assertEquals("only 1 message", i, 2);
    } catch (JspException e) {
        fail(e.getMessage());
    }
}
Also used : JspException(javax.servlet.jsp.JspException) ActionMessages(org.apache.struts.action.ActionMessages) Iterator(java.util.Iterator) ActionMessage(org.apache.struts.action.ActionMessage)

Aggregations

ActionMessages (org.apache.struts.action.ActionMessages)47 ActionMessage (org.apache.struts.action.ActionMessage)31 JspException (javax.servlet.jsp.JspException)15 ActionForward (org.apache.struts.action.ActionForward)14 Iterator (java.util.Iterator)11 AbstractContest (cn.edu.zju.acm.onlinejudge.bean.AbstractContest)10 Problem (cn.edu.zju.acm.onlinejudge.bean.Problem)6 UserProfile (cn.edu.zju.acm.onlinejudge.bean.UserProfile)6 ContestPersistence (cn.edu.zju.acm.onlinejudge.persistence.ContestPersistence)4 UserPersistence (cn.edu.zju.acm.onlinejudge.persistence.UserPersistence)4 UserSecurity (cn.edu.zju.acm.onlinejudge.security.UserSecurity)4 Date (java.util.Date)4 Submission (cn.edu.zju.acm.onlinejudge.bean.Submission)3 UserPreference (cn.edu.zju.acm.onlinejudge.bean.UserPreference)3 ProblemPersistence (cn.edu.zju.acm.onlinejudge.persistence.ProblemPersistence)3 Contest (cn.edu.zju.acm.onlinejudge.bean.Contest)2 Course (cn.edu.zju.acm.onlinejudge.bean.Course)2 Reference (cn.edu.zju.acm.onlinejudge.bean.Reference)2 Language (cn.edu.zju.acm.onlinejudge.bean.enumeration.Language)2 LogCriteria (cn.edu.zju.acm.onlinejudge.bean.request.LogCriteria)2