title: Pass form field values to parameters of a portlet:renderURL tag in WebSphere Portal 6.1
body: <p>I'm developing a portlet for <strong>WebSphere Portal 6.1, with JSP/JSTL, pure javascript, no AJAX frameworks</strong>, with a JSP that shows a send feedback form and, when submitted, redirects to another JSP to show the user the success of the operation.</p>
  
  <p>I use javascript to get the values of the form fields by using <code>document.getElementById()</code> function. For example:</p>
  
  <pre><code>var valorAsunto = document.getElementById("asunto").value;
  </code></pre>
  
  <p>where "asunto" is the ID of a text field in my form. Also my form has the following structure:</p>
  
  <pre><code>&lt;form name="formularioCorreo" id="formularioCorreo" method="post" action="&lt;portlet:renderURL&gt;&lt;portlet:param name="nextTask" value="sendFeedback"/&gt;&lt;/portlet:renderURL&gt;"&gt;
  </code></pre>
  
  <p>That works OK, but I'm having trouble when trying to build the <code>&lt;portlet:renderURL&gt;</code> tag from that javascript values: when I try to concatenate a string for the renderURL and then reassign to form action like this:</p>
  
  <pre><code>var valorAction = '&lt;portlet:renderURL&gt;&lt;portlet:param name="nextTask" value="sendFeedback"/&gt;&lt;portlet:param name="asunto" value="'+valorAsunto+'"/&gt;&lt;/portlet:renderURL&gt;';
  document.formularioCorreo.action = valorAction; 
  document.formularioCorreo.submit();
  </code></pre>
  
  <p>The resulting string, when application is deployed, has the structure:</p>
  
  <blockquote>
    <p>/wps/myportal/<code>&lt;portletpath&gt;</code>/!ut/p/c5/<code>&lt;a very long random sequence of
    numbers and letters&gt;</code>/</p>
  </blockquote>
  
  <p>So one can't figure out where the parameter values are, but if I print the assigned values it shows something like:</p>
  
  <blockquote>
    <p>asunto: '+valorAsunto+'</p>
  </blockquote>
  
  <p>instead of</p>
  
  <blockquote>
    <p>asunto: this is a sample subject</p>
  </blockquote>
  
  <p>I've been trying to use some other ways to concatenate the string; for instance with a <code>StringBuffer</code>, as shown on <a href="http://www.java2s.com/Tutorial/JavaScript/0120__String/StringBufferbasedonarray.htm" rel="nofollow">http://www.java2s.com/Tutorial/JavaScript/0120__String/StringBufferbasedonarray.htm</a></p>
  
  <p>and also javascript functions like <code>encodeURI()</code>/<code>decodeURI()</code>, <code>replace()</code>, etc. but I just can't get either the URL with the right parameter values or the URL encoded in the structure shown above (the one with the long sequence of chars).</p>
  
  <p>Sometimes I manage to get the right parameter values, by manually replacing in the valorAction assignation all the "<code>&lt;</code>" for "<code>&amp;lt;</code>" and all the "<code>&gt;</code>" for "<code>&amp;gt;</code>" before the concatenation, and then doing the following:</p>
  
  <pre><code>var valorAction = valorAction.replace(/&amp;lt;/g,"&lt;").replace(/&amp;gt;/g,"&gt;");
  </code></pre>
  
  <p>Then I get the following string:</p>
  
  <pre><code>&lt;portlet:renderURL&gt;&lt;portlet:param name="nextTask" value="sendFeedback"/&gt;&lt;portlet:param name="asunto" value="this is a sample subject"/&gt;&lt;/portlet:renderURL&gt;
  </code></pre>
  
  <p>which is OK, but when it has to redirect to the results page it shows an error like this</p>
  
  <blockquote>
    <p>Error 404: EJPEI0088E: The resource <code>&lt;portlet:renderURL&gt;&lt;portlet:param
    name="nextTask" value="sendFeedback"/&gt;&lt;portlet:param name="asunto"
    value="this is a sample subject"/&gt;&lt;/portlet:renderURL&gt;</code> could not be
    found.</p>
  </blockquote>
  
  <ul>
  <li>Does someone know how to transform that string to the right format to be rendered?</li>
  <li>Does someone know any other way to "inject" that parameter values to the renderURL?</li>
  <li>I'd like to know also if it is possible to pass that parameter values from javascript to JSP so I could put that values in a <code>HashMap</code> of parameters to use with the <code>PortletURLHelper.generateSinglePortletRenderURL()</code> method, in case the former is not possible. </li>
  </ul>
  
  <p>Thank you.</p>
  
  <hr>
  
  <p><strong>Update 1:</strong></p>
  
  <p>In my <code>doView()</code> I use the following, in order to make the redirection:</p>
  
  <pre><code>String targetJsp = "/_Feedback/jsp/html/FeedbackPortletView.jsp";
  String nextTask = request.getParameter("nextTask");
  //(... I have omitted code to conditionally select targetJsp value, according to nextTask value ...)
  PortletRequestDispatcher rd = getPortletContext().getRequestDispatcher(targetJsp);
  rd.include(request, response);
  </code></pre>
  
  <p>This is just a new JSP inside my portlet, not a different portal page. I do use <code>request.getParameter()</code> to get the values for my form fields from my <code>doview()</code>:</p>
  
  <pre><code>String subjectFeedback = request.getParameter("asunto");
  String bodyFeedback = request.getParameter("mensaje");
  String emailFeedback = request.getParameter("emailFeedback");
  </code></pre>
  
  <p>I don't see the need to include hidden fields if my form has the fields named above. In fact, what I'm trying to do is to pass the values the user entered in these fields as request parameters, but the values I get by this means are the following:</p>
  
  <pre><code>subjectFeedback: "'+valorAsunto+'"
  bodyFeedback: "'+valorMensaje+'"
  emailFeedback: "'+valorEmailFeedback+'"
  </code></pre>
  
  <p>I get the above values when using concatenation by "+"; when I use <code>StringBuffer</code> I get the following values:</p>
  
  <pre><code>subjectFeedback: "'); buffer.append(valorAsunto); buffer.append('"
  bodyFeedback: "'); buffer.append(valorMensaje); buffer.append('"
  emailFeedback: "'); buffer.append(valorEmailFeedback); buffer.append('"
  </code></pre>