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

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

Introduction

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

Prototype

public static void clear(PortletRequest portletRequest) 

Source Link

Usage

From source file:com.liferay.portlet.layoutsadmin.action.EditLayoutsAction.java

License:Open Source License

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

    try {/* w w  w .  ja  v  a2s .c om*/
        checkPermissions(actionRequest);
    } catch (PrincipalException pe) {
        return;
    }

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

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

    //Modification start
    SessionErrorsUtil.clear(actionRequest);
    SessionErrors.clear(actionRequest);
    //Modification end

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

        Layout layout = null;
        String oldFriendlyURL = StringPool.BLANK;

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

            layout = (Layout) returnValue[0];
            oldFriendlyURL = (String) returnValue[1];

            redirect = updateCloseRedirect(redirect, null, layout, oldFriendlyURL);
            closeRedirect = updateCloseRedirect(closeRedirect, null, layout, oldFriendlyURL);
        } else if (cmd.equals(Constants.DELETE)) {
            Object[] returnValue = SitesUtil.deleteLayout(actionRequest, actionResponse);

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

            redirect = updateCloseRedirect(redirect, group, null, oldFriendlyURL);
            redirect = HttpUtil.setParameter(redirect, "refererPlid", newRefererPlid);
            // ===================== start of change https://jira.playtech.corp/browse/WPL-2040
            redirect = HttpUtil.setParameter(redirect, actionResponse.getNamespace() + "selPlid",
                    newRefererPlid);
            // ===================== end of change
            closeRedirect = updateCloseRedirect(closeRedirect, group, null, oldFriendlyURL);
        } else if (cmd.equals("copy_from_live")) {
            StagingUtil.copyFromLive(actionRequest);
        } else if (cmd.equals("display_order")) {
            updateDisplayOrder(actionRequest);
        } else if (cmd.equals("delete_layout_revision")) {
            deleteLayoutRevision(actionRequest);
        } else if (cmd.equals("enable")) {
            enableLayout(actionRequest);
        } else if (cmd.equals("publish_to_live")) {
            StagingUtil.publishToLive(actionRequest);
        } else if (cmd.equals("publish_to_remote")) {
            StagingUtil.publishToRemote(actionRequest);
        } else if (cmd.equals("reset_customized_view")) {
            LayoutTypePortlet layoutTypePortlet = themeDisplay.getLayoutTypePortlet();

            if ((layoutTypePortlet != null) && layoutTypePortlet.isCustomizable()
                    && layoutTypePortlet.isCustomizedView()) {

                layoutTypePortlet.resetUserPreferences();
            }
        } else if (cmd.equals("reset_prototype")) {
            SitesUtil.resetPrototype(themeDisplay.getLayout());
        } else if (cmd.equals("schedule_copy_from_live")) {
            StagingUtil.scheduleCopyFromLive(actionRequest);
        } else if (cmd.equals("schedule_publish_to_live")) {
            StagingUtil.schedulePublishToLive(actionRequest);
        } else if (cmd.equals("schedule_publish_to_remote")) {
            StagingUtil.schedulePublishToRemote(actionRequest);
        } else if (cmd.equals("select_layout_set_branch")) {
            selectLayoutSetBranch(actionRequest);
        } else if (cmd.equals("select_layout_branch")) {
            selectLayoutBranch(actionRequest);
        } else if (cmd.equals("unschedule_copy_from_live")) {
            StagingUtil.unscheduleCopyFromLive(actionRequest);
        } else if (cmd.equals("unschedule_publish_to_live")) {
            StagingUtil.unschedulePublishToLive(actionRequest);
        } else if (cmd.equals("unschedule_publish_to_remote")) {
            StagingUtil.unschedulePublishToRemote(actionRequest);
        } else if (cmd.equals("update_layout_revision")) {
            updateLayoutRevision(actionRequest, themeDisplay);
        }

        if (Validator.isNotNull(closeRedirect)) {
            LiferayPortletConfig liferayPortletConfig = (LiferayPortletConfig) portletConfig;

            SessionMessages.add(actionRequest,
                    liferayPortletConfig.getPortletId() + SessionMessages.KEY_SUFFIX_CLOSE_REDIRECT,
                    closeRedirect);
        }

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

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

            setForward(actionRequest, "portlet.layouts_admin.error");
        } else if (e instanceof ImageTypeException || e instanceof LayoutFriendlyURLException
                || e instanceof LayoutHiddenException || e instanceof LayoutNameException
                || e instanceof LayoutParentLayoutIdException || e instanceof LayoutSetVirtualHostException
                || e instanceof LayoutTypeException || e instanceof RequiredLayoutException
                || e instanceof UploadException) {

            if (e instanceof LayoutFriendlyURLException) {
                SessionErrors.add(actionRequest, LayoutFriendlyURLException.class.getName(), e);
            } else {
                SessionErrors.add(actionRequest, e.getClass(), e);
            }
        } else if (e instanceof DuplicateLockException || e instanceof LayoutPrototypeException
                || e instanceof RemoteExportException || e instanceof RemoteOptionsException
                || e instanceof SystemException) {

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

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

            sendRedirect(actionRequest, actionResponse, redirect);
        } else {
            throw e;
        }
    } finally {
        SessionErrorsUtil.copyFromSessionErrors(actionRequest);
    }
}

