根据用户类型呈现主页
问题描述:
我使用以下代码在登录时重定向到我的主页...现在我想更进一步,并根据用户类型添加逻辑,将其重定向到不同的页面。根据用户类型呈现主页
例如:如果用户类型是员工,那么我应该重定向到employeehome.xhtml等等......这可能吗?
<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">
<navigation from-action="#{identity.login}">
<rule if="#{identity.loggedIn}">
<redirect view-id="/Home.xhtml" />
</rule>
</navigation>
答
我假设你有一个login.xhtml页的这。
用户登录之后,你可以创建一个包含一些导航规则login.page.xml页面。例如:
<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>
接下来,您可以限制页面,因此只有具有正确角色的用户才能访问该页面。在我的pages.xml中,我有以下几行:
<page view-id="/secure/upload.xhtml" login-required="true">
<restrict>#{s:hasRole('upload')}</restrict>
</page>