Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
RE: Liferay 7.1 Ajax calls and parameters
So, I'm seeing some odd namespace appending to form names/ids in my portlet when using an osgi module mvc-portlet in Liferay 7.1. I'm converting alot of 6.2 code to 7.1 and there is a weird "INSTANCE_" text string being appended before the variable name and I can't get it using ParamUtil in my serveResource method.
Currently, in my serveResource method in the MVC Portlet I have a line of code
So, I'm trying to get a drop-down element with the variable "dbSelection", which is passed in via an Ajax call in jQuery
When I print out the above url via an alert, I see something like this:
So, when I print out that variable value from the serveResource method I of course get null.. Why is this? And is there a new api like ParamUtil that will get that variable?
Currently, in my serveResource method in the MVC Portlet I have a line of code
String dbConnection = ParamUtil.getString(resourceRequest, "dbSelection");
So, I'm trying to get a drop-down element with the variable "dbSelection", which is passed in via an Ajax call in jQuery
var url ='<%=updatePopulationForUserURL%>'+'&<portlet:namespace />dbSelection=' + dbConnection;
When I print out the above url via an alert, I see something like this:
_practiceprofile_INSTANCE_7n0ap8UBjT2i_dbSelection
So, when I print out that variable value from the serveResource method I of course get null.. Why is this? And is there a new api like ParamUtil that will get that variable?
Kevin NeibargerIn the portal (or portlet-)world, you'll always run across the namespace. Through HTTP, all parameters need to be namespaced with the portal ID. You obviously have an instantiable portlet, e.g. you can have it on the page multiple times - thus the random gibberish in there: This is to make the portlet-ID unique. In JS, on the browser side, you naturally see the fully decorated parameter. On the portal side, in Java, your portlet will receive the parameters directed to it - without the decoration. Thus, your PortalUtil.getParameter(rq, "dbSelection") is what I'd expect you need to use.
Currently, in my serveResource method in the MVC Portlet I have a line of codeString dbConnection = ParamUtil.getString(resourceRequest, "dbSelection");
So, I'm trying to get a drop-down element with the variable "dbSelection", which is passed in via an Ajax call in jQueryvar url ='<%=updatePopulationForUserURL%>'+'&<portlet:namespace />dbSelection=' + dbConnection;
When I print out the above url via an alert, I see something like this:_practiceprofile_INSTANCE_7n0ap8UBjT2i_dbSelection
Does it not work? Or did you not try it? This should be unchanged forever (with the notable differences that early versions of Liferay used a 4-letter random string, while newer ones use the longer string)
Thanks Olaf, I actually figured it out. I was actually trying to read in an attribute instead of a parameter and got my issue fixed. I was just wondering about the <portlet:namespace/> because it looks like the string that is generated from that has changed between Liferay 6.2 and 7.1 and it confused me a bit.
Copyright © 2025 Liferay, Inc
• Privacy Policy
Powered by Liferay™