From source file:com.liferay.so.announcements.portlet.AnnouncementsPortlet.java

License:Open Source License

public void saveEntry(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

    JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

    try {//ww w .j  a  va2 s  .  c om
        doSaveEntry(actionRequest, actionResponse);

        long entryId = ParamUtil.getLong(actionRequest, "entryId");

        if (entryId <= 0) {
            SessionMessages.add(actionRequest, "announcementAdded");
        } else {
            SessionMessages.add(actionRequest, "announcementUpdated");
        }

        LiferayPortletResponse liferayPortletResponse = (LiferayPortletResponse) actionResponse;

        PortletURL portletURL = liferayPortletResponse.createRenderURL();

        portletURL.setParameter("mvcPath", "/manage_entries.jsp");
        portletURL.setParameter("distributionScope", ParamUtil.getString(actionRequest, "distributionScope"));

        jsonObject.put("redirect", portletURL.toString());

        jsonObject.put("success", true);
    } catch (Exception e) {
        String message = null;

        if (e instanceof EntryContentException) {
            message = "please-enter-valid-content";
        } else if (e instanceof EntryDisplayDateException) {
            message = "please-enter-a-valid-display-date";
        } else if (e instanceof EntryExpirationDateException) {
            message = "please-enter-a-valid-expiration-date";
        } else if (e instanceof EntryTitleException) {
            message = "please-enter-a-valid-title";
        } else if (e instanceof EntryURLException) {
            message = "please-enter-a-valid-url";
        } else {
            throw new PortletException(e);
        }

        SessionErrors.clear(actionRequest);

        jsonObject.put("message", translate(actionRequest, message));
        jsonObject.put("success", false);
    }

    writeJSON(actionRequest, actionResponse, jsonObject);
}

From source file:org.oep.cmon.portlet.hosochungthuc.HoSoChungThucPortlet.java

License:Apache License

/**
 * This is function saveHoSoChungThuc// w  w  w  .j  a  v a2  s  .  c  om
 * Version: 1.0
 *  
 * History: 
 *   DATE        AUTHOR      DESCRIPTION 
 *  ------------------------------------------------- 
 *  3-March-2013  Nam Dinh    Create new
 * @param actionRequest
 * @param actionResponse
 * @throws PortalException
 * @throws SystemException
 * @throws IOException
 * @throws WindowStateException
 * @throws PortletModeException
 */
