Message Boards

Javascript + Liferay

Fazalmahammad Babaria, modified 5 Years ago.

Javascript + Liferay

New Member Posts: 16 Join Date: 2/26/19 Recent Posts
How can i create RenderURL inside my Javascript i am created it and its almost working but when i use to put value of any javascript variable it take as a string in PORTLET PARAM. the code is as below.

for(var i = first.charCodeAt(0); i <= last.charCodeAt(0); i++) {
         var character = eval("String.fromCharCode(" + i + ")");
        $('#filter').append("<portlet:renderURL var='searchEmployeeURL'><portlet:param name='action' value='filterEmployeesURL' /><portlet:param name='filterBy' value='"+character+"'/></portlet:renderURL>");
        $('#filter').append("<a href=${searchEmployeeURL}>"+eval("String.fromCharCode(" + i + ")")+"</a>&nbsp;&nbsp;"); 
}
anybody have idea
Thank you !!
thumbnail
Olaf Kock, modified 5 Years ago.

RE: Javascript + Liferay

Liferay Legend Posts: 6403 Join Date: 9/23/08 Recent Posts
Fazalmahammad BabariaHow can i create RenderURL inside my Javascript i am created it and its almost working but when i use to put value of any javascript variable it take as a string in PORTLET PARAM. the code is as below.
for(var i = first.charCodeAt(0); i &lt;= last.charCodeAt(0); i++) {
         var character = eval("String.fromCharCode(" + i + ")");
        $('#filter').append("<portlet:renderurl var="searchEmployeeURL"><portlet:param name="action" value="filterEmployeesURL" /><portlet:param name="filterBy" value="&quot;+character+&quot;" /></portlet:renderurl>");
        $('#filter').append("<a href="${searchEmployeeURL}">"+eval("String.fromCharCode(" + i + ")")+"</a>&nbsp;&nbsp;"); 
}
To be honest, I don't know what you mean with "almost working".
But there's at least one image that I see in your code:

<portlet:renderURL/> will only output something directly on the page, when there's no var attribute. Otherwise it will create and initialize the scripting variable with the name given in the attribute.

E.g.:
<portlet:renderurl />               ---&gt; will output the actual renderURL
<portlet:renderurl var="someVar" /> ---&gt; will output nothing, but someVar is now available
&lt;%=someVar%&gt;                       ---&gt; will output the actual renderURL after the previous line
${someVar}                         ---&gt; an alternative notion for the previous line.
So the first "append" lines in the code you quote will generate the following javascript code:
$('#filter').append("");
I'm also not quite sure what you intended to do with those "eval" expressions and why you'd pass a filterEmployeesURL as a parameter to a renderURL.

Suggestion: Rewrite the question and give us what you actually need: What's the input, what's the desired output, what's the business case?
thumbnail
David H Nebinger, modified 5 Years ago.

RE: Javascript + Liferay

Liferay Legend Posts: 14919 Join Date: 9/2/06 Recent Posts
Ick, you should never just start concatenating things together in an effort to hodge-podge something that just happens to work in your current environment.  It is too fragile and subject to breakage on your next release.

Instead, use the portal source to see how they do it, then copy it into your own code.

A quick search for "renderurl" on all .js files of the portal gives me a short list, one included item is:

var portletURL = new Liferay.PortletURL.createURL(config.baseRenderURL);
This shows me that Liferay has a utility function to create a URL. Searching for PortletURL in all JS files leads me to modules/apps/foundation/frontend-js/frontend-js-aui-web/src/main/resources/META-INF/resources/liferay/portlet_url.js where I can see the methods that are exposed and everything that I can set in the URL.

So with just a few minutes of code searching, I've found that I can build a clean, single line of JS to create a render URL in javascript that, because it relies on Liferay-provided code, should be resilient to future versions as long as the given API doesn't change.
Fazalmahammad Babaria, modified 5 Years ago.

RE: Javascript + Liferay

New Member Posts: 16 Join Date: 2/26/19 Recent Posts
Thanx,now its working perfect