Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Kowbathullah Gnaniyar
View based on Role - Primefaces
April 14, 2013 2:53 AM
Answer

Kowbathullah Gnaniyar

Rank: Liferay Master

Posts: 608

Join Date: December 19, 2007

Recent Posts

How to redirect to different View based on the Roles in Primefaces portlet.

In MVC, we can change the view in render method by overriding viewTempale based on the role. But I am not sure how to change the view in Primefaces

Any idea?

- Gnaniyar Zubair
Vernon Singleton
RE: View based on Role - Primefaces
April 14, 2013 3:03 PM
Answer

Vernon Singleton

LIFERAY STAFF

Rank: Expert

Posts: 291

Join Date: January 14, 2013

Recent Posts

Hi Gnaniyar,

You might try looking at the jsf2-registration-portlet demo.
It deals with roles quite a bit in the portal context.

Also, if you want to do a redirect, a plain way of doing so
is usually to use a navigation-rule in faces-config.xml, and
then specify <redirect /> within the navigation rule something like this:
https://github.com/vsingleton/liferay-faces/blob/3.1.x/demos/portal/icefaces3-documents-portlet/src/main/webapp/WEB-INF/faces-config.xml

Whether you are using Primefaces or WhateverFaces,
the redirecting should be the same when using a navigation rule, I would think.

By the way, you can build all of the Liferay Faces Demos (including the jsf2-registration-portlet) for yourself by following these instructions:
http://www.liferay.com/community/wiki/-/wiki/Main/Building+Liferay+Faces+From+Source

Hope that helps,
Vernon
Kowbathullah Gnaniyar
RE: View based on Role - Primefaces
April 14, 2013 10:21 PM
Answer

Kowbathullah Gnaniyar

Rank: Liferay Master

Posts: 608

Join Date: December 19, 2007

Recent Posts

Thanks. I have handled the navigation through navigation-rule in faces-config.xml. I dont have an issue to redirect.

I have to direct to different view.xhtml based on the role when portlet loads. For example, in MVC portlet, I will write logic in render method like this:

if(role1) {
viewJSP = "view1.jsp"
} else if(role 2) {
viewJSP = "view2.jsp";
}

now in JSF portlet, how to achieve above scenario ?
Vernon Singleton
RE: View based on Role - Primefaces
April 15, 2013 3:34 AM
Answer

Vernon Singleton

LIFERAY STAFF

Rank: Expert

Posts: 291

Join Date: January 14, 2013

Recent Posts

Gnaniyar Zubair:
Thanks. I have handled the navigation through navigation-rule in faces-config.xml. I dont have an issue to redirect.

I have to direct to different view.xhtml based on the role when portlet loads. For example, in MVC portlet, I will write logic in render method like this:

if(role1) {
viewJSP = "view1.jsp"
} else if(role 2) {
viewJSP = "view2.jsp";
}

now in JSF portlet, how to achieve above scenario ?


So, if you put that code in your backing bean, you could then do something like this:

 1<navigation-rule>
 2   <from-view-id>/views/startPage.xhtml</from-view-id>
 3   <navigation-case>
 4      <from-outcome>view1</from-outcome>
 5      <to-view-id>/views/view1.xhtml</to-view-id>
 6      <redirect />
 7   </navigation-case>
 8   <navigation-case>
 9      <from-outcome>view2</from-outcome>
10      <to-view-id>/views/view2.xhtml</to-view-id>
11      <redirect />
12   </navigation-case>
13</navigation-rule>
Vernon Singleton
RE: View based on Role - Primefaces
April 15, 2013 8:42 AM
Answer

Vernon Singleton

LIFERAY STAFF

Rank: Expert

Posts: 291

Join Date: January 14, 2013

Recent Posts

Gnaniyar Zubair:
Thanks. I have handled the navigation through navigation-rule in faces-config.xml. I dont have an issue to redirect.

I have to direct to different view.xhtml based on the role when portlet loads. For example, in MVC portlet, I will write logic in render method like this:

if(role1) {
viewJSP = "view1.jsp"
} else if(role 2) {
viewJSP = "view2.jsp";
}

now in JSF portlet, how to achieve above scenario ?


Perhaps an even better way to code this is to simply use something like this in your main view:
<ui:include src="#{myBackingBean.role}.xhtml" />

And then create role1.xhtml and role2.xhtml ui:composition files.
Kowbathullah Gnaniyar
RE: View based on Role - Primefaces
April 18, 2013 12:24 AM
Answer

Kowbathullah Gnaniyar

Rank: Liferay Master

Posts: 608

Join Date: December 19, 2007

Recent Posts

It works fine. Thanks Vernon.
Vernon Singleton
RE: View based on Role - Primefaces
April 18, 2013 4:49 AM
Answer

Vernon Singleton

LIFERAY STAFF

Rank: Expert

Posts: 291

Join Date: January 14, 2013

Recent Posts

Glad to hear it is working for you.

Enjoy using Liferay.