3

我学会了用 Java 和 Seam(和 JSF 1.2)构建一个 web 应用程序

但现在我正在使用纯 Java EE 6 和 JSF (Mojara 2.0.9) - 没有任何额外的框架。

在 Seam 中,我使用index.xhtmlindex.page.xmlfor 限制:

<restrict>#{authorizationManager.isAdmin()}</restrict>

有没有像 page.xml 一样的功能?

并且:
我还使用index.page.xml进行了一些调用,例如:

<action execute="#{indexController.doSomething()}" on-postback="false"/>

现在是唯一的机会@PostConstruct在.xhtml 的控制器中使用吗?

另外,我如何在没有 ? 的情况下做这样的事情page.xml

<navigation>
    <rule if-outcome="OK">
        <redirect view-id="/pages/index.xhtml" />
    </rule>
</navigation>

在我看来,纯 JavaEE 的工作方式完全不同?

(你不必给我完整的代码,只要给我关键词我必须谷歌,谢谢!)

4

1 回答 1

5

在 Seam 中,我使用 index.xhtml 来限制 index.page.xml:

<restrict>#{authorizationManager.isAdmin()}</restrict>

有没有像 page.xml 一样的功能?

标准 JSF 不提供任何内置的身份验证/授权工具。所有这些都可以从“原始”Servlet API 或 Spring Security 等第 3 方框架中使用。

至于“原始”的 Servlet API 设施,则<security-constraint>web.xml接近。您只能限制全局 URL 模式,例如/app/*,而不是基于每个页面或每个操作。


我还使用 index.page.xml 进行了一些调用,例如:

 <action execute="#{indexController.doSomething()}" on-postback="false"/>

现在是在.xhtml 的控制器中使用@PostConstruct 的唯一机会吗?

XHTML 页面本身中的<f:event>接近:

<f:event type="preRenderView" listener="#{indexController.doSomething}" />

至于on-postback替换,检查Is it possible to disable f:event type="preRenderView" listener on postback? .


还有我如何在没有page.xml的情况下做这样的事情?

<navigation>
    <rule if-outcome="OK">
        <redirect view-id="/pages/index.xhtml" />
    </rule>
</navigation>

在我看来,纯 JavaEE 的工作方式完全不同?

JSF 2.0 支持完全多余的隐式导航<navigation-rule>faces-config.xml返回的结果将被隐式视为目标视图 ID。faces-redirect=true您可以通过将参数附加到结果查询字符串来执行重定向。例如

public String submit() {
    // ...

    return "/pages/index.xhtml?faces-redirect=true";
}

也可以看看:

于 2012-03-01T19:57:41.083 回答