Forums de discussion

View based on Role - Primefaces

thumbnail
Gnaniyar Zubair, modifié il y a 11 années.

View based on Role - Primefaces

Liferay Master Publications: 722 Date d'inscription: 19/12/07 Publications récentes
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
thumbnail
Vernon Singleton, modifié il y a 11 années.

RE: View based on Role - Primefaces

Expert Publications: 315 Date d'inscription: 14/01/13 Publications récentes
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
thumbnail
Gnaniyar Zubair, modifié il y a 11 années.

RE: View based on Role - Primefaces

Liferay Master Publications: 722 Date d'inscription: 19/12/07 Publications récentes
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 ?
thumbnail
Vernon Singleton, modifié il y a 11 années.

RE: View based on Role - Primefaces

Expert Publications: 315 Date d'inscription: 14/01/13 Publications récentes
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:

<navigation-rule>
   <from-view-id>/views/startPage.xhtml</from-view-id>
   <navigation-case>
      <from-outcome>view1</from-outcome>
      <to-view-id>/views/view1.xhtml</to-view-id>
      <redirect />
   </navigation-case>
   <navigation-case>
      <from-outcome>view2</from-outcome>
      <to-view-id>/views/view2.xhtml</to-view-id>
      <redirect />
   </navigation-case>
</navigation-rule>
thumbnail
Vernon Singleton, modifié il y a 11 années.

RE: View based on Role - Primefaces

Expert Publications: 315 Date d'inscription: 14/01/13 Publications récentes
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.
thumbnail
Gnaniyar Zubair, modifié il y a 11 années.

RE: View based on Role - Primefaces

Liferay Master Publications: 722 Date d'inscription: 19/12/07 Publications récentes
It works fine. Thanks Vernon.
thumbnail
Vernon Singleton, modifié il y a 11 années.

RE: View based on Role - Primefaces

Expert Publications: 315 Date d'inscription: 14/01/13 Publications récentes
Glad to hear it is working for you.

Enjoy using Liferay.