Foren

hide / show jsf portlet at runtime

Eric Soucy, geändert vor 8 Jahren.

hide / show jsf portlet at runtime

Junior Member Beiträge: 65 Beitrittsdatum: 21.01.14 Neueste Beiträge
Hello,
I have two jsf portlets on the same liferay page.
I would like to show the 1st portlet and hide the second one when the page is first displayed.
Then, based on a user action in the 1st portlet, I would like to show the second portlet.

I would like to know the best way this show/hide my second portlet.

If this is done in java in the (jsf) portlet, I would like to know how? using a phase listener and sessions attributes ?

I have seen https://www.liferay.com/community/forums/-/message_boards/message/3476580
and this https://www.liferay.com/community/forums/-/message_boards/message/40733729

thanks
thumbnail
David H Nebinger, geändert vor 8 Jahren.

RE: hide / show jsf portlet at runtime

Liferay Legend Beiträge: 14918 Beitrittsdatum: 02.09.06 Neueste Beiträge
Hey, Eric, normally this is frowned upon. A portlet should only be managing it's own HTML fragment and should not be trying to manage what the portal is doing.

Even IPC was designed to support things like a list/detail perspective where a selection from a list should update the detail portlet, but this is not highly used and does not allow for managing what the portal is doing.

I have done things like this using javascript where the display will change between none and block to manage the whole portlet div, but it was flaky at best. Some browsers, even though the div was hidden, would not adjust the remaining content up.

If you really need this kind of functionality, I would try creating a new portlet modeled after the nested portlet from Liferay. Let it be the determiner of whether to include the nested portlet or not, that way the content would be totally excluded from the rendered HTML.
thumbnail
Juan Gonzalez, geändert vor 8 Jahren.

RE: hide / show jsf portlet at runtime

Liferay Legend Beiträge: 3089 Beitrittsdatum: 28.10.08 Neueste Beiträge
Hi Eric,

if you are using Liferay Faces you could try the new portal:runtime component to embed portlets, and then use "rendered" to control them.

You have some examples here:

liferayfaces.org/web/guest/showcase/-/component/portal/runtime/multiple-instances
Eric Soucy, geändert vor 8 Jahren.

RE: hide / show jsf portlet at runtime

Junior Member Beiträge: 65 Beitrittsdatum: 21.01.14 Neueste Beiträge
Is this available only with Liferay Faces 4.2.0 ?

We are currently with 3.2.5 ga4

Thanks
thumbnail
Juan Gonzalez, geändert vor 8 Jahren.

RE: hide / show jsf portlet at runtime

Liferay Legend Beiträge: 3089 Beitrittsdatum: 28.10.08 Neueste Beiträge
Hi Eric,

no, it's also available in 3.2.5-rc1-SNAPSHOT.
Eric Soucy, geändert vor 8 Jahren.

RE: hide / show jsf portlet at runtime

Junior Member Beiträge: 65 Beitrittsdatum: 21.01.14 Neueste Beiträge
Juan Gonzalez:
Hi Eric,

no, it's also available in 3.2.5-rc1-SNAPSHOT.



Thanks
do we know when are 4.2.5 and 3.2.5 due for GA (Q3 2015?)
thumbnail
Neil Griffin, geändert vor 8 Jahren.

RE: hide / show jsf portlet at runtime

Liferay Legend Beiträge: 2655 Beitrittsdatum: 27.07.05 Neueste Beiträge
Hi Eric,

We are working on 4.2.5-rc1/3.2.5-rc1 right now and the goal to release those at the end of this month (June 2015). We may have to follow-up with 4.2.5-rc2/3.2.5-rc2. But hopefully 4.2.5-ga6/3.2.5-ga6 will be available soon thereafter.

Kind Regards,

Neil
thumbnail
David H Nebinger, geändert vor 8 Jahren.

RE: hide / show jsf portlet at runtime

Liferay Legend Beiträge: 14918 Beitrittsdatum: 02.09.06 Neueste Beiträge
Juan Gonzalezif you are using Liferay Faces you could try the new portal:runtime component to embed portlets, and then use "rendered" to control them.

You have some examples here:

liferayfaces.org/web/guest/showcase/-/component/portal/runtime/multiple-instances


Sweet! Thanks, Juan! I learned something new today!

Eric, Juan's suggestion is going to be better than mine if you can leverage the component.
Eric Soucy, geändert vor 8 Jahren.

RE: hide / show jsf portlet at runtime

Junior Member Beiträge: 65 Beitrittsdatum: 21.01.14 Neueste Beiträge
Juan GonzalezHi Eric,

