【问题标题】:How to get client side portlet-id in liferay?如何在liferay中获取客户端portlet-id?
【发布时间】:2012-11-27 19:37:56
【问题描述】:

我在我的 liferay portlet 中使用 AlloyUI。

我想在 javascript 中使用我的 <input> 的 ID。问题是元素的id在客户端发生了变化。

例如:
如果我将 <input> 的 Id 设置为“用户名”,它将更改为 _hospital_WAR_hospitalportlet_userName,即 _hospital_WAR_hospitalportlet_ 附加到 Id,其中 Hospital 是我的 portlet 名称。

如何获取客户端 ID 以便在 jquery 中使用它?

【问题讨论】:

    标签: liferay liferay-6 alloy-ui


    【解决方案1】:

    <input>Id 前面的字符串 _hospital_WAR_hospitalportlet_ 只不过是 portlet 命名空间。

    如果您使用 <aui:input> 标签,这只会添加到您的 <input>nameid 属性之前,如果您只使用普通 html,则不会更改 nameid 属性<input> 标签。

    但由于使用<aui:input> 是一种很好的做法,您可以执行以下操作以在您的 javascript 代码中获取 portlet 命名空间:

    1. 如果您在 JSP 中使用 javascript,即在 <script> .. </script><aui:script> .. </aui:script> 中使用,那么您可以使用 <portlet:namespace /><%= renderResponse.getNamespace() %> 来获取字符串_hospital_WAR_hospitalportlet_ 在你的 javascript 中,类似的东西。

      jQuery("#<portlet:namespace />username").val();
      
      // Or
      
      jQuery("#<%= renderResponse.getNamespace() %>username").val();
      
    2. 但如果您使用的是*.js 文件,那么我建议您将命名空间作为参数传递给js 文件中的javascript 函数:

      function changeValues(portletNamespace) { // this function is in a js file
          jQuery("#" + portletNamespace + "username").val("Lets change");
      }
      

      从 JSP 调用这个函数:

      <input type="button" onClick="changeValues('<portlet:namespace />')" />
      

    希望这会有所帮助。不知道有没有办法通过Liferay定义的一些javascript函数直接获取namespaceportletId。如果你得到类似的东西,你可以在这里发布,这将非常有帮助。

    【讨论】:

      【解决方案2】:

      试试这个:

      Liferay.Portlet.ready(
      
          /*
          This function gets loaded after each and every portlet on the page.
      
          portletId: the current portlet's id
          node: the Alloy Node object of the current portlet
          */
      
          function(portletId, node) {
          }
      );
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-07-10
        • 2011-10-22
        • 2013-03-18
        • 2014-06-02
        • 2017-08-19
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多