Forums de discussion

How to send parameters or value to one JSP to another

cacaca cacaca, modifié il y a 10 années.

How to send parameters or value to one JSP to another

New Member Publications: 14 Date d'inscription: 12/04/13 Publications récentes
Now, I developing simple JSP portlet(no use struts). I have the jsp view and the second jsp view_detail.jsp. In the jsp view.jsp I wrote this:
...
<TD> <a href="<portlet:renderURL ><portlet:param name="ric" value="/view_detail.jsp?id="<%=rs.getInt(1)%""/></portlet:renderURL>"><%=rs.getInt(1)%></a>
</TD>
....


this is my portlet.xml

<?xml version="1.0"?>

<portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd" version="2.0">
<portlet>
....
<portlet-class>com.liferay.util.bridges.mvc.MVCPortlet</portlet-class>
<init-param>
<name>view-template</name>
<value>/html/view/view.jsp</value>

</init-param>

<init-param>
<name>ric</name>
<value>/html/view/view_details.jsp</value>
</init-param>
<expiration-cache>0</expiration-cache>
<supports>
<mime-type>text/html</mime-type>
</supports>
<portlet-info>
...
</portlet>
</portlet-app>


but it is doesen't work.Can you help me,please.
thumbnail
Amit Doshi, modifié il y a 10 années.

RE: How to send parameters or value to one JSP to another

Liferay Master Publications: 550 Date d'inscription: 29/12/10 Publications récentes
Hi cacaca,

I am seeing something weird here.

As you are passing that all the things in renderURL

<portlet:renderURL ><portlet:param name="ric" value="/view_detail.jsp?id="<%=rs.getInt(1)%""/></portlet:renderURL>


When you will try to get "ric" in the doView Method it will give you entire value as "/view_detail.jsp?id="<%=rs.getInt(1)%"".

Instead of the above thing. Use Seperately.

<portlet:renderURL ><portlet:param name="page" value="/view_detail.jsp"/>
<portlet:param name="id" value="<%=rs.getInt(1)%=>"/>
</portlet:renderURL>

Now in the doView jsp try to get the Value of the Page and Id.

And if you need to get that value in view_details.jsp then you have to set once again that value in Doview method with the help of renderRequest.setAttribute("id","value");
Then only you will be able to get in the view_details.jsp. As the value will be set in the Request Scope so we need to set in the doView method.

Hope it's clear now.

Thanks & Regards,
Amit Doshi
cacaca cacaca, modifié il y a 10 années.

RE: How to send parameters or value to one JSP to another

New Member Publications: 14 Date d'inscription: 12/04/13 Publications récentes
I tried justo to display Hello in view_details.jsp wothout passing parameters.

I wrote this code:

<a href="<portlet:renderURL >
<portlet:param name="page" value="/view_dettaglio.jsp"/>
</portlet:renderURL>"><%=rs.getInt(1)%></a>

but it doesn't work.
thumbnail
Amit Doshi, modifié il y a 10 années.

RE: How to send parameters or value to one JSP to another

Liferay Master Publications: 550 Date d'inscription: 29/12/10 Publications récentes
You will not directly that parameter in view_details.jsp as I said it is in request scope.

You first need to study the liferay life cycle.

The URL you mentioned will call the render phase of liferay and then it will call the view_details.jsp page from doView Method.

So In controller, you need to get that value and set that value and then only it will get in the view_details.jsp.

So the code will be like this.

In View.jsp


<a href="<portlet:renderURL >
<portlet:param name=" page" value="/view_dettaglio.jsp"></a>
<portlet:param name="id" value="<%=rs.getInt(1)%=>" />
"&gt;&lt;%=rs.getInt(1)%&gt;


In Controller , doView method write below code.



@Override
	public void doView(final RenderRequest renderRequest, final RenderResponse renderResponse) throws PortletException, IOException {
		
	String page = ParamUtil.getString(renderRequest, "page");
	String id = ParamUtil.getInteger(renderRequest, "id");
			renderRequest.setAttribute("id",id.toString());	
		this.include(page, renderRequest, renderResponse);

	}



Now in view_details.jsp write below code to get the value.

<%=renderRequest.getAttribute("id")%>

Hope now it's clear.

Thanks & Regards,
Amit Doshi
cacaca cacaca, modifié il y a 10 années.

RE: How to send parameters or value to one JSP to another

New Member Publications: 14 Date d'inscription: 12/04/13 Publications récentes
Sorry, just a question in my action in the jsp I have this


<a href="<portlet:renderURL >
<portlet:param name=" page" value="/view_dettaglio.jsp"></a>
<portlet:param name="id" value="<%=rs.getInt(1)%=>" />
"&gt;&lt;%=rs.getInt(1)%&gt;

in my class this method

@Override
public void doView(final RenderRequest renderRequest, final RenderResponse renderResponse) throws PortletException, IOException {
  String page = ParamUtil.getString(renderRequest, "page");
 String id = ParamUtil.getInteger(renderRequest, "id");
  renderRequest.setAttribute("id",id.toString());   
  this.include(page, renderRequest, renderResponse);

Why it doesn't work...;(((((
thumbnail
Amit Doshi, modifié il y a 10 années.

RE: How to send parameters or value to one JSP to another

Liferay Master Publications: 550 Date d'inscription: 29/12/10 Publications récentes
Hi Cacaca,

If you are using MVC Portlet then use the doView Method.

If you are using Struts Portlet then use below method

public ActionForward render(ActionMapping mapping, ActionForm form,
PortletConfig config, RenderRequest req, RenderResponse res)
throws Exception {

}

It depends on the Class that you have extended.

Thanks & Regards,
Amit Doshi
thumbnail
Jennis Vaishnav, modifié il y a 7 années.

RE: How to send parameters or value to one JSP to another

Junior Member Publications: 59 Date d'inscription: 01/02/17 Publications récentes
Amit Doshi:

It depends on the Class that you have extended.

What if we extended LiferayPortlet?