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.ps.pt.configuration.Action.java

License:Open Source License

@Override
public void processAction(PortletConfig portletConfig, ActionRequest actionRequest,
        ActionResponse actionResponse) throws Exception {
    String portletResource = ParamUtil.getString(actionRequest, "portletResource");

    PortletPreferences prefs = PortletPreferencesFactoryUtil.getPortletSetup(actionRequest, portletResource);
    prefs.setValue(PUB_KEY, actionRequest.getParameter("pub"));
    prefs.setValue(SUB_KEY, actionRequest.getParameter("sub"));
    prefs.setValue(SSL_KEY, actionRequest.getParameter("ssl"));
    prefs.store();// w w w.j  a va2s  .  c o m

    actionRequest.setAttribute(PUB_KEY, prefs.getValue(Action.PUB_KEY, ""));
    actionRequest.setAttribute(SUB_KEY, prefs.getValue(Action.SUB_KEY, ""));
    actionRequest.setAttribute(SSL_KEY, prefs.getValue(Action.SSL_KEY, ""));

    SessionMessages.add(actionRequest, portletConfig.getPortletName() + ".doConfigure");
}

From source file:com.rcs.portlet.slider.action.ConfigurationActionImpl.java

License:Apache License

@Override
public void processAction(PortletConfig portletConfig, ActionRequest request, ActionResponse response)
        throws Exception {

    String cmd = request.getParameter(SliderConstants.CMD);

    if (Validator.isNull(cmd)) {
        throw new Exception("exception-occurred");
    }//from ww  w .  j a  v  a  2s .  c  o m
    try {
        if (cmd.equals(SliderConstants.UPDATE)) {
            savePreferences(request, response);
            response.setRenderParameter("tab", "slides");
        } else if (cmd.equals(SliderConstants.UPDATE_SETTINGS)) {
            String tab = ParamUtil.getString(request, "tab");
            if (tab != null) {
                response.setRenderParameter("tab", tab);
            }
            updateSettings(request, response);
        } else if (cmd.equals(SliderConstants.DELETE)) {
            deleteSlide(request, response);
            response.setRenderParameter("tab", "slides");
        }

        SessionMessages.add(request, "request-successfully");
    } catch (Exception e) {
        _log.error(e.getMessage());
        SessionErrors.add(request, e.getMessage());
    }
}

From source file:com.rcs.portlet.slider.action.ConfigurationActionImpl.java

License:Apache License

private void processRequest(PortletRequest request, PortletResponse response, String cmd) {

    try {//w  ww. ja v  a2  s.c o m
        if (cmd.equals(SliderConstants.DELETE)) {
            deleteSlide(request, response);
        } else if (cmd.equals(SliderConstants.SLIDE_MOVE_DOWN)) {
            updateSlideOrder(request, response, true);
        } else if (cmd.equals(SliderConstants.SLIDE_MOVE_UP)) {
            updateSlideOrder(request, response, false);
        }

        SessionMessages.add(request, "request-successfully");
    } catch (Exception e) {
        _log.error(e.getMessage());
        SessionErrors.add(request, e.getMessage());
    }
}

From source file:com.rivetlogic.ecommerce.portlet.ShoppingCartPortlet.java

License:Open Source License

public void checkout(ActionRequest request, ActionResponse response) throws IOException {

    SessionMessages.add(request,
            PortalUtil.getPortletId(request) + SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_ERROR_MESSAGE);
    SessionMessages.add(request,// ww w .jav  a  2s.co  m
            PortalUtil.getPortletId(request) + SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_SUCCESS_MESSAGE);

    String redirect = ParamUtil.getString(request, WebKeys.REDIRECT);

    if (!validateCheckoutInfo(request)) {
        SessionErrors.add(request, ShoppingCartPortletConstants.MESSAGE_MISSING_REQUIRED_CHECKOUT_INFO);
        response.sendRedirect(redirect);
    }
    if (!(new ShoppingCartPrefsBean(request).isCartPrefsValidForCheckout())) {
        SessionErrors.add(request, ShoppingCartPortletConstants.ERROR_MESSAGE_CHECKOUT);
        logger.error(ERROR_CHECKOUT_MISSING_PORTLET_CONFIG);
        response.sendRedirect(redirect);
    }
    try {
        doCheckout(request, response);
    } catch (Exception e) {
        SessionErrors.add(request, ShoppingCartPortletConstants.ERROR_MESSAGE_CHECKOUT);
        logger.error(e.getMessage());
    }

    response.sendRedirect(redirect);
}

From source file:com.rivetlogic.ecommerce.portlet.ShoppingCartPortlet.java

License:Open Source License

