views:

17

answers:

1

I use the following code to redirect to my home page on login... now i want to go a step further and add a logic where it redirects to different page based on user type.

for eg: if a user type is employee then i should redirect to employeehome.xhtml and so on ... is this possible ?

<page xmlns="http://jboss.com/products/seam/pages"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://jboss.com/products/seam/pages http://jboss.com/products/seam/pages-2.2.xsd"&gt;

<navigation from-action="#{identity.login}">
    <rule if="#{identity.loggedIn}">
        <redirect view-id="/Home.xhtml" />
    </rule>
</navigation>

+1  A: 

I suppose you have a login.xhtml page from which the user logs in.

Then you can create a login.page.xml page containing some navigation rules. For example:

     <navigation from-action='#{identity.login}'>
        <rule if="#{identity.loggedIn and s:hasRole('management')}">
            <redirect view-id="/management/home.xhtml"/>
        </rule>
        <rule if="#{identity.loggedIn and s:hasRole('upload')}">
            <redirect view-id="/secure/upload.xhtml"/>
        </rule>
        <rule if="#{identity.loggedIn and (s:hasRole('sss') or s:hasRole('sssmgmnt'))}">
            <redirect view-id="/secure/sss/home.xhtml"/>
        </rule>
        <rule if="#{identity.loggedIn}">
            <redirect view-id="/secure/home.xhtml"/>
        </rule>  
    </navigation>

next, you can restrict the pages, so only users with the right role can go there. In my pages.xml, I have the following lines:

<page view-id="/secure/upload.xhtml" login-required="true">
    <restrict>#{s:hasRole('upload')}</restrict>
</page>
Fortega