001
014
015 package com.liferay.portlet.currencyconverter.action;
016
017 import com.liferay.portal.kernel.portlet.LiferayPortletConfig;
018 import com.liferay.portal.kernel.servlet.SessionErrors;
019 import com.liferay.portal.kernel.servlet.SessionMessages;
020 import com.liferay.portal.kernel.util.Constants;
021 import com.liferay.portal.kernel.util.ParamUtil;
022 import com.liferay.portal.kernel.util.StringUtil;
023 import com.liferay.portal.struts.PortletAction;
024
025 import javax.portlet.ActionRequest;
026 import javax.portlet.ActionResponse;
027 import javax.portlet.PortletConfig;
028 import javax.portlet.PortletPreferences;
029 import javax.portlet.RenderRequest;
030 import javax.portlet.RenderResponse;
031 import javax.portlet.ValidatorException;
032
033 import org.apache.struts.action.ActionForm;
034 import org.apache.struts.action.ActionForward;
035 import org.apache.struts.action.ActionMapping;
036
037
040 public class EditPreferencesAction extends PortletAction {
041
042 @Override
043 public void processAction(
044 ActionMapping actionMapping, ActionForm actionForm,
045 PortletConfig portletConfig, ActionRequest actionRequest,
046 ActionResponse actionResponse)
047 throws Exception {
048
049 String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
050
051 if (!cmd.equals(Constants.UPDATE)) {
052 return;
053 }
054
055 PortletPreferences portletPreferences = actionRequest.getPreferences();
056
057 String[] symbols = StringUtil.split(
058 StringUtil.toUpperCase(
059 ParamUtil.getString(actionRequest, "symbols")));
060
061 portletPreferences.setValues("symbols", symbols);
062
063 try {
064 portletPreferences.store();
065 }
066 catch (ValidatorException ve) {
067 SessionErrors.add(
068 actionRequest, ValidatorException.class.getName(), ve);
069
070 return;
071 }
072
073 LiferayPortletConfig liferayPortletConfig =
074 (LiferayPortletConfig)portletConfig;
075
076 SessionMessages.add(
077 actionRequest,
078 liferayPortletConfig.getPortletId() +
079 SessionMessages.KEY_SUFFIX_UPDATED_PREFERENCES);
080 }
081
082 @Override
083 public ActionForward render(
084 ActionMapping actionMapping, ActionForm actionForm,
085 PortletConfig portletConfig, RenderRequest renderRequest,
086 RenderResponse renderResponse)
087 throws Exception {
088
089 return actionMapping.findForward("portlet.currency_converter.edit");
090 }
091
092 }