Message Boards

how do I hide a portlet from another page?

Tiago Machado, modified 5 Years ago.

how do I hide a portlet from another page?

Junior Member Posts: 59 Join Date: 2/21/19 Recent Posts
hello, I currently have a portlet with a carousel and below that portlet I have another called movies, where it has an image too and 3 buttons, if I click in the add movie or view movies it redirects me to another page(jsp) but shows the carousel portlet too... I want to show the carousel only in the home page, only in the view.jsp... 

my structure is the following:

-db-portlet-manipulation
    -modules
        -carousel (liferay module (mvc portlet))
        -movies (api - service - web)

I didnt create any pages at build -> pages I'm just using the welcome, that is maked as home.

how can I show the carousel only at the main page (view.jsp) and prevent it from showing in other pages?

​​​​​​​thank you!
thumbnail
Fernando Fernandez, modified 5 Years ago.

RE: how do I hide a portlet from another page?

Expert Posts: 396 Join Date: 8/22/07 Recent Posts
Hi Tiago,

When you jump to the second JSP you can maximize the portlet to occupy the whole page, something like this:

    public void jumpP2(ActionRequest rq, ActionResponse rs) throws WindowStateException {
        rs.setRenderParameter("jspPage", "/view2.jsp");
        rs.setWindowState(WindowState.MAXIMIZED);
    }

HTH

Fernando
Tiago Machado, modified 5 Years ago.

RE: how do I hide a portlet from another page?

Junior Member Posts: 59 Join Date: 2/21/19 Recent Posts
Hello Fernando, thank you for the answer,

Im using MVCRenderCommand, so I cant really use the ActionResponse there.

When I click the view movies button, it will go to the ViewMoviesMVCRenderCommand...
isnt there any  other way?

thank you very much
thumbnail
Fernando Fernandez, modified 5 Years ago.

RE: how do I hide a portlet from another page?

Expert Posts: 396 Join Date: 8/22/07 Recent Posts
Tiago MachadoHello Fernando, thank you for the answer,

Im using MVCRenderCommand, so I cant really use the ActionResponse there.

When I click the view movies button, it will go to the ViewMoviesMVCRenderCommand...
isnt there any  other way?

thank you very much

Hi Tiago,

I never used it myself but you might be able to use renderRequest.setWindowState(WindowState.MAXIMIZED), or something like that.

HTH

​​​​​​​Fernando
thumbnail
Gnaniyar Zubair, modified 5 Years ago.

RE: how do I hide a portlet from another page?

Liferay Master Posts: 722 Join Date: 12/19/07 Recent Posts
Hi,

Your requirement is not clear. You have a portal page of "Home"  where you have placed two portlets 1. Carousel 2. Movie

when you click the action on "Movie" portlet, it redirects to some other jsp page of the "Movie" portlet but in same "Home "page. 

Hope my understanding is correct?

Here is the solutions:

Option I :

       1. Set the proprty in portal-ext.properties as below

        layout.show.portlet.access.denied=false

      2.  Assign the users ( who can access "View" Page) to custom role.

      3. Add this below code to remove the permission in rendering of the portlet when triggering any button:
​​​​​​​ResourcePermissionLocalServiceUtil.removeResourcePermission(
themeDisplay.getCompanyId(), portlet.getPortletName(),
ResourceConstants.SCOPE_INDIVIDUAL, primKey, roleId,
ActionKeys.VIEW);

where

primKey - PortletPermissionUtil.getPrimaryKey(themeDisplay
.getPlid(), portlet.getPortletId());

roleId = your custom role id

portletId = which portlet you want to hide


Option II :

        1.  Set the portlet session when action is triggered from Movie portlet

        2. Get the session and if session is not empty then add this script:
[code]<%
String hideORShowSessionValue= portletSession.getAttribute("HIDE");

if (hideORShowSessionValue.equlas("HIDE")) { 
    renderRequest.setAttribute(WebKeys.PORTLET_CONFIGURATOR_VISIBILITY, Boolean.FALSE);
} else {
    renderRequest.setAttribute(WebKeys.PORTLET_CONFIGURATOR_VISIBILITY, Boolean.TRUE);
}
%>


Option III : 

           You can hide through css also which is not recommended as per web practice.

$('#portletId').css({display:'none'});[code] 

  OR


[code]document.getElementById(portletId).style.display = 'none';
portletId = which portlet you want to hide from page


​​​​​​​HTH
Tiago Machado, modified 5 Years ago.

RE: how do I hide a portlet from another page?

Junior Member Posts: 59 Join Date: 2/21/19 Recent Posts
Hello and thanks for the answer!

but saddly it didn't work emoticon I didnt't try the option 3 since it doesn't seems pratical,

Option I didn't work and was getting an "Syntax error on tokens, delete these tokens" at the following code:        ​​​​​​​ResourcePermissionLocalServiceUtil.removeResourcePermission(themeDisplay.getCompanyId(), portlet.getPortletName(), ResourceConstants.SCOPE_INDIVIDUAL, primKey, roleId, ActionKeys.VIEW);

and option II didnt work too.

And yes you undestood the problem, im sorry I got you confused, im gonna try to explain the problem again with details:

So, When I go to the portal at localhost, in Liferay -> Build -> Pages, I have the Search and the Welcome[Home],
I didn't touch this. If I click "Go to Site", there I have the portlets I Programmed, the Carousel that has 3 images, this is like showing new movies, and after that portlet I have the movies portlet, that has one simple image and below it has some buttons, one of them for example is the view movies that will list some added movies.
This 2 portlets are in the Welcome[Home] page.

Its ok for all users view the portlets, at least for now, since im just training and learning liferay... but I want to just see the carousel in the first page, my view.jsp.
For example, i enter localhost, i see the carousel and the movies portlet, but when I click the action button view movies where the list appears i dont want to see the carousel portlet, that portlet should just show at the main page(view.jsp) in the Welcome[Home] page, and not in the view_movies.jsp. 

take note the project structure I told in the first post please, inside modules i have my 2 diff portlets, movies and carousel, movies contain the bussiness logic, all my jsp's to show, add, edit, etc. and the carousel just have 2 jsp's, the view that shows the carousel with the images and well the init xD. it has a css file and images too to show in the  carousel.

and thats all. hope you understood more about my issue and what i want to do.

​​​​​​​thanks a lot.
thumbnail
Christoph Rabel, modified 5 Years ago.

RE: how do I hide a portlet from another page?

Liferay Legend Posts: 1554 Join Date: 9/24/09 Recent Posts
I think, you should create two pages (or more). I am not sure, I understood your description correctly, but I think this should fit pretty well:

On the first page, the landing page, you add only the carousel portlet. From there, you link to the second page.
On the second page, you don't add the carousel portlet. You only add the movies portlet.

That way, you don't have to do anything complicated. You just have different pages and each page shows what it should show.
You don't need to programm everything, the advantage of Liferay is that you can configure a lot of things.
Tiago Machado, modified 5 Years ago.

RE: how do I hide a portlet from another page?

Junior Member Posts: 59 Join Date: 2/21/19 Recent Posts
Thank you very much for the answer! i will try to do that and give some feedback after. thanks!
Tiago Machado, modified 5 Years ago.

RE: how do I hide a portlet from another page?

Junior Member Posts: 59 Join Date: 2/21/19 Recent Posts
I cant do it... emoticon

I can create a page, and I can give the link in eclipse, so when I click that page is open, but that will just open a blank page, there is no way unless I can say to render my jsp page from eclipse. I have my ViewMoviesMVCRenderCommand at eclipse, and I cant just reach that from here or can I?

there must be some solution to show the portlet only in the first page. I should be able to have 2 portlets there, and if a do some action to another page there should be some way to not show the portlet.

if I find some solution ill share it here, if someone can helps it woul mean a lot.

​​​​​​​thanks!
thumbnail
Gnaniyar Zubair, modified 5 Years ago.

RE: how do I hide a portlet from another page?

Liferay Master Posts: 722 Join Date: 12/19/07 Recent Posts
Not sure why option 1 and 2 doesn't help you. It should work. Need to check the permission related issue in dxp.

Ok i got your requirement. You can do one thing. Create only one portlet ( Movies) and which has two division
1. carouse 2. movies pare ( action buttons), so when you click the action, it will redirect to another jsp page where you cannot see the carousel.... 

​​​​​​​HTH
Tiago Machado, modified 5 Years ago.

RE: how do I hide a portlet from another page?

Junior Member Posts: 59 Join Date: 2/21/19 Recent Posts
Hello, thank you for the answer.

That way works fine, but I really wanted to have 2 different portlets, one for carousel and the other for the movies, this way I just needed to put the carrousel code in the view.

But what if I want to use multiple portlets? and just show some of that portlets in a particular page and dont show the others? I shouln't be using only one portlet for all...

Anyway, thanks a lot for you time!!
thumbnail
Christoph Rabel, modified 5 Years ago.

RE: how do I hide a portlet from another page?

Liferay Legend Posts: 1554 Join Date: 9/24/09 Recent Posts
I am a bit at a loss, because I don't understand what you are doing there.

NOTE: A page is NOT a jsp. You configure pages in Liferay, but your jsps show content in your portlet. I think, you are mixing that up somewhat. You can have as many pages you want and put as many portlets as you want on them. But you jsps always just show content in the area they occupy on a page.

Let me explain how I would solve the problem, that I think you have (I have no idea, if I understood it correctly):

1) Start Liferay
2) Login as admin
3) Go to Pages, create a page "Carousel"
4) In the header, right side, there is a "+" button. Click it, select Widgets, find your "Carousel" portlet and drag & drop it on the page.
5) Create a new page "Movies".
6) In the header, right side, there is a "+" button. Click it, select Widgets, find your "Movies" portlet and drag & drop it on the page.
7) Change the links on the carousel portlet to link to the "Movies" page.
 
Tiago Machado, modified 5 Years ago.

RE: how do I hide a portlet from another page?

Junior Member Posts: 59 Join Date: 2/21/19 Recent Posts
sorry for the late reply,
Thanks for the answer, that option works well, since I couln't do it the way I wanted I did it that way.

​​​​​​​thanks a lot guys!