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

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

Introduction

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

Prototype

public static void add(PortletRequest portletRequest, String key) 

Source Link

Usage

From source file:com.liferay.site.memberships.web.internal.portlet.SiteMembershipsPortlet.java

License:Open Source License

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

    Group group = _getGroup(actionRequest, actionResponse);

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

    long statusId = ParamUtil.getLong(actionRequest, "statusId");
    String replyComments = ParamUtil.getString(actionRequest, "replyComments");

    ServiceContext serviceContext = ServiceContextFactory.getInstance(actionRequest);

    _membershipRequestService.updateStatus(membershipRequestId, replyComments, statusId, serviceContext);

    if (statusId == MembershipRequestConstants.STATUS_APPROVED) {
        MembershipRequest membershipRequest = _membershipRequestService
                .getMembershipRequest(membershipRequestId);

        LiveUsers.joinGroup(group.getCompanyId(), membershipRequest.getGroupId(),
                new long[] { membershipRequest.getUserId() });
    }//from   w w w. ja v  a2s.  c o m

    SessionMessages.add(actionRequest, "membershipReplySent");

    sendRedirect(actionRequest, actionResponse);
}

From source file:com.liferay.site.my.sites.web.internal.portlet.MySitesPortlet.java

License:Open Source License

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

    long groupId = ParamUtil.getLong(actionRequest, "groupId");
    String comments = ParamUtil.getString(actionRequest, "comments");

    ServiceContext serviceContext = ServiceContextFactory.getInstance(actionRequest);

    long userId = serviceContext.getUserId();

    if (_membershipRequestLocalService.hasMembershipRequest(userId, groupId,
            MembershipRequestConstants.STATUS_PENDING)) {

        SessionErrors.add(actionRequest, "membershipAlreadyRequested");
    } else {/*from   w w w . java 2  s.co m*/
        _membershipRequestLocalService.addMembershipRequest(userId, groupId, comments, serviceContext);

        SessionMessages.add(actionRequest, "membershipRequestSent");

        addSuccessMessage(actionRequest, actionResponse);
    }

    sendRedirect(actionRequest, actionResponse);
}

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

