【问题标题】:Home page to be rendered according to user type根据用户类型呈现的主页
【发布时间】:2011-03-29 07:01:28
【问题描述】:

我使用以下代码在登录时重定向到我的主页...现在我想更进一步并添加一个逻辑,它根据用户类型重定向到不同的页面。

例如:如果用户类型是员工,那么我应该重定向到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>

【问题讨论】:

    标签: jsf seam richfaces


    【解决方案1】:

    我想你有一个用户登录的 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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-07-24
      • 1970-01-01
      • 1970-01-01
      • 2022-07-08
      • 2022-10-12
      • 1970-01-01
      • 2019-05-15
      • 2016-10-18
      相关资源
      最近更新 更多