if you are using Liferay Faces you could try the new portal:runtime component to embed portlets, and then use "rendered" to control them.

You have some examples here:

liferayfaces.org/web/guest/showcase/-/component/portal/runtime/multiple-instances



Hello Juan, can you explain more about using "rendered" to control them ?

thanks
thumbnail
Neil Griffin, geändert vor 8 Jahren.

RE: hide / show jsf portlet at runtime

Liferay Legend Beiträge: 2655 Beitrittsdatum: 27.07.05 Neueste Beiträge
Hi Eric,

I think Juan was thinking something like this:

<alloy:commandbutton value="Show Runtime Portlet" render="runtimePortlet">
    <f:setpropertyactionlistener target="#{viewBacking.runtimePortletRendered}" value="true" />
</alloy:commandbutton>
<alloy:commandbutton value="Hide Runtime Portlet" render="runtimePortlet">
    <f:setpropertyactionlistener target="#{viewBacking.runtimePortletRendered}" value="false" />
</alloy:commandbutton>

<portal:runtime id="runtimePortlet" portletName="56_INSTANCE_ABCD1234" rendered="#{viewBacking.runtimePortletRendered}" />


Kind Regards,

Neil
Eric Soucy, geändert vor 8 Jahren.

RE: hide / show jsf portlet at runtime

Junior Member Beiträge: 65 Beitrittsdatum: 21.01.14 Neueste Beiträge
hello Neil,
Where is the documentation of the tag portal:runtime ?
i'm looking here http://liferayfaces.org/doc/faces/4.2/vdldoc/ but I don't see it.


Thanks a lot
thumbnail
Neil Griffin, geändert vor 8 Jahren.

RE: hide / show jsf portlet at runtime

Liferay Legend Beiträge: 2655 Beitrittsdatum: 27.07.05 Neueste Beiträge
Hi Eric,

Oh, it looks like we didn't re-generate the VDLDoc and upload it to liferayfaces.org when we released 4.2.0-beta. I'll work on that soon.

For now, you can look at line 387 of components-ext.xml in the source.

Kind Regards,

Neil
Eric Soucy, geändert vor 8 Jahren.

RE: hide / show jsf portlet at runtime

Junior Member Beiträge: 65 Beitrittsdatum: 21.01.14 Neueste Beiträge
Hello
Another question for you
I have a portlet named "container", it has a view with the portal:runtime tags in it. These tags points to two other portlets A and B. all portlets are in different war files.

When the portlet "container"is first shown, portlet A is visible and portlet B is not (using rendered attribute with values based on a managed bean).

Based on an action done in portlet A (button click for example) i want Portlet A to become hidden and portlet B to show.

How would I do that?
1 have a managed bean in my portlet "container" and put it in portal session and share it with A and B (if so how) ?
2 use IPC between portlet A and portlet "container" to tell the latter to change the rendered attribute values in it's managed bean
3 use other methods ? public render parameter?


Thanks so much

Eric
thumbnail
Juan Gonzalez, geändert vor 8 Jahren.

RE: hide / show jsf portlet at runtime

Liferay Legend Beiträge: 3089 Beitrittsdatum: 28.10.08 Neueste Beiträge
Hi Eric,

if I understood right, then this is just a JSF conditional rendering. Just have an action that changes the "rendered" value on whichever portlet you want to show/hide and that's all, something similar from Neil's code snippets above.

Just use "rendered" attribute and play with it. Maybe you want to learn some basic JSF tutorial about its usage.
Eric Soucy, geändert vor 8 Jahren.

RE: hide / show jsf portlet at runtime

Junior Member Beiträge: 65 Beitrittsdatum: 21.01.14 Neueste Beiträge
Juan Gonzalez:
Hi Eric,

if I understood right, then this is just a JSF conditional rendering. Just have an action that changes the "rendered" value on whichever portlet you want to show/hide and that's all, something similar from Neil's code snippets above.

Just use "rendered" attribute and play with it. Maybe you want to learn some basic JSF tutorial about its usage.



Hello,
In my managed bean that is packaged (same war) with my "container" portlet, I have action methods that change boolean values associated with the rendered attributes.

My issue is : how to call these methods from another portlet (portlet A in another war).


Thanks
thumbnail
Juan Gonzalez, geändert vor 8 Jahren.

RE: hide / show jsf portlet at runtime

Liferay Legend Beiträge: 3089 Beitrittsdatum: 28.10.08 Neueste Beiträge
Oh I see.