public void saveHoSoChungThuc(ActionRequest actionRequest, ActionResponse response)
        throws PortalException, SystemException, IOException, WindowStateException, PortletModeException {
    UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(actionRequest);

    HoSoChungThuc hsChungThuc = ChungThucUtils.fillDataHoSoChungThuc(uploadRequest);

    if (ChungThucValidator.hoSoChungThucValidate(uploadRequest, actionRequest)) {
        if (hsChungThuc.getHoSoChungThucId() == 0) {
            long idHoSo = CounterLocalServiceUtil.increment(HoSoChungThuc.class.getName());
            hsChungThuc.setHoSoChungThucId(idHoSo);
            HoSoChungThucLocalServiceUtil.addHoSoChungThuc(hsChungThuc);

        } else {
            HoSoChungThucLocalServiceUtil.updateHoSoChungThuc(hsChungThuc);

            // delete current thanh phan ho so
            ThanhPhanHoSoChungThucLocalServiceUtil
                    .removeThanhPhanHoSoByHSChungThucId(hsChungThuc.getHoSoChungThucId());
        }

        ChungThucUtils.saveThanhPhanHoSoChungThuc(uploadRequest, hsChungThuc.getHoSoChungThucId(),
                hsChungThuc.getThuTucHanhChinhId());

        SessionErrors.clear(actionRequest);
        actionRequest.setAttribute("savemessage", " lu h s chng thc");

        hsChungThuc.setTenChungThuc("");
    }

    //      else {
    //         actionRequest.setAttribute(Constants.ChungThuc.NAME, 
    //               ChungThucUtils.fillDataHoSoChungThuc(uploadRequest));
    //      }
    //      
    actionRequest.setAttribute(Constants.ChungThuc.NAME, hsChungThuc);
}

From source file:org.oep.cmon.portlet.hosochungthuc.HoSoChungThucPortlet.java

License:Apache License

/**
 * This is function saveSoDanhMuc/*from ww w. j  av a 2 s .c  om*/
 * Version: 1.0
 *  
 * History: 
 *   DATE        AUTHOR      DESCRIPTION 
 *  ------------------------------------------------- 
 *  3-March-2013  Nam Dinh    Create new
 * @param actionRequest
 * @param actionResponse
 * @throws PortalException
 * @throws SystemException
 */
public void saveSoDanhMuc(ActionRequest actionRequest, ActionResponse actionResponse)
        throws PortalException, SystemException {
    if (ChungThucValidator.soDanhMucValidator(actionRequest)) {
        SoDanhMuc soDanhMuc = ChungThucUtils.fillDataSoDanhMuc(actionRequest);

        if (soDanhMuc.getId() == 0) {
            long idHoSo = CounterLocalServiceUtil.increment(SoDanhMuc.class.getName());
            soDanhMuc.setId(idHoSo);

            SoDanhMucLocalServiceUtil.addSoDanhMuc(soDanhMuc);

            //ChungThucUtils.saveThanhPhanHoSoChungThuc(uploadRequest, idHoSo);
        } else {
            SoDanhMucLocalServiceUtil.updateSoDanhMuc(soDanhMuc);
        }

        SessionErrors.clear(actionRequest);
        actionRequest.setAttribute("savemessage", " lu s danh mc");

    } else {
        actionResponse.setRenderParameter("jspPage", ParamUtil.getString(actionRequest, "targetPage"));
    }

    actionRequest.setAttribute(Constants.ChungThuc.SO_DANH_MUC_NAME,
            ChungThucUtils.fillDataSoDanhMuc(actionRequest));

}

From source file:org.oep.cmon.portlet.ipmslist.business.FormOfflineBusiness.java

License:Apache License

/**
 * This is function validationData/*from  www  . j av  a 2 s  .c  om*/
 * Version: 1.0
 *  
 * History: 
 *   DATE        AUTHOR      DESCRIPTION 
 *  ------------------------------------------------- 
 *  3-March-2013  Nam Dinh    Create new
 * @param firstName
 * @param middleName
 * @param lastName
 * @param cmnd
 * @param ngaySinh
 * @param idGioiTinh
 * @param idXaHienTai
 * @param actionRequest
 * @return boolean
 */
