Foren

Url GET parameters in portlet java code

Laurie Tynor, geändert vor 15 Jahren.

Url GET parameters in portlet java code

New Member Beiträge: 6 Beitrittsdatum: 30.07.08 Neueste Beiträge
I'm trying to retrieve the GET url parameters from inside of a portlet. I'm using liferay 4.4.2, with jsf and the MyFacesGenericPortlet and inside of one of my backing beans I've tried the following:

1. ((PortletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest()).getParameter(KEY);
2. ((RenderRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest()).getParameter(KEY);
3. ((PortletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest()).getAttribute(KEY);
4. ((RenderRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest()).getAttribute(KEY);
5. PortalUtil.getHttpServletRequest(
((PortletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest()).getParameter(KEY));
6. PortalUtil.getHttpServletRequest(
((PortletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest()).getParameter(KEY));


I call the portlet by entering the url in my browser: http://<portal path>/<portal_page>?KEY=VALUE

I always get null back for the GET parameter. I have successfully used #1 above when sending a POST parameter from a JSF page using the h:inputHidden element inside an h:commandButton. It just doesn't seem to work from a GET parameter in a url.

If you have any info about the proper way to get the parameter, I'd really appreciate it. (I've seen one other post on the forums about this that recommended #5 above, but it doesn't work for me.


Thanks,
Laurie Tynor
thumbnail
Ray Augé, geändert vor 15 Jahren.

Re: [Liferay Forums][3. Development] Url GET parameters in portlet java cod

Liferay Legend Beiträge: 1197 Beitrittsdatum: 08.02.05 Neueste Beiträge
I'm not sure about JSF in particular, but the params DO have to be
portlet namespaced, which is probably why they are working from a POST
(because the jsf-portlet framework is namespaceing them for you).

This will normally look like: [tt]_PORTLET_ID_key=20[/tt].

If you don't want that namespacing (which is required by all portlets),
then you need to look at the JSR-286 feature called "public render
parameters" which allows you to globally define params which are
accessed using such an un-namespaced pattern.

This feature also allows for IPC if more than one portlet are configured
to handle the same public parameter, but this is not expressly required.

HTH!
thumbnail
Tobias Amon, geändert vor 15 Jahren.

RE: Re: [Liferay Forums][3. Development] Url GET parameters in portlet java

Liferay Master Beiträge: 546 Beitrittsdatum: 08.08.07 Neueste Beiträge
Hello,

you can only get the parameter values if the parameters were addressed to the portlet where you have your code.
This is difficult as you need to have the instance id of a portlet to be able to attach a parameter to it.

What I do to achive this is to set the portlet where you want to get the param to "not instanceable" this means that the ID of the portlet follows a given structure. Addressing a portlet is then easy as you only need this fix instance id. Here is an example:
http://localhost:8080/web/guest/home?p_p_id=test_WAR_mytestwar&p_p_action=0&myparam=myvalue
Inside the portlet called "test" packaged in a war file called my_test_war.war you can get the values.

Optionally as Ray already said you can use the Portlet 2.0 features (but only in Liferay 5)
Radu B, geändert vor 15 Jahren.

RE: Url GET parameters in portlet java code

New Member Beiträge: 11 Beitrittsdatum: 19.06.08 Neueste Beiträge
The workaround that was OK for me was to call:

String queryString = (String)renderRequest.getAttribute("javax.servlet.forward.query_string");

which is giving back the original query string that you can parse with StringTokenizer for instance.

I am now using FriendlyURL for my portlet. If the portlet is not multiple-instance, the URL will look like
http://server-name/page/-/FriendlyName/ParameterName/ParameterValue

which is more nice and SEO friendly than QueryString with portlet namespace
Laurie Tynor, geändert vor 15 Jahren.

RE: Url GET parameters in portlet java code

New Member Beiträge: 6 Beitrittsdatum: 30.07.08 Neueste Beiträge
Thanks everyone. I tried both ways (namespaced url params and getting the original query string), and both worked!

I really appreciate the fast help!


Laurie
venkat v venkat, geändert vor 14 Jahren.

RE: Url GET parameters in portlet java code

New Member Beitrag: 1 Beitrittsdatum: 27.09.09 Neueste Beiträge
Radu B:
The workaround that was OK for me was to call:

String queryString = (String)renderRequest.getAttribute("javax.servlet.forward.query_string");

which is giving back the original query string that you can parse with StringTokenizer for instance.

I am now using FriendlyURL for my portlet. If the portlet is not multiple-instance, the URL will look like
http://server-name/page/-/FriendlyName/ParameterName/ParameterValue

which is more nice and SEO friendly than QueryString with portlet namespace



Hi All,

This is Venkat, working as WebSphere Portal Developer with JSR 286 Portlet Development.

Please share some examples if you have already come across of the below scenario.

I have a requirement where i need to access the Portal Page Browser

URL and then i need to parse it.
I am using WebSphere Portal 6.1 and RAD 7.5 using JSR 286.

So using jsr 286 specifications how can i read the portal browser url.

To make the requirement more clear, we have an url which comes from
Legacy (outside the portal environment) and opens the portal page, so
the url comes into portal environment has an id appended to it.

as an example the url looks something like this:

http://www.abc.com/application/100034

so based on the appended 100034 value my portal page displays the
content (portlet content).

How can i parse the value 100034 and get as a string into my portal environment, so that i can display the corresponding content based on that value.

As of now i have only this requirement with me, i hope i make you guys
understand what is the requirement.

It would be great favour if you answer me the question.

Please Please, if anyone come across with the similar requirement or who knows how to do it, please share some step by step process and sample code.( Please do not think that i am asking tooo much, i am really in urgency).

Thanks,

Venkat.
thumbnail
Ivan Andrew Pointer, geändert vor 14 Jahren.

RE: Url GET parameters in portlet java code

New Member Beitrag: 1 Beitrittsdatum: 03.06.09 Neueste Beiträge
Hello,

I am not sure if this is the right place for your post, but I have been in your shoes before. I would like to help. The first item of note is which IDE are you using? Are you in NetBeans, Eclipse or (In your case, the best option) Rational?

If you are in Rational, your job has been made very easy my friend:

Open the portlet.xml file for the web application. Go to the "Render Parameters" tab. You need to register a render parameter that you want to receive there. This would be the name of the parameter coming in on the URL. In order for a portlet to be allowed scope to the URL parameter, it must be specifically noted.

Once your portlet.xml file is updated, the code for accessing the parameter is simple:

String customerID = renderRequest.getParameter("custID");


I believe, but am not sure, that this "getParameter" function can be called by any of the PortletRequest objects (PortletRequest, ActionRequest or RenderRequest).

If you are using either NetBeans, Eclipse or another tool, I personally do not know of any automagical way for you to configure the portlet.xml file. What you are looking for is something similar to:


<!--?xml version="1.0" encoding="UTF-8"?-->
<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>
		<description>AnExamplePortlet</description>
		<portlet-name>AnExamplePortlet</portlet-name>
		<display-name>AnExamplePortlet</display-name>
		<portlet-class>com.somesite.ExamplePortlet</portlet-class>
		<expiration-cache>0</expiration-cache>
		<supports>
			<mime-type>text/html</mime-type>
			<portlet-mode>VIEW</portlet-mode>
			<portlet-mode>EDIT</portlet-mode>
			<portlet-mode>HELP</portlet-mode>
		</supports>
		<resource-bundle>com.somesite.rb.ExamplePortlet</resource-bundle>
		<portlet-info>
			<title>Example Portlet</title>
			<short-title>Example Portlet</short-title>
		</portlet-info>
		<supported-public-render-parameter>myParamName</supported-public-render-parameter>
	</portlet>
	<public-render-parameter>
		<description>A public render parameter</description>
		<identifier>custID</identifier>
		<name>myParamName</name>
	</public-render-parameter>
</portlet-app>


This is all a part of the JSR 286 Standard and will work in any portal.

I hope this helps

emoticon

P.S. You can also check

this IBM Infocenter page for additional help; however, I would wait to see if what I suggested above works enough or not as this may confuse.

If that does not work yet, the concept you are looking for is "Public Render Parameters", one of the major search engines should turn something useful up for you.
Sangeea Patra, geändert vor 12 Jahren.

RE: Url GET parameters in portlet java code

New Member Beitrag: 1 Beitrittsdatum: 22.07.11 Neueste Beiträge
String strUserType =null;
HttpServletRequest httpReq = PortalUtil.getOriginalServletRequest(PortalUtil.getHttpServletRequest(renderRequest));
strUserType = httpReq.getParameter("userType");
dynamicRequest.setAttribute("UserType",strUserType);

This code is correct.It worked for me.