Migrating JSF 1.1 from Ajax4jsf 1.x to JSF 2

We are migrating the JSF 1.1 project (MyFaces) to JSF 2. The idea is to periodically migrate, supporting both JSP and XHTML for some time. We use a lot of ajax4jsf-1.1.1 tags in JSP pages. We do not use RichFaces. After setting up the system on JSF 2 (with all the configuration changes mentioned in the tutorial from Balusc) When you tried to access the JSP page using ajax4jsf.jar in the 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 seems that ajax4jsf.jar is not compatible with JSF 2. It causes some configuration problems with LifeCycle.

Is there a way to make a4j work with JSP 2 JSP? I know when we use XHTML, we don’t need it.

+6
source share
1 answer

Get rid of Ajax4jsf 1.x in general. It is really incompatible with JSF2. Instead, JSF2 offers a new core tag, ajax <f:ajax> , which covers all the basic functions, as previously proposed by Ajax4jsf 1.x.

If upgrading to RichFaces 4 is not an option (because, as you said yourself, you are not using RichFaces components anywhere), simply remove Ajax4jsf 1.x and replace the <a4j:xxx> tags with standard JSF2 equivalents.

  • <a4j:ajaxListener> : use <f:ajax listener> .
  • <a4j:keepAlive> : just enter the managed bean into the @ViewScoped .
  • <a4j:log> : use jsf.ajax.addOnEvent() or jsf.ajax.addOnError() in the JS context.
  • <a4j:commandLink> : only socket <f:ajax> inside <h:commandLink> .
  • <a4j:outputPanel> : use <h:panelGroup> and remember to include its identifier in <f:ajax render> or PrimeFaces <p:outputPanel> .
  • <a4j:repeat> : just use the standard <ui:repeat> .
  • <a4j:form> : just use <h:form> , it will autorecognize <f:ajax> .
  • <a4j:htmlCommandLink> : only socket <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 the standard <f:loadBundle> .
  • <a4j:status> : use jsf.ajax.addOnEvent() or jsf.ajax.addOnError() in the JS context.
  • <a4j:actionparam> : just use the standard <f:param> .
  • <a4j:loadScript> : just use the 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> : only socket <f:ajax> inside <h:commandButton> .
  • <a4j:include> : just use the standard <ui:include> .
  • <a4j:loadStyle> : just use the standard <h:outputStylesheet> .
  • <a4j:support> : just use the standard <f:ajax> .

You also need to rename / rewrite JSP files to Facelets files. In simple cases, this is usually associated with changing root declarations and file extensions. Facelets makes it easy to replace all duplicate code with one template. The following answer applies:

+13
source

Source: https://habr.com/ru/post/949032/


All Articles