此内容没有您所选择的语言版本。

7.2. Page actions


A Seam page action is an event occurring immediately before a JSF request is rendered. Declare page actions in WEB-INF/pages.xml. We can define a page action for a particular JSF view ID:
<pages> 
    <page view-id="/hello.jsp" action="#{helloWorld.sayHello}"/> 
    </pages>
Copy to Clipboard Toggle word wrap
Or we can use a * wildcard as a suffix to the view-id to specify an action that applies to all view IDs that match that pattern:
<pages> 
    <page view-id="/hello/*" action="#{helloWorld.sayHello}"/> 
    </pages>
Copy to Clipboard Toggle word wrap

Note

If the <page> element is defined in a fine-grained page descriptor, the view-id attribute can be omitted, as it is already implied.
If multiple wildcarded page actions match the current view-id, Seam will call all the actions, in order of least-specific to most-specific.
The page action method can return a JSF outcome. If the outcome is not null, Seam uses the defined navigation rules to navigate to a view.
The view ID mentioned in the <page> element need not correspond to a real JSP or Facelets page. This way, we can reproduce the functionality of a traditional action-oriented framework like Struts or WebWork using page actions. This is useful for performing complex actions in response to non-Faces requests like HTTP GET.
Multiple or conditional page actions can be specified with the <action> tag:
<pages> 
  <page view-id="/hello.jsp">
    <action execute="#{helloWorld.sayHello}" 
            if="#{not validation.failed}"/>
    <action execute="#{hitCount.increment}"/> 
  </page> 
</pages>
Copy to Clipboard Toggle word wrap
Page actions are executed on both an initial (non-Faces) request and a postback (Faces) request. If you use the page action to load data, it may conflict with the standard JSF actions being executed on a postback. One way to disable the page action is to set up a condition that resolves to true only upon an initial request.
<pages> 
  <page view-id="/dashboard.xhtml"> 
    <action execute="#{dashboard.loadData}" 
            if="#{not FacesContext.renderKit.responseStateManager
                .isPostback(FacesContext)}"/> 
  </page> 
</pages>
Copy to Clipboard Toggle word wrap
This condition consults the ResponseStateManager#isPostback(FacesContext) to determine if the request is a postback. The ResponseStateManager is accessed using FacesContext.getCurrentInstance().getRenderKit(). getResponseStateManager().
Seam offers a built-in condition that accomplishes this result less verbosely. You can disable a page action on a postback by setting the on-postback attribute to false:
<pages> 
    <page view-id="/dashboard.xhtml"> 
    <action execute="#{dashboard.loadData}" on-postback="false"/> 
    </page> 
    </pages>
Copy to Clipboard Toggle word wrap
The on-postback attribute defaults to true to maintain backwards compatibility. However, you are more likely to use false more often.
返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat