Forums

Home » Liferay Portal » English » 2. Using Liferay » General

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Ana Mikana
how to pass parameter from jsp to another jsp using same portlet
July 5, 2011 7:24 AM
Answer

Ana Mikana

Rank: New Member

Posts: 4

Join Date: July 5, 2011

Recent Posts

hai
This is my first time using liferay 6 to develop system.I want to know how to pass parameter from one . jsp to another .jsp page using same portlet.
Example when user key-in ic number then clik button submit , how can i get the value form first page jsp to pass in second page jsp



Anybody can help me and please give me example

Thanks
Rob Chan
RE: how to pass parameter from jsp to another jsp using same portlet
July 5, 2011 7:35 AM
Answer

Rob Chan

Rank: Junior Member

Posts: 82

Join Date: March 23, 2011

Recent Posts

You may need to implement a MVC Portlet class that will perform a "doProcess()" method that will process a form from your first .JSP and save the variable into your render request using renderRequest.setAttribute() method. You may retreive the variable on the second JSP file by using a request.getAttribute() method.

These documents may help you understand how this works:

http://www.liferay.com/documentation/liferay-portal/6.0/development/-/ai/understanding-the-two-phases-of-portlet-execution
http://www.liferay.com/documentation/liferay-portal/6.0/development/-/ai/passing-information-from-the-action-phase-to-the-render-phase
http://www.liferay.com/documentation/liferay-portal/6.0/development/-/ai/developing-a-portlet-with-multiple-actions
Ana Mikana
RE: how to pass parameter from jsp to another jsp using same portlet
July 5, 2011 8:00 AM
Answer

Ana Mikana

Rank: New Member

Posts: 4

Join Date: July 5, 2011

Recent Posts

Thanks for reply, can you give me simple example, I already read the link you give, but i'm not very understand.
Here i'm paste my code
firstPO.jsp - this is my first page jsp
<%@ include file="init.jsp" %>
<%@ page import="javax.portlet.WindowState" %>
<script type='text/javascript' src='/<%=application.getServletContextName()%>/js/FirstPO.js'></script>
<aui:form>
<table width=100% border=0px>
<tr>
<td>No Kad Pengenalan<div align=right>:</div></td>
<td><input class="aui-field-input aui-field-input-text" id="noIC" name="noIC" type="text" /></td>
</tr>

<tr>
<td>

<input class="aui-field-input aui-field-input-text" id="nokp" name="nokp" type="text" />
<portlet:renderURL var="addURL" windowState="<%=WindowState.MAXIMIZED.toString()%>">
<portlet:param name="jspPage" value="/PendaftaranOnline.jsp"></portlet:param>
</portlet:renderURL>
<aui:button type="button" value="Daftar" id="daftar" onClick="<%=addURL.toString()%>"></aui:button>

</td>
<td></td>
</tr>
</table>
</aui:form>

second page


<aui:form>
<table width=100% border=0px>
<tr>
<td>MAKLUMAT CALON</td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td><input class="aui-field-input aui-field-input-text" id="noIC" name="noIC" type="text" readonly="readonly"/>
</td>
</tr>
</table>
</aui:form>
Rob Chan
RE: how to pass parameter from jsp to another jsp using same portlet
July 5, 2011 10:03 AM
Answer

Rob Chan

Rank: Junior Member

Posts: 82

Join Date: March 23, 2011

Recent Posts

I was suggesting for you to create a java back end to handle your requests, but if you want to create it entirely in .JSPs, you may want to just save it under your portlet preferences. Here is sample code that shows how this is done:
http://www.liferay.com/documentation/liferay-portal/6.0/development/-/ai/writing-the-my-greeting-portlet

Note in particular this code:
 1
 2<%
 3
 4PortletPreferences prefs = renderRequest.getPreferences();
 5
 6String greeting = renderRequest.getParameter("greeting");
 7
 8if (greeting != null) {   
 9
10    prefs.setValue("greeting", greeting);
11
12    prefs.store();
13
14%>   
15
16<p>Greeting saved successfully!</p>
17
18<%
19
20}


On the page that is storing the data.

With:
 1<%
 2
 3PortletPreferences prefs = renderRequest.getPreferences();
 4
 5String greeting = (String)prefs.getValue(
 6
 7    "greeting", "Hello! Welcome to our portal.");
 8
 9%>
10
11<p><%= greeting %></p>


On the page that is displaying the data.
Lalit Jugran
RE: how to pass parameter from jsp to another jsp using same portlet
July 6, 2011 4:16 AM
Answer

Lalit Jugran

Rank: Junior Member

Posts: 30

Join Date: July 25, 2010

Recent Posts

Hi Ana Mikana,

