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.my.account.web.internal.portlet.action.EditUserMVCRenderCommand.java

License:Open Source License

@Override
public String render(RenderRequest renderRequest, RenderResponse renderResponse) throws PortletException {

    try {//  w  ww  .j  av  a  2 s  . co  m
        User user = _portal.getUser(renderRequest);

        RenderRequestImpl renderRequestImpl = (RenderRequestImpl) renderRequest;

        DynamicServletRequest dynamicRequest = (DynamicServletRequest) renderRequestImpl
                .getHttpServletRequest();

        dynamicRequest.setParameter("p_u_i_d", String.valueOf(user.getUserId()));

        _portal.getSelectedUser(renderRequest);
    } catch (Exception e) {
        if (e instanceof PrincipalException) {
            SessionErrors.add(renderRequest, e.getClass());

            return "/error.jsp";
        } else {
            throw new PortletException(e);
        }
    }

    return "/edit_user.jsp";
}

From source file:com.liferay.my.account.web.internal.portlet.action.UpdatePasswordMVCActionCommand.java

License:Open Source License

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

    try {/*from   ww  w.j a v a  2s . c om*/
        authenticateUser(actionRequest, actionResponse);
    } catch (Exception e) {
        if (e instanceof NoSuchUserException || e instanceof PrincipalException) {

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

            actionResponse.setRenderParameter("mvcPath", "/error.jsp");
        } else if (e instanceof UserPasswordException) {
            SessionErrors.add(actionRequest, e.getClass(), e);

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

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

    _mvcActionCommand.processAction(actionRequest, actionResponse);
}

From source file:com.liferay.opensocial.adhocgadget.action.ConfigurationActionImpl.java

License:Open Source License

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

    String tabs2 = ParamUtil.get(actionRequest, "tabs2", "gadget");

    if (tabs2.equals("manage-oauth")) {
        ShindigUtil.updateOAuthConsumers(actionRequest, actionResponse);

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

        SessionMessages.add(actionRequest,
                PortalUtil.getPortletId(actionRequest) + SessionMessages.KEY_SUFFIX_REFRESH_PORTLET,
                portletResource);//from ww w  .ja v  a 2 s.  c o  m

        SessionMessages.add(actionRequest,
                PortalUtil.getPortletId(actionRequest) + SessionMessages.KEY_SUFFIX_UPDATED_CONFIGURATION);
    } else if (tabs2.equals("preferences")) {
        doProcessAction(portletConfig, actionRequest, actionResponse);
    } else {
        String url = getParameter(actionRequest, "url");

        try {
            ShindigUtil.getGadgetSpec(url, false, true);
        } catch (Exception e) {
            SessionErrors.add(actionRequest, e.getClass());
        }

        setPreference(actionRequest, "url", url);

        super.processAction(portletConfig, actionRequest, actionResponse);
    }
}

From source file:com.liferay.opensocial.portlet.AdminPortlet.java

License:Open Source License

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

    checkPermissions(actionRequest);/*  w  ww.ja  v a  2 s.  com*/

    try {
        doUpdateGadget(actionRequest, actionResponse);
    } catch (PortalException pe) {
        SessionErrors.add(actionRequest, pe.getClass().getName());
    }
}

From source file:com.liferay.osgiadmin.portlet.OSGiAdminPortlet.java

License:Open Source License

