Example usage for com.liferay.portal.kernel.servlet SessionErrors add

List of usage examples for com.liferay.portal.kernel.servlet SessionErrors add

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.servlet SessionErrors add.

Prototype

public static void add(PortletRequest portletRequest, String key) 

Source Link

Usage

From source file:com.liferay.portlet.shopping.action.EditCouponAction.java

License:Open Source License

@Override
public void processAction(ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
        ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

    String cmd = ParamUtil.getString(actionRequest, Constants.CMD);

    try {/*from   ww  w.  j  a v  a 2 s  .  c om*/
        if (cmd.equals(Constants.ADD) || cmd.equals(Constants.UPDATE)) {
            updateCoupon(actionRequest);
        } else if (cmd.equals(Constants.DELETE)) {
            deleteCoupons(actionRequest);
        }

        sendRedirect(actionRequest, actionResponse);
    } catch (Exception e) {
        if (e instanceof NoSuchCouponException || e instanceof PrincipalException) {

            SessionErrors.add(actionRequest, e.getClass().getName());

            setForward(actionRequest, "portlet.shopping.error");
        } else if (e instanceof CouponCodeException || e instanceof CouponDateException
                || e instanceof CouponDescriptionException || e instanceof CouponDiscountException
                || e instanceof CouponEndDateException || e instanceof CouponLimitCategoriesException
                || e instanceof CouponLimitSKUsException || e instanceof CouponMinimumOrderException
                || e instanceof CouponNameException || e instanceof CouponStartDateException
                || e instanceof DuplicateCouponCodeException) {

            if (e instanceof CouponLimitCategoriesException) {
                CouponLimitCategoriesException clce = (CouponLimitCategoriesException) e;

                SessionErrors.add(actionRequest, e.getClass().getName(), clce.getCategoryIds());
            } else if (e instanceof CouponLimitSKUsException) {
                CouponLimitSKUsException clskue = (CouponLimitSKUsException) e;

                SessionErrors.add(actionRequest, e.getClass().getName(), clskue.getSkus());
            } else {
                SessionErrors.add(actionRequest, e.getClass().getName());
            }
        } else {
            throw e;
        }
    }
}

From source file:com.liferay.portlet.shopping.action.EditCouponAction.java

License:Open Source License

@Override
public ActionForward render(ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
        RenderRequest renderRequest, RenderResponse renderResponse) throws Exception {

    try {/*from ww w. j  a v  a2s .c o  m*/
        ActionUtil.getCoupon(renderRequest);
    } catch (Exception e) {
        if (e instanceof NoSuchCouponException || e instanceof PrincipalException) {

            SessionErrors.add(renderRequest, e.getClass().getName());

            return mapping.findForward("portlet.shopping.error");
        } else {
            throw e;
        }
    }

    return mapping.findForward(getForward(renderRequest, "portlet.shopping.edit_coupon"));
}

From source file:com.liferay.portlet.shopping.action.EditItemAction.java

License:Open Source License

@Override
public void processAction(ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
        ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

    String cmd = ParamUtil.getString(actionRequest, Constants.CMD);

    try {/*  w  w w  . ja va 2 s . c  o  m*/
        if (cmd.equals(Constants.ADD) || cmd.equals(Constants.UPDATE)) {
            updateItem(actionRequest);
        } else if (cmd.equals(Constants.DELETE)) {
            deleteItem(actionRequest);
        }

        if (Validator.isNotNull(cmd)) {
            sendRedirect(actionRequest, actionResponse);
        }
    } catch (Exception e) {
        if (e instanceof NoSuchCategoryException || e instanceof NoSuchItemException
                || e instanceof PrincipalException) {

            SessionErrors.add(actionRequest, e.getClass().getName());

            setForward(actionRequest, "portlet.shopping.error");
        } else if (e instanceof DuplicateItemSKUException || e instanceof ItemLargeImageNameException
                || e instanceof ItemLargeImageSizeException || e instanceof ItemMediumImageNameException
                || e instanceof ItemMediumImageSizeException || e instanceof ItemNameException
                || e instanceof ItemSKUException || e instanceof ItemSmallImageNameException
                || e instanceof ItemSmallImageSizeException) {

            SessionErrors.add(actionRequest, e.getClass().getName());
        } else {
            throw e;
        }
    }
}

