如何通过使用JavaScript在Liferay中隐藏Portlet [英] How to hide portlet in liferay by using javascript

查看:33
本文介绍了如何通过使用JavaScript在Liferay中隐藏Portlet的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

实际上在单个页面上我有2个portlet,但是我想通过单击submit按钮隐藏第一个portlet,并且只有第二个portlet应该可见,我使用了以下代码:

Actually on a single page I have 2 portlet but I want to hide the first portlet by clicking the submit button and only the second portlet should be visible I used the following code:

document.getElementById("portlet-id").style.visibility='none'

但是刷新页面后,仍然可以看到portlet,任何人都可以向我提供有关如何进行的解决方案.

But after refreshing the page, again portlet is visible can anyone provide me the solution as to how I can proceed.

推荐答案

您可以使用以下代码在JSP中将portlet的visibility设置为false:

You can set the visibility of the portlet to false in the JSP by using the following code:

<%
renderRequest.setAttribute(WebKeys.PORTLET_CONFIGURATOR_VISIBILITY, Boolean.FALSE);
%>

这将从用户的角度隐藏您的portlet.

This would hide your portlet from user's view.

每次呈现portlet时,您都可以检查在请求或会话(您的选择)中设置的参数,以显示portlet或不显示portlet,例如:

Everytime your portlet is rendered you can check a parameter which was set in the request or session (your choice) to either show the portlet or not show the portlet, like:

<%
String paramFromRequestToHide = renderRequest.getParameter("hidePortlet");
// can also fetch from session: portletSession.getAttribute("hidePortlet");

if (paramFromRequestToHide .equals("YES")) { // you can use your favorite data-type
    renderRequest.setAttribute(WebKeys.PORTLET_CONFIGURATOR_VISIBILITY, Boolean.FALSE);
} else {
    renderRequest.setAttribute(WebKeys.PORTLET_CONFIGURATOR_VISIBILITY, Boolean.TRUE);
}
%>


另一种方法:


如果您不想采用上述方法,则可以将javascript方法与参数方法结合使用,如下所示:


Another method:


If you don't want to go with the above approach then you can combine your javascript approach with the parameter approach as follows:

<%
String paramFromRequestToHide = renderRequest.getParameter("hidePortlet");

if (paramFromRequestToHide .equals("YES")) {
%>

<aui:script>
    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) {
            document.getElementById(portletId).style.display = 'none';
            // or alternatively using pure Alloy UI
            // node.hide();
        }
    );
</aui:script>

<%
} else {
%>

<aui:script>
    Liferay.Portlet.ready(
        function(portletId, node) {
            document.getElementById(portletId).style.display = 'block';
            // or alternatively using pure Alloy UI
            // node.show();
        }
    );
</aui:script>

<%
}
%>

如果您要签出合金UI API 和一些<从Liferay 6.1开始,a href ="http://deploy.alloyui.com/" rel ="nofollow">演示即可学习Alloy UI,Alloy UI是Liferay的事实上的JavaScript库.现在,Alloy UI拥有一个官方网站,其中包含许多有用的教程和示例.

In case you want to check-out Alloy UI API and some of the demos to learn Alloy UI since starting from Liferay 6.1 Alloy UI is the de-facto javascript library for liferay. Now Alloy UI has an official web-site with many helpful tutorials and examples.

希望这为您提供了足够的素材来进行:-)

Hope this gives you ample material to proceed :-)

这篇关于如何通过使用JavaScript在Liferay中隐藏Portlet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