In that case, you should use IPC (InterPortlet Communication) between portlet A, and the first one. When receiving the event, you should change the flag from your @ManagedBean, in order to take control under your rendered portlets. You can take a look at our IPC demo examples from github:

https://github.com/liferay/liferay-faces/blob/master/demos/bridge/jsf2-ipc-events-customers-portlet/src/main/java/com/liferay/faces/demos/event/CustomerEditedEventHandler.java#L41-46
Eric Soucy, geändert vor 8 Jahren.

RE: hide / show jsf portlet at runtime

Junior Member Beiträge: 65 Beitrittsdatum: 21.01.14 Neueste Beiträge
Hello,
In the same architecture, my portlet A (which is embedded in the container portlet) has a button inside it that calls an action in a managedbean. When I try it I get an error in the logs (and console) :

 WARN [SecurityPortletContainerWrapper:623] Reject process action for ...


and my action is never called.

Is there something I am missing ?

Thanks
Eric Soucy, geändert vor 8 Jahren.

RE: hide / show jsf portlet at runtime

Junior Member Beiträge: 65 Beitrittsdatum: 21.01.14 Neueste Beiträge
I have some new information about my problem
I set the loglevel to debug and now I see:

DEBUG [http-bio-8443-exec-9][SecurityPortletContainerWrapper:617] null
com.liferay.portal.security.auth.PrincipalException: Invalid authentication token
        at com.liferay.portal.security.auth.SessionAuthToken.checkCSRFToken(SessionAuthToken.java:83)
...
WARN  [http-bio-8443-exec-9][SecurityPortletContainerWrapper:623] Reject process action for ...


Because i use the portal:runtime tag it seems my portlet A that is included is having an issue with the p_auth?
thumbnail
Juan Gonzalez, geändert vor 8 Jahren.

RE: hide / show jsf portlet at runtime

Liferay Legend Beiträge: 3089 Beitrittsdatum: 28.10.08 Neueste Beiträge
Yes, there is an issue with that. Let me do some checks this week.
Eric Soucy, geändert vor 8 Jahren.

RE: hide / show jsf portlet at runtime

Junior Member Beiträge: 65 Beitrittsdatum: 21.01.14 Neueste Beiträge
Hello Juan,
Any news on the issue ?

Thanks so much

Eric
thumbnail
Juan Gonzalez, geändert vor 8 Jahren.

RE: hide / show jsf portlet at runtime

Liferay Legend Beiträge: 3089 Beitrittsdatum: 28.10.08 Neueste Beiträge
Hi Eric,

I was thinking on how to implement a sample portlet itselft but there are many possible combinations that may not be the case you implemented.

Please, can you build a simple portlet so I can reproduce and focus on the specific problem?

Thanks!
Eric Soucy, geändert vor 8 Jahren.

RE: hide / show jsf portlet at runtime

Junior Member Beiträge: 65 Beitrittsdatum: 21.01.14 Neueste Beiträge
Juan,
Here is an example

Thanks
thumbnail
Juan Gonzalez, geändert vor 8 Jahren.

RE: hide / show jsf portlet at runtime

Liferay Legend Beiträge: 3089 Beitrittsdatum: 28.10.08 Neueste Beiträge
Hi Eric,

thanks very much for your sample portlet! It helped a lot.

We are investigating the issue.

Thanks!
thumbnail
Juan Gonzalez, geändert vor 8 Jahren.

RE: hide / show jsf portlet at runtime

Liferay Legend Beiträge: 3089 Beitrittsdatum: 28.10.08 Neueste Beiträge
Hi Eric,

ok, after some checks seems this is an issue in Liferay Portal when using custom portlets rendering other custom portlets. Please watch this issue if you want to track it:

https://issues.liferay.com/browse/LPS-56769

Fortunately, there is a workaround but this can lead to some CSRF security problems with your embedded portlet. To disable this protection just add this portal-ext.property:

auth.token.ignore.portlets=82,poc_master_WAR_poc_master10SNAPSHOT


As you may have notice, portlet name can change depending on your real environment.

Last thing, you can remove:

<add-default-resource>true</add-default-resource>
from your portlets as this doesn't apply here.

Hope it helps!
Eric Soucy, geändert vor 8 Jahren.

RE: hide / show jsf portlet at runtime

Junior Member Beiträge: 65 Beitrittsdatum: 21.01.14 Neueste Beiträge
Thank you Juan
Another way is to change the portlet.xml file to add :
		
<init-param>
			<name>check-auth-token</name>
			<value>false</value>
		</init-param>


I find it to be better than edit the portal-ext.properties.