private boolean validationData(String firstName, String middleName, String lastName, String cmnd,
        String ngaySinh, String idGioiTinh, String numberHome, String idTinhHienTai, String idHuyenHienTai,
        String idXaHienTai, ActionRequest actionRequest) {
    SessionErrors.clear(actionRequest);
    if (firstName.length() == 0) {
        SessionErrors.add(actionRequest, "requireFirstName");
    }
    //      if (middleName.trim().length() == 0) {
    //         SessionErrors.add(actionRequest, "requireMiddleName");
    //      }
    if (lastName.length() == 0) {
        SessionErrors.add(actionRequest, "requireLastName");
    }
    if (cmnd.length() == 0) {
        SessionErrors.add(actionRequest, "requireCMND");
    } else {
        if (ConvertUtil.convertToLong(cmnd) <= 0) {
            SessionErrors.add(actionRequest, "numberCMND");
        } else if (cmnd.length() != 9 && cmnd.length() != 12) {
            SessionErrors.add(actionRequest, "arrangeCMND");
        } else {
            List<CongDan> listCongDan = findByCMND(cmnd);
            if (listCongDan.size() > 0) {
                SessionErrors.add(actionRequest, "exitCMND");
            }
        }
    }
    if (ngaySinh.length() == 0) {
        SessionErrors.add(actionRequest, "requireNgaySinh");
    } else {
        Date currentDate = new Date();
        if (ngaySinh.trim().length() > 0
                && ConvertUtil.parseStringToDate(ngaySinh.trim()).compareTo(currentDate) > 0) {
            //if (ConvertUtil.parseStringToDate(ngaySinh.trim()).compareTo(new Date()) > 0 || ngaySinh.trim().equals(ConvertUtil.parseDateToTring(new Date()))) {
            SessionErrors.add(actionRequest, "invalidNgaySinh");
        }
    }
    if (ConvertUtil.convertToInt(idGioiTinh) == 0) {
        SessionErrors.add(actionRequest, "requireGioiTinh");
    }
    if (numberHome.length() == 0) {
        SessionErrors.add(actionRequest, "requireNumberhome");
    }
    if (ConvertUtil.convertToInt(idTinhHienTai) == 0) {
        SessionErrors.add(actionRequest, "requireTinh");
    }
    if (ConvertUtil.convertToInt(idHuyenHienTai) == 0) {
        SessionErrors.add(actionRequest, "requireHuyen");
    }
    if (ConvertUtil.convertToInt(idXaHienTai) == 0) {
        SessionErrors.add(actionRequest, "requireXa");
    }

    if (SessionErrors.isEmpty(actionRequest)) {
        return true;
    }

    return false;
}

From source file:org.oep.cmon.portlet.ipmslist.business.FormOfflineBusiness.java

License:Apache License

/**
 * This is function validationDataDoanhNghiep
 * Version: 1.0//  w w w.j a  v a2s. c o  m
 *  
 * History: 
 *   DATE        AUTHOR      DESCRIPTION 
 *  ------------------------------------------------- 
 *  3-March-2013  Nam Dinh    Create new
 * @param maSoDoanhNghiep
 * @param maSothueDoanhNghiep
 * @param tenDoanhNghiep
 * @param soGiayPhepDangKyDoanhNghiep
 * @param ngayCapGiayPhepDangKyDoanhNghiep
 * @param tongSoVon
 * @param idLoaiDoiTuong
 * @param numberHome
 * @param idTinhHienTai
 * @param idHuyenHienTai
 * @param idXaHienTai
 * @param moTaNganhNgheKinhDoanh
 * @param quocGiaId
 * @param idTrangThai
 * @param actionRequest
 * @return boolean
 */