private void doCheckout(ActionRequest request, ActionResponse response) throws Exception {
    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
    ShoppingOrder activeShoppingOrder = null;
    List<String> orderItemsIdsList = null;

    if (themeDisplay.isSignedIn()) {
        activeShoppingOrder = ShoppingOrderLocalServiceUtil.getUserActiveOrder(themeDisplay.getUserId(),
                themeDisplay.getCompanyGroupId(), themeDisplay.getCompanyId(), Boolean.TRUE);
        List<ShoppingOrderItem> orderItemsList = ShoppingOrderItemLocalServiceUtil
                .findByOrderId(activeShoppingOrder.getOrderId());
        if (null == orderItemsList || orderItemsList.isEmpty())
            return;
    } else {//  w w w  .j a  v a 2 s .  c om
        orderItemsIdsList = getOrderItemsIdsFromSession(request);
        if (null != orderItemsIdsList) {
            activeShoppingOrder = ShoppingOrderLocalServiceUtil
                    .createOrder(CounterLocalServiceUtil.increment(ShoppingOrderItem.class.getName()));
            activeShoppingOrder.setUserId(-1l);
            activeShoppingOrder.setUserName(RoleConstants.GUEST);
        }
    }
    activeShoppingOrder.setCustomerName(
            ParamUtil.getString(request, ShoppingCartPortletConstants.CHECKOUT_PARAMETER_NAME));
    activeShoppingOrder.setCustomerEmail(
            ParamUtil.getString(request, ShoppingCartPortletConstants.CHECKOUT_PARAMETER_EMAIL));
    activeShoppingOrder.setShippingAddress1(
            ParamUtil.getString(request, ShoppingCartPortletConstants.CHECKOUT_PARAMETER_ADDRESS_1));
    activeShoppingOrder.setShippingAddress2(
            ParamUtil.getString(request, ShoppingCartPortletConstants.CHECKOUT_PARAMETER_ADDRESS_2));
    activeShoppingOrder.setShippingCity(
            ParamUtil.getString(request, ShoppingCartPortletConstants.CHECKOUT_PARAMETER_CITY));
    activeShoppingOrder.setShippingStateProvince(
            ParamUtil.getString(request, ShoppingCartPortletConstants.CHECKOUT_PARAMETER_STATE_PROVINCE));
    activeShoppingOrder.setShippingPostalCode(
            ParamUtil.getString(request, ShoppingCartPortletConstants.CHECKOUT_PARAMETER_POSTAL_CODE));
    activeShoppingOrder.setShippingCountry(
            ParamUtil.getString(request, ShoppingCartPortletConstants.CHECKOUT_PARAMETER_COUNTRY));
    activeShoppingOrder.setCustomerPhone(
            ParamUtil.getString(request, ShoppingCartPortletConstants.CHECKOUT_PARAMETER_PHONE));
    ShoppingCartPrefsBean cartPrefsBean = new ShoppingCartPrefsBean(request);
    Message customerMessage = getNotificationMessage(themeDisplay, activeShoppingOrder, orderItemsIdsList,
            cartPrefsBean, NotificationConstants.CUSTOMER_NOTIFICATION);
    Message storeMessage = getNotificationMessage(themeDisplay, activeShoppingOrder, orderItemsIdsList,
            cartPrefsBean, NotificationConstants.STORE_NOTIFICATION);
    ShoppingOrderLocalServiceUtil.placeOrder(activeShoppingOrder,
            new Message[] { customerMessage, storeMessage }, orderItemsIdsList);
    removeOrderItemsIdsFromSession(request);
    SessionMessages.add(request, ShoppingCartPortletConstants.SUCCESS_MESSAGE_CHECKOUT);
}

From source file:com.rivetlogic.event.portlet.EventPortlet.java

License:Open Source License

@Override
public void render(RenderRequest request, RenderResponse response) throws PortletException, IOException {

    String mvcPath = ParamUtil.getString(request, WebKeys.MVC_PATH);
    if (mvcPath.equals(WebKeys.EVENT_VIEW_PAGE)) {
        ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
        User user = themeDisplay.getUser();
        if (themeDisplay.isSignedIn()) {
            Participant participant = new ParticipantImpl();
            participant.setFullName(user.getFullName());
            participant.setEmail(user.getEmailAddress());

            try {
                List<Phone> phones = user.getPhones();
                if (phones.size() > 0) {
                    Phone phone = phones.get(0);
                    String phoneNumber = phone.getNumber();
                    if (phone.getExtension() != null && phone.getExtension().length() > 0) {
                        phoneNumber += " " + PHONE_EXTENSION_PREFIX + phone.getExtension();
                    }/*from w  w w  .j  av  a2 s.com*/
                    participant.setPhoneNumber(phoneNumber);
                }
            } catch (SystemException e) {
                _log.error(e.getMessage());
            }

            request.setAttribute(WebKeys.PARTICIPANT_ENTRY, participant);
        }

        try {
            EventActionUtil.loadEvent(request, true);
        } catch (SystemException e) {
            _log.error("Unable to load event");
            _log.debug(e);
        }
        // Remove default error message
        SessionMessages.add(request,
                PortalUtil.getPortletId(request) + SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_ERROR_MESSAGE);
    }

    super.render(request, response);
}