License:Open Source License

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

    JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

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

    try {/*from  w w w . j a  v  a  2s  . c  om*/
        AnnouncementsEntryServiceUtil.deleteEntry(entryId);

        SessionMessages.add(actionRequest, "announcementDeleted");

        jsonObject.put("success", true);
    } catch (Exception e) {
        jsonObject.put("message", translate(actionRequest, "the-announcement-could-not-be-deleted"));
        jsonObject.put("success", false);
    }

    writeJSON(actionRequest, actionResponse, jsonObject);
}

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 {//  w w  w.  j av a  2 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:com.liferay.staging.bar.web.internal.portlet.action.DeleteLayoutBranchMVCActionCommand.java

License:Open Source License

@Override
protected void doProcessAction(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

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

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

    try {/*from  w w w .  j  a v  a 2 s.  c o m*/
        _layoutBranchService.deleteLayoutBranch(layoutBranchId);

        SessionMessages.add(actionRequest, "pageVariationDeleted");

        if (layoutBranchId == currentLayoutBranchId) {
            SessionMessages.add(actionRequest,
                    _portal.getPortletId(actionRequest) + SessionMessages.KEY_SUFFIX_PORTLET_NOT_AJAXABLE);
        }

        ActionUtil.addLayoutBranchSessionMessages(actionRequest, actionResponse);
    } catch (Exception e) {
        SessionErrors.add(actionRequest, e.getClass(), e);

        actionResponse.setRenderParameter("mvcPath", "/error.jsp");
    }
}

From source file:com.liferay.staging.bar.web.internal.portlet.action.DeleteLayoutSetBranchMVCActionCommand.java

License:Open Source License

@Override
protected void doProcessAction(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

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

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

    if (layoutSetBranchId == currentLayoutBranchId) {
        SessionMessages.add(actionRequest,
                _portal.getPortletId(actionRequest) + SessionMessages.KEY_SUFFIX_PORTLET_NOT_AJAXABLE);
    }//  ww w .ja  v  a  2  s . c  om

    try {
        _layoutSetBranchService.deleteLayoutSetBranch(layoutSetBranchId);

        SessionMessages.add(actionRequest, "sitePageVariationDeleted");

        ActionUtil.addLayoutBranchSessionMessages(actionRequest, actionResponse);
    } catch (Exception e) {
        SessionErrors.add(actionRequest, e.getClass(), e);

        actionResponse.setRenderParameter("mvcPath", "/error.jsp");
    }
}

From source file:com.liferay.staging.bar.web.internal.portlet.action.EditLayoutBranchMVCActionCommand.java

License:Open Source License

@Override
protected void doProcessAction(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

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

    long layoutRevisionId = ParamUtil.getLong(actionRequest, "copyLayoutRevisionId");
    String name = ParamUtil.getString(actionRequest, "name");
    String description = ParamUtil.getString(actionRequest, "description");

    ServiceContext serviceContext = ServiceContextFactory.getInstance(actionRequest);

    try {//from  w w w  .  j  a  va2s . c  om
        if (layoutBranchId <= 0) {
            _layoutBranchService.addLayoutBranch(layoutRevisionId, name, description, false, serviceContext);

            SessionMessages.add(actionRequest, "pageVariationAdded");
        } else {
            _layoutBranchService.updateLayoutBranch(layoutBranchId, name, description, serviceContext);

            SessionMessages.add(actionRequest, "pageVariationUpdated");
        }

        ActionUtil.addLayoutBranchSessionMessages(actionRequest, actionResponse);
    } catch (Exception e) {
        SessionErrors.add(actionRequest, e.getClass(), e);

        if (e instanceof LayoutBranchNameException) {
            actionResponse.setRenderParameter("mvcPath", "/edit_layout_branch.jsp");
        } else {
            actionResponse.setRenderParameter("mvcPath", "/error.jsp");
        }
    }
}

From source file:com.liferay.staging.bar.web.internal.portlet.action.EditLayoutSetBranchMVCActionCommand.java

License:Open Source License

@Override
protected void doProcessAction(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

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

    long groupId = ParamUtil.getLong(actionRequest, "groupId");
    boolean privateLayout = ParamUtil.getBoolean(actionRequest, "privateLayout");
    String name = ParamUtil.getString(actionRequest, "name");
    String description = ParamUtil.getString(actionRequest, "description");
    long copyLayoutSetBranchId = ParamUtil.getLong(actionRequest, "copyLayoutSetBranchId",
            LayoutSetBranchConstants.ALL_BRANCHES);

    ServiceContext serviceContext = ServiceContextFactory.getInstance(actionRequest);

    try {//from  ww w .ja  v a 2  s  .  co m
        if (layoutSetBranchId <= 0) {
            _layoutSetBranchService.addLayoutSetBranch(groupId, privateLayout, name, description, false,
                    copyLayoutSetBranchId, serviceContext);

            SessionMessages.add(actionRequest, "sitePageVariationAdded");
        } else {
            _layoutSetBranchLocalService.updateLayoutSetBranch(layoutSetBranchId, name, description,
                    serviceContext);

            SessionMessages.add(actionRequest, "sitePageVariationUpdated");
        }

        ActionUtil.addLayoutBranchSessionMessages(actionRequest, actionResponse);
    } catch (Exception e) {
        SessionErrors.add(actionRequest, e.getClass(), e);

        if (e instanceof LayoutSetBranchNameException) {
            actionResponse.setRenderParameter("mvcPath", "/edit_layout_set_branch.jsp");
        } else {
            actionResponse.setRenderParameter("mvcPath", "/error.jsp");
        }
    }
}

From source file:com.liferay.staging.bar.web.internal.portlet.action.MergeLayoutSetBranchMVCActionCommand.java

License:Open Source License

@Override
protected void doProcessAction(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

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

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

    ServiceContext serviceContext = ServiceContextFactory.getInstance(actionRequest);

    try {//  ww  w  .j a va  2 s . com
        _layoutSetBranchService.mergeLayoutSetBranch(layoutSetBranchId, mergeLayoutSetBranchId, serviceContext);

        SessionMessages.add(actionRequest, "sitePageVariationMerged");

        ActionUtil.addLayoutBranchSessionMessages(actionRequest, actionResponse);
    } catch (Exception e) {
        SessionErrors.add(actionRequest, e.getClass(), e);

        actionResponse.setRenderParameter("mvcPath", "/view_layout_set_branches.jsp");
    }
}

From source file:com.liferay.staging.configuration.web.internal.portlet.StagingConfigurationPortlet.java

License:Open Source License

public void editStagingConfiguration(ActionRequest actionRequest, ActionResponse actionResponse)
        throws IOException, PortalException, PortletException {

    hideDefaultSuccessMessage(actionRequest);

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

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

    Group liveGroup = _groupLocalService.getGroup(liveGroupId);

    int stagingType = ParamUtil.getInteger(actionRequest, "stagingType");

    boolean branchingPublic = ParamUtil.getBoolean(actionRequest, "branchingPublic");
    boolean branchingPrivate = ParamUtil.getBoolean(actionRequest, "branchingPrivate");

    ServiceContext serviceContext = ServiceContextFactory.getInstance(actionRequest);

    boolean forceDisable = ParamUtil.getBoolean(actionRequest, "forceDisable");

    boolean stagedGroup = true;

    if (forceDisable) {
        _groupLocalService.disableStaging(liveGroupId);
    } else if (stagingType == StagingConstants.TYPE_LOCAL_STAGING) {
        stagedGroup = liveGroup.hasStagingGroup();

        _stagingLocalService.enableLocalStaging(themeDisplay.getUserId(), liveGroup, branchingPublic,
                branchingPrivate, serviceContext);
    } else if (stagingType == StagingConstants.TYPE_REMOTE_STAGING) {
        String remoteAddress = ParamUtil.getString(actionRequest, "remoteAddress");
        int remotePort = ParamUtil.getInteger(actionRequest, "remotePort");
        String remotePathContext = ParamUtil.getString(actionRequest, "remotePathContext");
        boolean secureConnection = ParamUtil.getBoolean(actionRequest, "secureConnection");
        long remoteGroupId = ParamUtil.getLong(actionRequest, "remoteGroupId");

        stagedGroup = liveGroup.isStagedRemotely();

        _stagingLocalService.enableRemoteStaging(themeDisplay.getUserId(), liveGroup, branchingPublic,
                branchingPrivate, remoteAddress, remotePort, remotePathContext, secureConnection, remoteGroupId,
                serviceContext);//from w w w . java  2  s .  co m
    } else if (stagingType == StagingConstants.TYPE_NOT_STAGED) {
        _stagingLocalService.disableStaging(liveGroup, serviceContext);
    }

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

    if (!stagedGroup) {

        // Staging was turned on

        PortletURL portletURL = null;

        if (stagingType == StagingConstants.TYPE_LOCAL_STAGING) {
            portletURL = _portal.getControlPanelPortletURL(actionRequest, liveGroup.getStagingGroup(),
                    StagingProcessesPortletKeys.STAGING_PROCESSES, 0, 0, PortletRequest.RENDER_PHASE);
        } else if (stagingType == StagingConstants.TYPE_REMOTE_STAGING) {
            portletURL = _portal.getControlPanelPortletURL(actionRequest, liveGroup,
                    StagingProcessesPortletKeys.STAGING_PROCESSES, 0, 0, PortletRequest.RENDER_PHASE);
        }

        if (portletURL != null) {
            redirect = portletURL.toString();
        }
    } else if ((stagingType == StagingConstants.TYPE_NOT_STAGED)
            || (stagingType == StagingConstants.TYPE_REMOTE_STAGING)) {

        // Staging was turned off or remote staging configuration was
        // modified

        PortletURL portletURL = _portal.getControlPanelPortletURL(actionRequest, liveGroup,
                StagingProcessesPortletKeys.STAGING_PROCESSES, 0, 0, PortletRequest.RENDER_PHASE);

        portletURL.setParameter("showStagingConfiguration", Boolean.TRUE.toString());

        if (portletURL != null) {
            redirect = portletURL.toString();
        }

        if (stagingType == StagingConstants.TYPE_NOT_STAGED) {
            SessionMessages.add(actionRequest, "stagingDisabled");
        }
    } else {

        // Local staging configuration was modified

        PortletURL portletURL = _portal.getControlPanelPortletURL(actionRequest, liveGroup.getStagingGroup(),
                StagingProcessesPortletKeys.STAGING_PROCESSES, 0, 0, PortletRequest.RENDER_PHASE);

        portletURL.setParameter("showStagingConfiguration", Boolean.TRUE.toString());

        if (portletURL != null) {
            redirect = portletURL.toString();
        }
    }

    actionRequest.setAttribute(WebKeys.REDIRECT, redirect);

    sendRedirect(actionRequest, actionResponse);
}