Suppose you have two jsp pages one.jsp & two.jsp within the same portlet. & you want to send a parameter from one.jsp to two.jsp. For this
1-create a PortletURL in one.jsp page. Map this entry "/ext/map/search/two " in struts-config.xml & tiles-defs.xml so that it will point to two.jsp.

PortletURL searchURL=renderResponse.createRenderURL();
searchURL.setParameter("struts_action", "/ext/map/search/two");
searchURL.setWindowState(WindowState.MAXIMIZED);

2- create a form in one.jsp page. give the searchURL as form action in one.jsp.
<form method="post" name="<portlet:namespace/>fm" action="<%=searchURL.toString()%>">
<input type="text" name="first_name" value=""/>
<input type="text" name="second_name" value=""/>
<input type="submit" name="submit" value="submit"/>
</form>
3- you can explicitly set parameters in searchURL.

searchURL.setParameter("tabs1", "general");

4- when you will submit this form in one.jsp, request will go to two.jsp & in two.jsp you will get everyting what you have submitted inside form & what you have explicitly set in searchURL in one.jsp. code for two.jsp is.

<%@ page import="com.liferay.portal.kernel.util.ParamUtil" %>

String tabs1= ParamUtil.getString(request, "tabs1");
String first_name= ParamUtil.getString(request, "first_name");
String second_name= ParamUtil.getString(request, "second_name");
Ana Mikana
RE: how to pass parameter from jsp to another jsp using same portlet
July 7, 2011 12:56 AM
Answer

Ana Mikana

Rank: New Member

Posts: 4

Join Date: July 5, 2011

Recent Posts

Okey thanks.I already sucess use that solution
mouli siripurapu
RE: how to pass parameter from jsp to another jsp using same portlet
December 9, 2015 9:54 PM
Answer

mouli siripurapu

Rank: New Member

Posts: 1

Join Date: February 10, 2014

Recent Posts

Hai Lalit Jugran,

how to render the the jsp using javascript after the click event.
Lalit Jugran
RE: how to pass parameter from jsp to another jsp using same portlet
February 21, 2016 8:07 PM
Answer

Lalit Jugran

Rank: Junior Member

Posts: 30

Join Date: July 25, 2010

Recent Posts

Hi mouli,
Please explain your scenario.
Edwin Lobo
RE: how to pass parameter from jsp to another jsp using same portlet
July 19, 2016 10:23 AM
Answer

Edwin Lobo

Rank: New Member

Posts: 10

Join Date: May 5, 2016

Recent Posts

Hi Lalit,

I suppose I have the Mouli's question too. I'm trying to submit a form using aui to MyPortletClass.java and use the coming parameters to build a database query, then MyPortletClass.java would returns a resultant String to be manipulated by a Javascript function in the same JSP where the form is.

I have the form and will be submitted to findByKeyword method in MyPortletClass.java

 1
 2<portlet:renderURL var="viewURL">
 3    <portlet:param name="mvcPath" value="/html/visualizer/view.jsp"></portlet:param>
 4</portlet:renderURL>
 5
 6<portlet:actionURL name="findByKeyword" var="findByKeywordURL"></portlet:actionURL>
 7
 8<aui:form action="<%= findByKeywordURL %>" name="<portlet:namespace />fm">
 9    <aui:fieldset>
10        <aui:input name="keyword" label="Keyword"></aui:input> // this parameter would be used by MyPortletClass to make query
11    </aui:fieldset>
12   
13    <aui:button-row>
14        <aui:button type="submit"></aui:button>
15        <aui:button onClick="<%= viewURL.toString()%>" type="cancel"></aui:button> // back to the view page
16    </aui:button-row>
17</aui:form>
18
19//From here follow the Javascript code to manipulate the resultant query of String
20// Javascript function


Now, so far, all is pretty good but when I try to manipulate the requested parameters and return a result String to the jsp whence the request came I don't know what to do :/

I tried this without success:
 1
 2public String findByKeyword(ActionRequest request, ActionResponse response)
 3            throws PortalException, SystemException {
 4
 5        ServiceContext serviceContext = ServiceContextFactory.getInstance(
 6            Urbanatweet.class.getName(), request);
 7
 8        String keyword = ParamUtil.getString(request, "keyword");
 9       
10        String keywordFound = null;
11
12        try {
13            keywordFound = UrbanatweetLocalServiceUtil.findByKeyword(keyword); //returns a String
14            
15            SessionMessages.add(request, "searchByKeywordDone");
16            
17
18        } catch (Exception e) {
19            SessionErrors.add(request, e.getClass().getName());
20
21            response.setRenderParameter("mvcPath",
22                "/html/visualizer/test_keyword.jsp");
23        }
24        return keywordFound;
25
26    }


Can you help me?
I am really stuck.

Thanks,
Edwin Lobo