Foros de discusión

how to pass parameter from jsp to another jsp using same portlet

Azuwa Kasnan, modificado hace 12 años.

how to pass parameter from jsp to another jsp using same portlet

New Member Mensajes: 4 Fecha de incorporación: 5/07/11 Mensajes recientes
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
thumbnail
Rob Chan, modificado hace 12 años.

RE: how to pass parameter from jsp to another jsp using same portlet

Junior Member Mensajes: 82 Fecha de incorporación: 23/03/11 Mensajes recientes
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, modificado hace 12 años.

RE: how to pass parameter from jsp to another jsp using same portlet

New Member Mensajes: 4 Fecha de incorporación: 5/07/11 Mensajes recientes
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>
thumbnail
Rob Chan, modificado hace 12 años.

RE: how to pass parameter from jsp to another jsp using same portlet

Junior Member Mensajes: 82 Fecha de incorporación: 23/03/11 Mensajes recientes
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:

&lt;%

PortletPreferences prefs = renderRequest.getPreferences();

String greeting = renderRequest.getParameter("greeting");

if (greeting != null) {    

    prefs.setValue("greeting", greeting);

    prefs.store();

%&gt;    

<p>Greeting saved successfully!</p>

&lt;%

}


On the page that is storing the data.

With:
&lt;%

PortletPreferences prefs = renderRequest.getPreferences();

String greeting = (String)prefs.getValue(

    "greeting", "Hello! Welcome to our portal.");

%&gt;

<p>&lt;%= greeting %&gt;</p>


On the page that is displaying the data.
thumbnail
Lalit Jugran, modificado hace 12 años.

RE: how to pass parameter from jsp to another jsp using same portlet

Junior Member Mensajes: 33 Fecha de incorporación: 25/07/10 Mensajes recientes
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, modificado hace 12 años.

RE: how to pass parameter from jsp to another jsp using same portlet

New Member Mensajes: 4 Fecha de incorporación: 5/07/11 Mensajes recientes
Okey thanks.I already sucess use that solution
thumbnail
mouli siripurapu, modificado hace 8 años.

RE: how to pass parameter from jsp to another jsp using same portlet

New Member Mensajes: 5 Fecha de incorporación: 10/02/14 Mensajes recientes
Hai Lalit Jugran,

how to render the the jsp using javascript after the click event.
thumbnail
Lalit Jugran, modificado hace 8 años.

RE: how to pass parameter from jsp to another jsp using same portlet

Junior Member Mensajes: 33 Fecha de incorporación: 25/07/10 Mensajes recientes
Hi mouli,
Please explain your scenario.
thumbnail
Edwin Lobo, modificado hace 7 años.

RE: how to pass parameter from jsp to another jsp using same portlet

New Member Mensajes: 10 Fecha de incorporación: 5/05/16 Mensajes recientes
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


<portlet:renderurl var="viewURL">
	<portlet:param name="mvcPath" value="/html/visualizer/view.jsp"></portlet:param>
</portlet:renderurl>

<portlet:actionurl name="findByKeyword" var="findByKeywordURL"></portlet:actionurl>

<aui:form action="<%= findByKeywordURL %>" name="<portlet:namespace />fm">
	<aui:fieldset>
		<aui:input name="keyword" label="Keyword"></aui:input> // this parameter would be used by MyPortletClass to make query
	</aui:fieldset>
	
	<aui:button-row>
		<aui:button type="submit"></aui:button>
		<aui:button onclick="<%= viewURL.toString()%>" type="cancel"></aui:button> // back to the view page
	</aui:button-row>
</aui:form>

//From here follow the Javascript code to manipulate the resultant query of String
// 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:

public String findByKeyword(ActionRequest request, ActionResponse response)
	        throws PortalException, SystemException {

	    ServiceContext serviceContext = ServiceContextFactory.getInstance(
	        Urbanatweet.class.getName(), request);

	    String keyword = ParamUtil.getString(request, "keyword");
	    
	    String keywordFound = null;

	    try {
	        keywordFound = UrbanatweetLocalServiceUtil.findByKeyword(keyword); //returns a String
	        
	        SessionMessages.add(request, "searchByKeywordDone");
	        

	    } catch (Exception e) {
	        SessionErrors.add(request, e.getClass().getName());

	        response.setRenderParameter("mvcPath",
	            "/html/visualizer/test_keyword.jsp");
	    }
	    return keywordFound;

	}


Can you help me?
I am really stuck.

Thanks,
Edwin Lobo