private boolean validationDataDoanhNghiep(String maSoDoanhNghiep, String maSothueDoanhNghiep,
        String tenDoanhNghiep, String soGiayPhepDangKyDoanhNghiep, String ngayCapGiayPhepDangKyDoanhNghiep,
        String tongSoVon, String idLoaiDoiTuong, String numberHome, String idTinhHienTai, String idHuyenHienTai,
        String idXaHienTai, String moTaNganhNgheKinhDoanh, String quocGiaId, String idTrangThai,
        ActionRequest actionRequest) {
    SessionErrors.clear(actionRequest);
    if (tenDoanhNghiep.length() == 0) {
        SessionErrors.add(actionRequest, "requireTenDoanhNghiep");
    } else {
        DoanhNghiep doanhNghiep = DoanhNghiepLocalServiceUtil.findByTen(tenDoanhNghiep);
        if (doanhNghiep != null) {
            SessionErrors.add(actionRequest, "exitTenDoanhNghiep");
        }
    }
    if (ngayCapGiayPhepDangKyDoanhNghiep.trim().length() == 0) {
        SessionErrors.add(actionRequest, "requireNgayCapGiayPhepDangKyDoanhNghiep");
    } else {
        if (ConvertUtil.parseStringToDate(ngayCapGiayPhepDangKyDoanhNghiep).after(new Date())) {
            SessionErrors.add(actionRequest, "afterNgayCapGiayPhepDangKyDoanhNghiep");
        }
    }
    if (moTaNganhNgheKinhDoanh.length() == 0) {
        SessionErrors.add(actionRequest, "requireMoTaNganhNgheKinhDoanh");
    }

    if (maSoDoanhNghiep.trim().length() == 0) {
        SessionErrors.add(actionRequest, "requireMaSoDoanhNghiep");
    } else if (ConvertUtil.convertToLong(maSoDoanhNghiep) <= 0) {
        SessionErrors.add(actionRequest, "numberMaSoDoanhNghiep");
    } else {
        DoanhNghiep doanhNghiep = DoanhNghiepLocalServiceUtil.findByMaDoanhNghiep(maSoDoanhNghiep);
        if (doanhNghiep != null) {
            SessionErrors.add(actionRequest, "exitMaSoDoanhNghiep");
        }
    }
    if (maSothueDoanhNghiep.trim().length() == 0) {
        SessionErrors.add(actionRequest, "requireMaSothueDoanhNghiep");
    } else if (ConvertUtil.convertToLong(maSothueDoanhNghiep) <= 0) {
        SessionErrors.add(actionRequest, "numberMaSothueDoanhNghiep");
    } else {
        DoanhNghiep doanhNghiep = DoanhNghiepLocalServiceUtil.findByMaSoThue(maSothueDoanhNghiep);
        if (doanhNghiep != null) {
            SessionErrors.add(actionRequest, "exitMaSothueDoanhNghiep");
        }
    }
    if (soGiayPhepDangKyDoanhNghiep.trim().length() == 0) {
        SessionErrors.add(actionRequest, "requireSoGiayPhepDangKyDoanhNghiep");
    } else if (ConvertUtil.convertToLong(soGiayPhepDangKyDoanhNghiep) <= 0) {
        SessionErrors.add(actionRequest, "numberSoGiayPhepDangKyDoanhNghiep");
    } else {
        DoanhNghiep doanhNghiep = DoanhNghiepLocalServiceUtil.findBySoGCNDKKD(soGiayPhepDangKyDoanhNghiep);
        if (doanhNghiep != null) {
            SessionErrors.add(actionRequest, "exitSoGiayPhepDangKyDoanhNghiep");
        }
    }
    if (tongSoVon.trim().length() == 0) {
        SessionErrors.add(actionRequest, "requireTongSoVon");
    } else if (ConvertUtil.convertToLong(tongSoVon) <= 0) {
        SessionErrors.add(actionRequest, "numberTongSoVon");
    }
    if (ConvertUtil.convertToLong(quocGiaId) <= 0) {
        SessionErrors.add(actionRequest, "numberQuocGia");
    }
    if (ConvertUtil.convertToLong(idLoaiDoiTuong) <= 0) {
        SessionErrors.add(actionRequest, "numberLoaiDoiTuong");
    }
    if (numberHome.length() == 0) {
        SessionErrors.add(actionRequest, "requireNumberhome");
    }
    if (ConvertUtil.convertToInt(idTinhHienTai) == 0) {
        SessionErrors.add(actionRequest, "requireTinh");
    }
    if (ConvertUtil.convertToInt(idHuyenHienTai) == 0) {
        SessionErrors.add(actionRequest, "requireHuyen");
    }
    if (ConvertUtil.convertToInt(idXaHienTai) == 0) {
        SessionErrors.add(actionRequest, "requireXa");
    }
    if (ConvertUtil.convertToLong(idTrangThai) <= 0) {
        SessionErrors.add(actionRequest, "numberIdTrangThai");
    }

    if (SessionErrors.isEmpty(actionRequest)) {
        return true;
    }

    return false;
}