001
014
015 package com.liferay.portlet.pollsdisplay.action;
016
017 import com.liferay.portal.kernel.servlet.SessionErrors;
018 import com.liferay.portal.kernel.util.GetterUtil;
019 import com.liferay.portal.kernel.util.StringPool;
020 import com.liferay.portal.security.auth.PrincipalException;
021 import com.liferay.portal.struts.PortletAction;
022 import com.liferay.portal.util.WebKeys;
023 import com.liferay.portlet.polls.NoSuchQuestionException;
024 import com.liferay.portlet.polls.model.PollsQuestion;
025 import com.liferay.portlet.polls.service.PollsQuestionServiceUtil;
026
027 import javax.portlet.PortletConfig;
028 import javax.portlet.PortletPreferences;
029 import javax.portlet.RenderRequest;
030 import javax.portlet.RenderResponse;
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 ViewAction extends PortletAction {
040
041 public ActionForward render(
042 ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
043 RenderRequest renderRequest, RenderResponse renderResponse)
044 throws Exception {
045
046 try {
047 PortletPreferences preferences = renderRequest.getPreferences();
048
049 long questionId = GetterUtil.getLong(
050 preferences.getValue("question-id", StringPool.BLANK));
051
052 PollsQuestion question =
053 PollsQuestionServiceUtil.getQuestion(questionId);
054
055 renderRequest.setAttribute(WebKeys.POLLS_QUESTION, question);
056
057 return mapping.findForward("portlet.polls_display.view");
058 }
059 catch (NoSuchQuestionException nsqe) {
060 return mapping.findForward("/portal/portlet_not_setup");
061 }
062 catch (PrincipalException pe) {
063 SessionErrors.add(renderRequest, pe.getClass().getName());
064
065 return mapping.findForward("portlet.polls_display.error");
066 }
067 }
068
069 }