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: 27

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