将带有 Ajax4jsf 1.x 的 JSF 1.1 迁移到 JSF 2 [英] Migrating JSF 1.1 with Ajax4jsf 1.x to JSF 2

查看:20
本文介绍了将带有 Ajax4jsf 1.x 的 JSF 1.1 迁移到 JSF 2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在将 JSF 1.1 (MyFaces) 项目迁移到 JSF 2.这个想法是通过将 JSP 和 XHTML 保持在一起一段时间来定期迁移.我们在 JSP 页面中使用了很多 ajax4jsf-1.1.1 标签.我们不使用 RichFaces.将系统配置为 JSF 2 后(在 Balusc 的教程中提到了所有配置更改)当尝试使用类路径中的 ajax4jsf.jar 访问 JSP 页面时,我们得到一个异常:

We are migrating JSF 1.1 (MyFaces) project to JSF 2. The idea is to migrate periodically by keeping both JSP and XHTML together for some time. We use many ajax4jsf-1.1.1 tags in JSP pages. We don't use RichFaces. After configuring the system to JSF 2 (with all config changes mentioned in tutorial by Balusc) When tried to access the JSP page with ajax4jsf.jar in classpath, we get an exception:

Caused by: java.lang.IllegalStateException: setViewHandler may not be executed after a lifecycle request has been completed
    at org.apache.myfaces.application.ApplicationImpl.setViewHandler(ApplicationImpl.java:853)
    at org.ajax4jsf.framework.ajax.InitPhaseListener.beforePhase(InitPhaseListener.java:92)
    at org.apache.myfaces.lifecycle.PhaseListenerManager.informPhaseListenersBefore(PhaseListenerManager.java:76)
    at org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:131)

看起来 ajax4jsf.jar 与 JSF 2 不兼容.生命周期配置看起来有些问题.

It looks ajax4jsf.jar is not compatible with JSF 2. Looks some issue with LifeCycle configuration.

有什么方法可以让 a4j 与 JSF 2 JSP 一起工作?我知道当我们使用 XHTML 时,我们不需要所有这些.

Is there any way we can make a4j work with JSF 2 JSPs? I know when we use XHTML we don't need all this.

推荐答案

彻底摆脱 Ajax4jsf 1.x.它确实与 JSF2 不兼容.相反,JSF2 提供了一个新的主要 ajax 标记 <f:ajax>,它涵盖了以前由 Ajax4jsf 1.x 提供的所有核心功能.

Get rid of Ajax4jsf 1.x altogether. It's indeed not compatible with JSF2. Instead, JSF2 offers a new main ajax tag <f:ajax> which covers all the core functionality as previously offered by Ajax4jsf 1.x.

如果升级到 RichFaces 4 不是一个选项(因为,正如你自己所说,你没有在任何地方使用 RichFaces 组件),那么只需删除 Ajax4jsf 1.x 并替换所有 由标准 JSF2 等效项标记.

If upgrading to RichFaces 4 is not an option (because, as you said yourself, you aren't using RichFaces components anywhere), then just remove Ajax4jsf 1.x and replace all <a4j:xxx> tags by standard JSF2 equivalents.

  • :使用.
  • :只需将托管 bean 通过 @ViewScoped 放入视图范围.
  • :在 JS 上下文中使用 jsf.ajax.addOnEvent()jsf.ajax.addOnError().
  • :将 嵌套在 中.
  • :使用并记住在中包含它的ID代码> 或 PrimeFaces .
  • :只使用标准的.
  • :只要使用,它就会自动识别.
  • :将 嵌套在 中.
  • :没有替代品.考虑 OmniFaces PrimeFaces .
  • :只要使用,甚至可以包裹> 围绕一组组件.
  • :只使用标准的.
  • :在 JS 上下文中使用 jsf.ajax.addOnEvent()jsf.ajax.addOnError().
  • :只使用标准的.
  • :只使用标准的.
  • :没有替代品.考虑 PrimeFaces .
  • :没有替代品.考虑 OmniFaces PrimeFaces .
  • :将 嵌套在 中.
  • :只使用标准的.
  • :只使用标准的.
  • :只使用标准的.
  • <a4j:ajaxListener>: use <f:ajax listener>.
  • <a4j:keepAlive>: just put managed bean in the view scope by @ViewScoped.
  • <a4j:log>: use jsf.ajax.addOnEvent() or jsf.ajax.addOnError() in JS context.
  • <a4j:commandLink>: just nest <f:ajax> inside <h:commandLink>.
  • <a4j:outputPanel>: use <h:panelGroup> and remember to include its ID in <f:ajax render> or PrimeFaces <p:outputPanel>.
  • <a4j:repeat>: just use standard <ui:repeat>.
  • <a4j:form>: just use <h:form>, it will autorecognize <f:ajax>.
  • <a4j:htmlCommandLink>: just nest <f:ajax> inside <h:commandLink>.
  • <a4j:jsFunction>: no replacement. Consider OmniFaces <o:commandScript> or PrimeFaces <p:remoteCommand>.
  • <a4j:region>: just use <f:ajax execute>, you can even wrap <f:ajax> around a group of components.
  • <a4j:loadBundle>: just use standard <f:loadBundle>.
  • <a4j:status>: use jsf.ajax.addOnEvent() or jsf.ajax.addOnError() in JS context.
  • <a4j:actionparam>: just use standard <f:param>.
  • <a4j:loadScript>: just use standard <h:outputScript>.
  • <a4j:mediaOutput>: no replacement. Consider PrimeFaces <p:media>.
  • <a4j:poll>: no replacement. Consider OmniFaces <o:commandScript> or PrimeFaces <p:poll>.
  • <a4j:commandButton>: just nest <f:ajax> inside <h:commandButton>.
  • <a4j:include>: just use standard <ui:include>.
  • <a4j:loadStyle>: just use standard <h:outputStylesheet>.
  • <a4j:support>: just use standard <f:ajax>.

您还需要将 JSP 文件重命名/重写为 Facelets 文件.在简单的情况下,这通常只是更改根声明和文件扩展名的问题.Facelets 使用单个模板替换所有重复代码变得更加容易.以下答案适用:

You also need to rename/rewrite JSP files to Facelets files. In simple cases, this is usually just a matter of changing root declarations and file extensions. Facelets makes it easier to replace all duplicated code by a single template. The following answer applies:

这篇关于将带有 Ajax4jsf 1.x 的 JSF 1.1 迁移到 JSF 2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