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