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.struts.PortletAction;
021 import com.liferay.portal.util.WebKeys;
022 import com.liferay.portlet.polls.NoSuchQuestionException;
023 import com.liferay.portlet.polls.model.PollsQuestion;
024 import com.liferay.portlet.polls.service.PollsQuestionServiceUtil;
025
026 import javax.portlet.PortletConfig;
027 import javax.portlet.PortletPreferences;
028 import javax.portlet.RenderRequest;
029 import javax.portlet.RenderResponse;
030
031 import org.apache.struts.action.ActionForm;
032 import org.apache.struts.action.ActionForward;
033 import org.apache.struts.action.ActionMapping;
034
035
038 public class ViewAction extends PortletAction {
039
040 @Override
041 public ActionForward render(
042 ActionMapping actionMapping, ActionForm actionForm,
043 PortletConfig portletConfig, RenderRequest renderRequest,
044 RenderResponse renderResponse)
045 throws Exception {
046
047 try {
048 PortletPreferences preferences = renderRequest.getPreferences();
049
050 long questionId = GetterUtil.getLong(
051 preferences.getValue("questionId", StringPool.BLANK));
052
053 if (questionId > 0) {
054 PollsQuestion question = PollsQuestionServiceUtil.getQuestion(
055 questionId);
056
057 renderRequest.setAttribute(WebKeys.POLLS_QUESTION, question);
058 }
059 }
060 catch (Exception e) {
061 if (!(e instanceof NoSuchQuestionException)) {
062 SessionErrors.add(renderRequest, e.getClass());
063
064 return actionMapping.findForward("portlet.polls_display.error");
065 }
066 }
067
068 return actionMapping.findForward("portlet.polls_display.view");
069 }
070
071 }