com.beorn.onlinepayment.shopping.action.ConfigurationActionImpl.java Source code

Java tutorial

Introduction

Here is the source code for com.beorn.onlinepayment.shopping.action.ConfigurationActionImpl.java

Source

/**
 * Copyright (c) 2007-2013 BEORN Technologies, SARL. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 3 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

package com.beorn.onlinepayment.shopping.action;

import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.PortletConfig;
import javax.portlet.PortletPreferences;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;

import com.liferay.portal.kernel.struts.BaseStrutsPortletAction;
import com.liferay.portal.kernel.util.ParamUtil;
import com.liferay.portal.kernel.util.WebKeys;
import com.liferay.portal.service.PortletPreferencesLocalServiceUtil;
import com.liferay.portal.theme.ThemeDisplay;
import com.liferay.portal.util.PortalUtil;

/**
 * @author Alaa Boutahar
 */
public class ConfigurationActionImpl extends BaseStrutsPortletAction {

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

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

        long companyId = PortalUtil.getCompanyId(actionRequest);
        long groupId = themeDisplay.getScopeGroupId();
        int ownerType = 2;
        long plid = 0;
        String portletId = "34";

        PortletPreferences portletPreferences = PortletPreferencesLocalServiceUtil.getPreferences(companyId,
                groupId, ownerType, plid, portletId);

        long sellerId = ParamUtil.getLong(actionRequest, "sellerId");
        String paymentType = ParamUtil.getString(actionRequest, "paymentType");

        portletPreferences.setValue("sellerId", String.valueOf(sellerId));
        portletPreferences.setValue("paymentType", String.valueOf(paymentType));

        portletPreferences.store();
    }

    @Override
    public String render(PortletConfig portletConfig, RenderRequest renderRequest, RenderResponse renderResponse)
            throws Exception {

        return "/portlet/shopping/configuration.jsp";
    }

}