From source file:com.liferay.portlet.shopping.action.EditItemAction.java

License:Open Source License

@Override
public ActionForward render(ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
        RenderRequest renderRequest, RenderResponse renderResponse) throws Exception {

    try {/*from   w w w .j av  a  2  s  .c  om*/
        ActionUtil.getItem(renderRequest);
    } catch (Exception e) {
        if (e instanceof NoSuchItemException || e instanceof PrincipalException) {

            SessionErrors.add(renderRequest, e.getClass().getName());

            return mapping.findForward("portlet.shopping.error");
        } else {
            throw e;
        }
    }

    return mapping.findForward(getForward(renderRequest, "portlet.shopping.edit_item"));
}

From source file:com.liferay.portlet.shopping.action.EditOrderAction.java

License:Open Source License

@Override
public void processAction(ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
        ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

    String cmd = ParamUtil.getString(actionRequest, Constants.CMD);

    try {/*ww  w  .  j  a v a2s . com*/
        if (cmd.equals(Constants.ADD) || cmd.equals(Constants.UPDATE)) {
            updateOrder(actionRequest);
        } else if (cmd.equals(Constants.DELETE)) {
            deleteOrders(actionRequest);
        } else if (cmd.equals("sendEmail")) {
            sendEmail(actionRequest);
        }

        sendRedirect(actionRequest, actionResponse);
    } catch (Exception e) {
        if (e instanceof NoSuchOrderException || e instanceof PrincipalException) {

            SessionErrors.add(actionRequest, e.getClass().getName());

            setForward(actionRequest, "portlet.shopping.error");
        } else {
            throw e;
        }
    }
}

From source file:com.liferay.portlet.shopping.action.EditOrderAction.java

License:Open Source License

@Override
public ActionForward render(ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
        RenderRequest renderRequest, RenderResponse renderResponse) throws Exception {

    try {// w w  w .  j ava  2s . co m
        ActionUtil.getOrder(renderRequest);
    } catch (Exception e) {
        if (e instanceof NoSuchOrderException || e instanceof PrincipalException) {

            SessionErrors.add(renderRequest, e.getClass().getName());

            return mapping.findForward("portlet.shopping.error");
        } else {
            throw e;
        }
    }

    return mapping.findForward(getForward(renderRequest, "portlet.shopping.edit_order"));
}

From source file:com.liferay.portlet.shopping.action.ViewAction.java

License:Open Source License

@Override
public ActionForward render(ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
        RenderRequest renderRequest, RenderResponse renderResponse) throws Exception {

    try {//  w  ww.  j  a  v  a  2 s .  com
        ActionUtil.getCategory(renderRequest);
    } catch (Exception e) {
        if (e instanceof NoSuchCategoryException || e instanceof PrincipalException) {

            SessionErrors.add(renderRequest, e.getClass().getName());

            return mapping.findForward("portlet.shopping.error");
        } else {
            throw e;
        }
    }

    return mapping.findForward("portlet.shopping.view");
}

From source file:com.liferay.portlet.shopping.action.ViewCouponAction.java

License:Open Source License

@Override
public ActionForward render(ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
        RenderRequest renderRequest, RenderResponse renderResponse) throws Exception {

    try {//  w  ww.j ava  2  s  .  c  om
        long couponId = ParamUtil.getLong(renderRequest, "couponId");

        String code = ParamUtil.getString(renderRequest, "code");

        ShoppingCoupon coupon = null;

        if (couponId > 0) {
            coupon = ShoppingCouponLocalServiceUtil.getCoupon(couponId);
        } else {
            coupon = ShoppingCouponLocalServiceUtil.getCoupon(code);
        }

        renderRequest.setAttribute(WebKeys.SHOPPING_COUPON, coupon);
    } catch (Exception e) {
        if (e instanceof NoSuchCouponException || e instanceof PrincipalException) {

            SessionErrors.add(renderRequest, e.getClass().getName());

            return mapping.findForward("portlet.shopping.error");
        } else {
            throw e;
        }
    }

    return mapping.findForward("portlet.shopping.view_coupon");
}

