views:

400

answers:

3

Hi, I am using Liferay portal 5.x. I have deployed a simple portlet ( uses jsp & servlet extending GenericPortlet). This portlet will contain username & password field. I am able to see the form in view mode. But when i submit the form, the action is coming to processAction() of the Portlet class but the username & password request parameters are getting as null.

Any ideas?

+2  A: 

Is this a JSR 168 or 286 portlet?

It sounds like you're confident that the processAction() method is actually being invoked. If not, I'd start by verifying that. The key there would be the action attribute on your form. Are you using the actionURL tag to render the action attribute on the JSP?

That said, whenever I find calls to getParameter() returning null, it means I've misspelled the parameter, either in the name attribute on the input element in the form, or in the argument to getParameter(). Also, the parameters are case sensitive.

Any chance you could update your question with the code for the form and the processAction() method?

Here is an example portlet(JSR 286) that pulls the request parameters (package statement and imports omitted):

public class TestPortlet extends GenericPortlet {

public void init() throws PortletException {
 super.init();
}


public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException {
 response.setContentType(request.getResponseContentType());
 PortletRequestDispatcher rd = getPortletContext().getRequestDispatcher("/jsp/view.jsp");
 rd.include(request,response);
}


public void processAction(ActionRequest request, ActionResponse response) throws PortletException {
 System.err.println(request.getParameter("username"));
 System.err.println(request.getParameter("password"));
}

}

Here is a sample JSP:

<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>

<portlet:defineObjects />

<div>
    <form action="<portlet:actionURL />">
 <table>
  <tr>
   <td>
    User Name:
   </td>
   <td>
    <input type="text" name="username" value="">
   </td>
  </tr>
  <tr>
   <td>
    Password:
   </td>
   <td>
    <input type="password" name="password" value="">
   </td>
  </tr>
  <tr>
   <td>
    &nbsp;
   </td>
   <td>            
    <input type="submit" name="submit" value="Submit">
   </td>
  </tr>
 </table>           
</form>
</div>
cc1001
A: 

Thanks for your reply.

I am using request.getAttribute("param1") method but when i used request.getParameter("param1") it is working fine.

venu
Venu, I think you should flag this (your own) answer as the accepted solution for your question - because obviously the reason you didn't get the input was you using the wrong method (getAttribute) as you state in this answer. Thanks :-)
Ridcully
A: 

thanks a lot.. also for portlet building.. http://docs.jboss.org/jbportal/v2.4/reference-guide/en/html/index.html

Ravi