将带有Ajax4jsf 1.x的JSF 1.1迁移到JSF 2 [英] Migrating JSF 1.1 with Ajax4jsf 1.x to JSF 2
问题描述
我们正在将JSF 1.1(MyFaces)项目迁移到JSF2.其想法是通过将JSP和XHTML放在一起一段时间来定期迁移.我们在JSP页面中使用了许多ajax4jsf-1.1.1标记.我们不使用RichFaces.在将系统配置为JSF 2(具有Balusc教程中提到的所有配置更改)之后,当尝试使用classpath中的ajax4jsf.jar访问JSP页面时,会出现异常:
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不兼容.看上去与LifeCycle配置有关.
有什么方法可以使a4j与JSF 2 JSP一起使用?我知道当我们使用XHTML时,我们并不需要所有这些.
完全摆脱Ajax4jsf1.x.它确实与JSF2不兼容.相反,JSF2提供了一个新的主要ajax标记<f:ajax>
,该标记涵盖了以前由Ajax4jsf 1.x提供的所有核心功能.
如果不是升级到RichFaces 4的选择(因为正如您自己说的那样,您在任何地方都没有使用RichFaces组件),那么只需删除Ajax4jsf 1.x并将所有<a4j:xxx>
标记替换为标准的JSF2等效项. /p>
-
<a4j:ajaxListener>
:使用<f:ajax listener>
. -
<a4j:keepAlive>
:只需按@ViewScoped
将托管bean放入视图范围. -
<a4j:log>
:在JS上下文中使用jsf.ajax.addOnEvent()
或jsf.ajax.addOnError()
. -
<a4j:commandLink>
:只是将<f:ajax>
嵌套在<h:commandLink>
内. -
<a4j:outputPanel>
:使用<h:panelGroup>
,并记住将其ID包含在<f:ajax render>
或 OmniFaces<o:commandScript>
或 PrimeFaces<p:media>
. -
<a4j:poll>
:无替代品.考虑 OmniFaces<o:commandScript>
或从JSF 1.2迁移到JSF 2.0
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)
It looks ajax4jsf.jar is not compatible with JSF 2. Looks some issue with LifeCycle configuration.
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.
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.
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.
<a4j:ajaxListener>
: use<f:ajax listener>
.<a4j:keepAlive>
: just put managed bean in the view scope by@ViewScoped
.<a4j:log>
: usejsf.ajax.addOnEvent()
orjsf.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>
: usejsf.ajax.addOnEvent()
orjsf.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>
.
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屋!