留言板

how to put <portlet:namespace> in main.js

wei tang,修改在11 年前。

how to put <portlet:namespace> in main.js

Junior Member 帖子: 36 加入日期: 12-12-3 最近的帖子
I put <portlet:namespace> in main.js, but it's doesn't work.
ps:
jquery code:$('#'+'<portlet:namespace/><%=ProductDisplayTerms.STANDARD%>').val(value);
The <%=ProductDisplayTerms.STANDARD%> value cann't be referenced in main.js accurately!
I'm sure that work in jsp file fine!
thumbnail
Jan Geißler,修改在11 年前。

RE: how to put <portlet:namespace> in main.js

Liferay Master 帖子: 735 加入日期: 11-7-5 最近的帖子
Exactly. It works fine in JSP file but can not work in JS file.
First of all: JSP files will be executed on the server as it is server side code. However, a js file will be executed AFTER all server side code is processed and the HTML output is sent to the client, as JavaScript is client side code. Long story short, what you are trying to achieve is simply not possible in the way you are trying.
So why is it working in JSP?
Your JavaSript will be executed AFTER the tag <portlet:namespace> has been processed on the server, which means on execution time of JavaScript, there isn't the tag anymore, but the evaluated portlet namespace.
A possible workaraound would be to call the JS funtion from the JSP and pass the namespace as a parameter to your function. Another would be to put a hidden field on your page with the namespace in it and retrieve the value of the field via JavaScript.

Hope this helps you ;)

So long
thumbnail
Priyanka Dhingra,修改在11 年前。

RE: how to put <portlet:namespace> in main.js

Liferay Master 帖子: 501 加入日期: 11-12-20 最近的帖子
try putting as follows
jquery code:$('#<portlet:namespace />'+&lt;%=ProductDisplayTerms.STANDARD%&gt;).val(value);
thumbnail
Jan Geißler,修改在11 年前。

RE: how to put <portlet:namespace> in main.js

Liferay Master 帖子: 735 加入日期: 11-7-5 最近的帖子
This will also not work in a JS file.....
thumbnail
Priyanka Dhingra,修改在11 年前。

RE: how to put <portlet:namespace> in main.js

Liferay Master 帖子: 501 加入日期: 11-12-20 最近的帖子
I missed main.js

for that there is a workaround
in view.jsp:-
<script>
productStandard = ''<portlet:namespace/>''+<%=ProductDisplayTerms.STANDARD%>;
</script>


in main.js

var productStandard ; //declare it globally

$('#'+productStandard ).val(value);
wei tang,修改在11 年前。

RE: how to put <portlet:namespace> in main.js

Junior Member 帖子: 36 加入日期: 12-12-3 最近的帖子
maybe this is good idea. anyone else?
thumbnail
Jan Geißler,修改在11 年前。

RE: how to put <portlet:namespace> in main.js

Liferay Master 帖子: 735 加入日期: 11-7-5 最近的帖子
Just as I said in my post where I explained why it can not work, I gave you 2 solutions. Here the way I would do it:
<script>
thisIsMyFunctionCall(<portlet:namespace/>);
</script>
thumbnail
Avinash R,修改在10 年前。

RE: how to put <portlet:namespace> in main.js

New Member 帖子: 13 加入日期: 13-9-19 最近的帖子
how about not thinking about the <portlet:namespace/> ?

Usually, the portlet will be having a wrapper with the class defined in liferay-portlet.xml

This is usually what you are supposed to define.

so instead of using the <porlet:namespace>, can't you use this to get your form elements?

eg:

$(function() {
  var wrapper = $(".my-portlet');
  //use wrapper.find to get the elements by it's name or class
});


or using AUI:


AUI().ready("node", function(A) {
  var wrapper = A.one(".my-portlet');
  //use wrapper.one or wrapper.all to get the element(s) by it's name or class
});


where my-portlet is the css class that you defined.

HTH.
thumbnail
Olaf Kock,修改在9 年前。

RE: how to put <portlet:namespace> in main.js

Liferay Legend 帖子: 6403 加入日期: 08-9-23 最近的帖子
Avinash R:
how about not thinking about the <portlet:namespace/> ?

Usually, the portlet will be having a wrapper with the class defined in liferay-portlet.xml


works only for non-instanciable portlets, and only if nobody else chooses the same wrapper name. As soon as you can have two portlets of the same kind on the same page, you'll effectively address all of them.
thumbnail
Borxa Varela Bouzas,修改在9 年前。

RE: how to put <portlet:namespace> in main.js

Junior Member 帖子: 69 加入日期: 06-12-26 最近的帖子
var ppid = "";
AUI().ready('node', function(A){
ppid = this.config.win.ppid;
});
thumbnail
Olaf Kock,修改在9 年前。

RE: how to put <portlet:namespace> in main.js

Liferay Legend 帖子: 6403 加入日期: 08-9-23 最近的帖子
Borxa Varela Bouzas:
var ppid = "";
AUI().ready('node', function(A){
ppid = this.config.win.ppid;
});


Also works only on noninstanciable portlets. As soon as you have two of the same kind on page, you'll get a duplicate global variable.

There's a reason for <portlet:namespace/> - here you have found one.
thumbnail
Borxa Varela Bouzas,修改在9 年前。

RE: how to put <portlet:namespace> in main.js

Junior Member 帖子: 69 加入日期: 06-12-26 最近的帖子
I don't know other way to get portlet namespace only inside main.js for all kind of portlets.

One way (but no only in main.js) could be to put in init.jsp:


<script type="text/javascript">
     var ppid = "<portlet:namespace/>";
     ppid = ppid.substring(1,ppid.length - 1);
</script>


After, you will have variable for use in your main.js
thumbnail
Olaf Kock,修改在9 年前。

RE: how to put <portlet:namespace> in main.js

Liferay Legend 帖子: 6403 加入日期: 08-9-23 最近的帖子
Instead of using the implicit global variable ppid that can be overridden by any other portlet on the same page, rather use <portlet:namespace/> as a parameter to the functions that you have in main.js.

E.g. instead of attempting

  function doSomethingOnDOM() {
     var e = document.getElementById("<portlet:namespace />MyId");
     // do something with e
  }


rather do

  function doSomethingOnDOM(element) {
    var e = document.getElementById(element);
    // do something with e
  }


and call it from your jsp with <portlet:namespace/> as parameter