0
votes

I have a liferay portlet where I want to take an input string and transfer/"get" it from the jsp into the portlet mvc class method. That string I want to use to search a database for some results and display a generated result string. I have tried a few of the setAttribute like methods of the renderRequest but it always gives a "null" result.

I start simply by inputting the initial string through a text input form and accessing it in the method.

<input  type="text" name="<portlet:namespace/>class" id="<portlet:namespace/>class"/><br/>

String className = ParamUtil.getString(actionRequest, "class");

That part was successful.

Then I am able to create the string from the search results and want to know what is the best way to display the simple string through the jsp. i.e. how can I transport this generated string to the jsp page?

1

1 Answers

0
votes

in view.jsp: Create action url, when i submit the form it will go to the name mentioned in the action url(display) in the FormPortlet.java it will execute display() method. Note: name of the action url and name of the method should match. see this example.

view.jsp

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

    <portlet:defineObjects />

    <%@ taglib uri=”http://liferay.com/tld/aui” prefix=”aui” %>

    <portlet:actionURL name=”display” var=”submitURL”/>


    <aui:form action=”<%= submitURL %>” method=”post”>
    <aui:input label=”First name” name=”fName” type=”text” value=”“/>
    <aui:input label=”Last name” name=”lName” type=”text” value=”“/>
    <aui:input label=”Password” name=”password” type=”password” value=”“/>
    <aui:button type=”submit” value=”Submit Form”/>
    <aui:button type=”reset” value=”Reset Values”/>
    </aui:form>

FormPortlet.java

package com.form;

import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;

import com.liferay.portal.kernel.servlet.SessionMessages;
import com.liferay.util.bridges.mvc.MVCPortlet;

/**
* Portlet implementation class FormPortlet
*/
public class FormPortlet extends MVCPortlet {

public void display(ActionRequest req, ActionResponse res)
{
String fName = req.getParameter(“fName”);
String lName = req.getParameter(“lName”);
String password = req.getParameter(“password”); 
System.out.println(fName);
System.out.println(lName);
System.out.println(password);
String successMsg = “form submitted Successfully!”; 
SessionMessages.add(req, “request_processed”, successMsg);
}

}