title: Passing parameters to Liferay PortletURL
body: <p>I would like to validate the request of an user by doing he types his personal key. First of all he does the request, now the portlet redirects to a second jsp file where he validates with the key and finally if it is ok the portlet complete the request otherwise returns to the first step.</p>
  
  <p>Here is the code,</p>
  
  <p>1.- view.jsp (the request)</p>
  
  <pre><code>&lt;%@ include file="/html/blue/init.jsp" %&gt;
  
  Welcome to our Colors workflow
  &lt;br/&gt;
  
  &lt;% 
  PortletURL redirectURL = renderResponse.createActionURL();
  redirectURL.setParameter(ActionRequest.ACTION_NAME, "redirect");
  %&gt;
  
  &lt;aui:form name="fmAdd" method="POST" action="&lt;%= redirectURL.toString() %&gt;"&gt;
  &lt;aui:input type="hidden" name="myaction" value="add" /&gt;
  &lt;aui:button type="submit" value="Add New Box"/&gt;
  &lt;/aui:form&gt;
  &amp;nbsp;
  &lt;aui:form name="fmList" method="POST" action="&lt;%= redirectURL.toString() %&gt;"&gt;
  &lt;aui:input type="hidden" name="myaction" value="list" /&gt;
  &lt;aui:button type="submit" value="Show All Boxes"/&gt;
  &lt;/aui:form&gt;
  </code></pre>
  
  <p>2.- the java code,</p>
  
  <pre><code>public void redirect(ActionRequest actionRequest,
          ActionResponse actionResponse) throws IOException, PortletException {
  
      String action = ParamUtil.getString(actionRequest, "myaction");
  
      PortletURL redirectURL = null;
      String redirectJSP = "/checkuser.jsp";
      if(action != null) {
          String portletName = (String)actionRequest.getAttribute(WebKeys.PORTLET_ID);
          ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
          redirectURL = PortletURLFactoryUtil.create(PortalUtil.getHttpServletRequest(actionRequest),
                  portletName, themeDisplay.getLayout().getPlid(), PortletRequest.RENDER_PHASE);
          redirectURL.setParameter("myaction", action);
          redirectURL.setParameter("jspPage", redirectJSP);
      }
  
      actionResponse.sendRedirect(redirectURL.toString());
  }
  </code></pre>
  
  <p>3._ checkuser.jsp (the user validate with his key)</p>
  
  <pre><code>&lt;%@ include file="/html/blue/init.jsp" %&gt;
  
  &lt;% 
  PortletURL checkUserURL = renderResponse.createActionURL();
  checkUserURL.setParameter(ActionRequest.ACTION_NAME, "checkUser");
  
  String myaction = renderRequest.getParameter("myaction");
  %&gt;
  
  &lt;p&gt; Your action:&amp;nbsp;&lt;%= myaction %&gt; &lt;/p&gt;
  
  &lt;aui:form name="fm" method="POST" action="&lt;%= checkUserURL.toString() %&gt;"&gt;
  &lt;aui:input type="hidden" name="myaction" value="&lt;%= myaction %&gt;" /&gt;
  &lt;aui:input type="text" name="key" value=""/&gt;
  &lt;aui:button type="submit" value="Save"/&gt;
  &lt;/aui:form&gt;
  </code></pre>
  
  <p>In this phase I am getting the first problem because I do not see the value of the request (myaction variable). This is only for debug.</p>
  
  <p>4._ the java code that catches the last form,</p>
  
  <pre><code>public void checkUser(ActionRequest actionRequest,
          ActionResponse actionResponse) throws IOException, PortletException {
  
      String key = ParamUtil.getString(actionRequest, "key");
      String action = ParamUtil.getString(actionRequest, "myaction");
  
      String portletName = (String)actionRequest.getAttribute(WebKeys.PORTLET_ID);
      ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
      PortletURL redirectURL = PortletURLFactoryUtil.create(PortalUtil.getHttpServletRequest(actionRequest),
              portletName, themeDisplay.getLayout().getPlid(), PortletRequest.RENDER_PHASE);
  
      String redirectJSP = "/view.jsp";
      if(key != null) {
          if(key.equalsIgnoreCase("blue")) {
              if(action != null) {
                  if(action.equalsIgnoreCase("add")) {
                      redirectJSP = "/update.jsp";
                  }
                  if(action.equalsIgnoreCase("list")) {
                      redirectJSP = "/list.jsp";
                  }
              }
          }
      }
  
      redirectURL.setParameter("jspPage", redirectJSP);
      actionResponse.sendRedirect(redirectURL.toString());
  }
  </code></pre>
  
  <p>In this phase the portlet always goes to view.jsp where the user does the request. I am thinking both key and action variables are null or at least one of them.</p>
  
  <p>What am I doing wrong?</p>
  
  <p>Regards,
  Jose</p>