Search in sources :

Example 41 with ActionMessages

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

the class TestTagUtils method testGetActionErrors1e.

// ActionErrors (thrown Exception)
// TODO -- currently this does not hit the line for caught Exception
public void testGetActionErrors1e() {
    ActionMessages actionErrors = new ActionMessages();
    actionErrors.add("prop", new ActionMessage("key.key"));
    request.setAttribute("errors", actionErrors);
    try {
        ActionMessages errors = tagutils.getActionMessages(pageContext, "does-not-exist");
        assertNotNull("errors should not be null", errors);
        assertNotNull("errors prop should not be null", errors.get("prop"));
        for (Iterator iter = errors.get("prop"); iter.hasNext(); ) {
            fail("Should not have any errors for does-not-exist");
        }
    } 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 42 with ActionMessages

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

the class TestTagUtils method testActionMessages_getActionMessages_PageContext_String1.

// ------------------------------------------ getActionMessages()
// -- using ActionMessages
public void testActionMessages_getActionMessages_PageContext_String1() {
    ActionMessages actionMessages = new ActionMessages();
    actionMessages.add("prop", new ActionMessage("key.key"));
    request.setAttribute("messages", actionMessages);
    try {
        ActionMessages messages = tagutils.getActionMessages(pageContext, "messages");
        assertNotNull("messages should not be null", messages);
        assertNotNull("messages prop should not be null", messages.get("prop"));
        String val = null;
        int i = 0;
        for (Iterator iter = messages.get("prop"); iter.hasNext(); ) {
            ActionMessage message = (ActionMessage) iter.next();
            val = message.getKey();
            i++;
        }
        assertEquals("only 1 message", i, 1);
        assertEquals("messages 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 43 with ActionMessages

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

the class TestTagUtils method testActionMessages_getActionMessages_PageContext_String2.

// -- using ActionErrors
public void testActionMessages_getActionMessages_PageContext_String2() {
    ActionMessages actionMessages = new ActionMessages();
    actionMessages.add("prop", new ActionMessage("key.key"));
    request.setAttribute("messages", actionMessages);
    try {
        ActionMessages messages = tagutils.getActionMessages(pageContext, "messages");
        assertNotNull("messages should not be null", messages);
        assertNotNull("messages prop should not be null", messages.get("prop"));
        String val = null;
        int i = 0;
        for (Iterator iter = messages.get("prop"); iter.hasNext(); ) {
            ActionMessage message = (ActionMessage) iter.next();
            val = message.getKey();
            i++;
        }
        assertEquals("only 1 message", i, 1);
        assertEquals("messages 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 44 with ActionMessages

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

the class TestTagUtils method testActionMessages_getActionMessages_PageContext_String6.

// ActionMessages (thrown Exception)
// TODO -- currently this does not hit the line for caught Exception
public void testActionMessages_getActionMessages_PageContext_String6() {
    ActionMessages actionMessages = new ActionMessages();
    actionMessages.add("prop", new ActionMessage("key.key"));
    request.setAttribute("messages", actionMessages);
    try {
        ActionMessages messages = tagutils.getActionMessages(pageContext, "does-not-exist");
        assertNotNull("messages should not be null", messages);
        assertNotNull("messages prop should not be null", messages.get("prop"));
        for (Iterator iter = messages.get("prop"); iter.hasNext(); ) {
            fail("Should not have any messages for does-not-exist");
        }
    } 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 45 with ActionMessages

use of org.apache.struts.action.ActionMessages in project head by mifos.

the class FeeAction method update.

@TransactionDemarcate(validateAndResetToken = true)
public ActionForward update(ActionMapping mapping, ActionForm form, @SuppressWarnings("unused") HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    FeeActionForm feeActionForm = (FeeActionForm) form;
    FeeStatus feeStatus = feeActionForm.getFeeStatusValue();
    String forward = "";
    Short feeStatusValue = null;
    String whereToForward = "";
    if (feeStatus != null) {
        feeStatusValue = feeStatus.getValue();
    }
    FeeUpdateRequest feeUpdateRequest = new FeeUpdateRequest(Short.valueOf(feeActionForm.getFeeId()), feeActionForm.getCurrencyId(), feeActionForm.getAmount(), feeStatusValue, feeActionForm.getRateValue());
    if (feeUpdateRequest.getFeeStatusValue() == 2) {
        this.feeServiceFacade.updateFee(feeUpdateRequest);
        try {
            boolean remove = feeActionForm.isToRemove();
            this.feeServiceFacade.removeFee(feeUpdateRequest, remove);
            whereToForward = REMOVE_SUCCESS;
        } catch (MifosRuntimeException e) {
            ActionMessages messages = new ActionMessages();
            messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("Fees.feeCannotBeRemoved"));
            saveMessages(request, messages);
            whereToForward = UPDATE_SUCCESS;
        }
    } else if (feeActionForm.isToRemove() && feeUpdateRequest.getFeeStatusValue() == 1) {
        ActionMessages errors = new ActionMessages();
        errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("Fees.feeCantBeRemove"));
        saveErrors(request, errors);
        whereToForward = UPDATE_FAILURE;
    } else {
        this.feeServiceFacade.updateFee(feeUpdateRequest);
        whereToForward = UPDATE_SUCCESS;
    }
    if (whereToForward.equals(UPDATE_SUCCESS)) {
        forward = ActionForwards.update_success.toString();
    } else if (whereToForward.equals(UPDATE_FAILURE)) {
        forward = ActionForwards.update_failure.toString();
    } else if (whereToForward.equals(REMOVE_SUCCESS)) {
        forward = ActionForwards.remove_fee_success.toString();
    }
    return mapping.findForward(forward);
}
Also used : FeeActionForm(org.mifos.accounts.fees.struts.actionforms.FeeActionForm) ActionMessages(org.apache.struts.action.ActionMessages) FeeUpdateRequest(org.mifos.dto.domain.FeeUpdateRequest) ActionMessage(org.apache.struts.action.ActionMessage) FeeStatus(org.mifos.accounts.fees.util.helpers.FeeStatus) MifosRuntimeException(org.mifos.core.MifosRuntimeException) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

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