@Override
public void processAction(ActionRequest actionRequest, ActionResponse actionResponse)
        throws IOException, PortletException {

    try {/*from w  w w  .j  a  va  2 s . c  o m*/
        UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(actionRequest);

        String cmd = ParamUtil.getString(uploadRequest, Constants.CMD);
        File file = uploadRequest.getFile("importBundle");
        String location = ParamUtil.getString(uploadRequest, "location");

        if (cmd.equals("install-from-upload")) {
            if (Validator.isNull(location)) {
                location = uploadRequest.getFullFileName("importBundle");
            }

            if ((file == null) || !file.exists()) {
                throw new OSGiException("file-does-not-exist");
            }

            OSGiServiceUtil.addBundle(location, new FileInputStream(file));
        } else if (cmd.equals("install-from-remote-location")) {
            OSGiServiceUtil.addBundle(location);
        } else if (cmd.equals("update-from-upload")) {
            long bundleId = ParamUtil.getLong(uploadRequest, "bundleId");

            if ((file == null) || !file.exists()) {
                throw new OSGiException("file-does-not-exist");
            }

            OSGiServiceUtil.updateBundle(bundleId, new FileInputStream(file));
        } else if (cmd.equals("update-from-remote-location")) {
            long bundleId = ParamUtil.getLong(uploadRequest, "bundleId");

            OSGiServiceUtil.updateBundle(bundleId);
        } else if (cmd.equals("uninstall")) {
            long bundleId = ParamUtil.getLong(uploadRequest, "bundleId");

            OSGiServiceUtil.uninstallBundle(bundleId);
        }

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

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

From source file:com.liferay.plugins.admin.web.internal.portlet.action.EditPluginActionCommand.java

License:Open Source License

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

    try {/*from  ww w  .ja va 2s .  c  o m*/
        updatePluginSetting(actionRequest);
    } catch (Exception e) {
        if (e instanceof PrincipalException) {
            SessionErrors.add(actionRequest, e.getClass());

            sendRedirect(actionRequest, actionResponse, "/error.jsp");
        } else {
            throw e;
        }
    }
}

From source file:com.liferay.polls.web.internal.portlet.action.AddQuestionRedirectMVCRenderCommand.java

License:Open Source License

@Override
public String render(RenderRequest renderRequest, RenderResponse renderResponse) throws PortletException {

    try {//from  ww w  .  j a v  a  2 s . c  om
        ActionUtil.getQuestion(renderRequest);
    } catch (Exception e) {
        if (e instanceof NoSuchQuestionException || e instanceof PrincipalException) {

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

            return "/polls/error.jsp";
        } else {
            throw new PortletException(e);
        }
    }

    return "/polls/view_question.jsp";
}

From source file:com.liferay.polls.web.internal.portlet.action.EditQuestionMVCActionCommand.java

License:Open Source License

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

    PortletConfig portletConfig = (PortletConfig) actionRequest
            .getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG);

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

    try {//  www  . j av  a  2 s .  c  o m
        if (Validator.isNull(cmd)) {
            return;
        } else if (cmd.equals(Constants.ADD) || cmd.equals(Constants.UPDATE) || cmd.equals(Constants.VOTE)) {

            updateQuestion(portletConfig, actionRequest, actionResponse);
        } else if (cmd.equals(Constants.DELETE)) {
            deleteQuestion(actionRequest);
        }

        WindowState windowState = actionRequest.getWindowState();

        if (windowState.equals(LiferayWindowState.POP_UP)) {
            String redirect = portal.escapeRedirect(ParamUtil.getString(actionRequest, "redirect"));

            if (Validator.isNotNull(redirect)) {
                actionResponse.sendRedirect(redirect);
            }
        } else {
            sendRedirect(actionRequest, actionResponse);
        }
    } catch (Exception e) {
        if (e instanceof NoSuchQuestionException || e instanceof PrincipalException) {

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

            actionResponse.setRenderParameter("mvcPath", "/polls/error.jsp");
        } else if (e instanceof DuplicateVoteException || e instanceof NoSuchChoiceException
                || e instanceof QuestionChoiceException || e instanceof QuestionDescriptionException
                || e instanceof QuestionExpirationDateException || e instanceof QuestionTitleException) {

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

            hideDefaultErrorMessage(actionRequest);
        } else if (e instanceof QuestionExpiredException) {
        } else {
            throw e;
        }
    }
}

From source file:com.liferay.polls.web.internal.portlet.action.EditQuestionMVCRenderCommand.java

License:Open Source License

@Override
public String render(RenderRequest renderRequest, RenderResponse renderResponse) throws PortletException {

    try {/*from  w ww  . java  2  s.c o m*/
        ActionUtil.getQuestion(renderRequest);
    } catch (Exception e) {
        if (e instanceof NoSuchQuestionException || e instanceof PrincipalException) {

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

            return "/polls/error.jsp";
        } else {
            throw new PortletException(e);
        }
    }

    return "/polls/edit_question.jsp";
}

From source file:com.liferay.polls.web.internal.portlet.action.ViewActionMVCRenderCommand.java

License:Open Source License

@Override
public String render(RenderRequest renderRequest, RenderResponse renderResponse) throws PortletException {

    try {/*from   w ww  .  j  a  va  2s.co m*/
        PortletPreferences portletPreferences = renderRequest.getPreferences();

        long questionId = GetterUtil.getLong(portletPreferences.getValue("questionId", StringPool.BLANK));

        if (questionId > 0) {
            PollsQuestion question = _pollsQuestionService.getQuestion(questionId);

            renderRequest.setAttribute(PollsWebKeys.POLLS_QUESTION, question);
        }
    } catch (Exception e) {
        if (!(e instanceof NoSuchQuestionException)) {
            SessionErrors.add(renderRequest, e.getClass());

            return "/polls_display/error.jsp";
        }
    }

    return "/polls_display/view.jsp";
}