From source file:com.liferay.portlet.sites.action.EditGroupAction.java

License:Open Source License

@Override
public void processAction(ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
        ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    String cmd = ParamUtil.getString(actionRequest, Constants.CMD);

    String redirect = ParamUtil.getString(actionRequest, "redirect");

    try {/*  w ww . jav  a  2 s. c  o m*/
        String closeRedirect = ParamUtil.getString(actionRequest, "closeRedirect");

        if (cmd.equals(Constants.ADD) || cmd.equals(Constants.UPDATE)) {
            Object[] returnValue = updateGroup(actionRequest);

            Group group = (Group) returnValue[0];
            String oldFriendlyURL = (String) returnValue[1];
            String oldStagingFriendlyURL = (String) returnValue[2];
            long newRefererPlid = (Long) returnValue[3];

            redirect = HttpUtil.setParameter(redirect, "doAsGroupId", group.getGroupId());
            redirect = HttpUtil.setParameter(redirect, "refererPlid", newRefererPlid);

            closeRedirect = updateCloseRedirect(closeRedirect, group, themeDisplay, oldFriendlyURL,
                    oldStagingFriendlyURL);
        } else if (cmd.equals(Constants.DEACTIVATE) || cmd.equals(Constants.RESTORE)) {

            updateActive(actionRequest, cmd);
        } else if (cmd.equals(Constants.DELETE)) {
            deleteGroup(actionRequest);
        }

        if (Validator.isNotNull(closeRedirect)) {
            SessionMessages.add(actionRequest,
                    portletConfig.getPortletName() + SessionMessages.KEY_SUFFIX_CLOSE_REDIRECT, closeRedirect);
        }

        sendRedirect(actionRequest, actionResponse, redirect);
    } catch (Exception e) {
        if (e instanceof NoSuchGroupException || e instanceof PrincipalException) {

            SessionErrors.add(actionRequest, e.getClass().getName());

            setForward(actionRequest, "portlet.sites_admin.error");
        } else if (e instanceof AssetCategoryException || e instanceof AssetTagException
                || e instanceof DuplicateGroupException || e instanceof GroupFriendlyURLException
                || e instanceof GroupNameException || e instanceof LayoutSetVirtualHostException
                || e instanceof RemoteExportException || e instanceof RemoteOptionsException
                || e instanceof RequiredGroupException || e instanceof SystemException) {

            SessionErrors.add(actionRequest, e.getClass().getName(), e);

            if (cmd.equals(Constants.DEACTIVATE) || cmd.equals(Constants.DELETE)
                    || cmd.equals(Constants.RESTORE)) {

                if (Validator.isNotNull(redirect)) {
                    actionResponse.sendRedirect(redirect);
                }
            }
        } else {
            throw e;
        }
    }
}

From source file:com.liferay.portlet.sites.action.EditGroupAction.java

License:Open Source License

@Override
public ActionForward render(ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
        RenderRequest renderRequest, RenderResponse renderResponse) throws Exception {

    try {/*www. j a  va2  s  . c  o m*/
        ActionUtil.getGroup(renderRequest);
    } catch (Exception e) {
        if (e instanceof NoSuchGroupException || e instanceof PrincipalException) {

            SessionErrors.add(renderRequest, e.getClass().getName());

            return mapping.findForward("portlet.sites_admin.error");
        } else {
            throw e;
        }
    }

    return mapping.findForward(getForward(renderRequest, "portlet.sites_admin.edit_site"));
}