From source file:com.rivetlogic.event.portlet.EventPortlet.java

License:Open Source License

private void saveParticipant(ActionRequest request, ActionResponse response, Participant participant,
        String redirect) {/*w w  w.  j  a  v a2 s . c o  m*/

    verifyEvent(request, participant.getEventId());

    if (SessionErrors.isEmpty(request)) {
        try {
            participant.setStatus(EventConstant.EVENT_STATUS_ACCEPTER);
            participant = ParticipantLocalServiceUtil.addParticipant(participant);

            sendNotification(request, participant);
            SessionMessages.add(request, MESSAGE_REGISTRATION_SUCCESS);
            SessionMessages.add(request, MESSAGE_REGISTRATION_EMAIL);
            response.sendRedirect(redirect);
        } catch (Exception e) {
            _log.error(e);
            SessionErrors.add(request, ERROR_SAVING_PARTICIPANT);
        }
    }
}

From source file:com.rivetlogic.evernote.configuration.ConfigurationActionImpl.java

License:Open Source License

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

    PortletPreferences prefs = actionRequest.getPreferences();
    prefs.setValue(NOTES_LOADED, ParamUtil.getString(actionRequest, NOTES_LOADED));
    prefs.store();/*from  www  .  jav a2  s .com*/

    SessionMessages.add(actionRequest, SUCCESS_KEY);
}

From source file:com.rivetlogic.evernote.portlet.EvernotePortlet.java

License:Open Source License

@Override
public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException {

    PortletSession portletSession = request.getPortletSession();

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

    if (themeDisplay.isSignedIn()) {
        if (((String) portletSession.getAttribute(ACCESS_TOKEN)) != null) {
            request.setAttribute(ACCESS_TOKEN, (String) portletSession.getAttribute(ACCESS_TOKEN));
            request.setAttribute(NEED_AUTHORIZE, Boolean.FALSE);
        } else {/*from  w  w  w. j  ava  2s. c  o m*/
            request.setAttribute(NEED_AUTHORIZE, Boolean.TRUE);
            try {
                EvernoteUtil.authenticateEvernote(request, portletSession, themeDisplay);
            } catch (OAuthException e) {

                if (LOG.isDebugEnabled()) {
                    LOG.error(EVERNOTE_AUTHENTICATION_ERROR, e);
                }

                if (SessionErrors.isEmpty(request)) {
                    SessionMessages.add(request, request.getAttribute(WebKeys.PORTLET_ID)
                            + SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_ERROR_MESSAGE);
                }

                SessionErrors.add(request, OAuthException.class);
            }
        }
    }

    super.doView(request, response);
}

From source file:com.rivetlogic.geo.portlet.GeoLocationServicesPortlet.java

License:Open Source License

public void processGeoFiles(ActionRequest request, ActionResponse response) {
    UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(request);

    File locationsFile = uploadRequest.getFile(GeoServicesPortletConstants.ATTR_GEO_LOCATIONS_CSV);
    File blocksFile = uploadRequest.getFile(GeoServicesPortletConstants.ATTR_GEO_BLOCKS_CSV);

    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
    ServiceContext serviceContext = new ServiceContext();
    serviceContext.setScopeGroupId(themeDisplay.getScopeGroupId());

    try {//from   w  ww  .  j  a v a  2s .  c om
        InputStream locations = new FileInputStream(locationsFile);
        InputStream blocks = new FileInputStream(blocksFile);

        Message message = new Message();
        message.put(GeoServicesPortletConstants.ATTR_GEO_LOCATIONS_CSV, locations);
        message.put(GeoServicesPortletConstants.ATTR_GEO_BLOCKS_CSV, blocks);
        message.put(GeoServicesPortletConstants.RESPONSE_RECEIVER,
                GeoServicesPortletConstants.MESSAGE_RESPONSE);
        message.put(GeoServicesPortletConstants.USER_ID, themeDisplay.getUserId());
        MessageBusUtil.sendMessage(GeoServicesPortletConstants.MESSAGE_DESTINATION, message);

        SessionMessages.add(request, GeoServicesPortletConstants.UPLOAD_SUCCESS_KEY);
    } catch (FileNotFoundException e) {
        SessionErrors.add(request, GeoServicesPortletConstants.ERROR_PROCESSING_CSV);
        logger.error(e);
    }
}