JSF 2 equivalent of IBM hx: scriptCollector postRender

I am moving the old JSF application from WebSphere to JBoss: the old version uses the JSF implementation for IBM. My question relates to the following component:

<hx:scriptCollector id="aScriptCollector" preRender="#{aBean.onPageLoadBegin}" postRender="#{aBean.onPageLoadEnd}"> 

To reproduce the preRender behavior in JSF 2, I use form binding (s. Here ). My questions:

1) Do you know the trick for simulating postRender in JSF 2?

2) What do you think the trick I use for preRender is "clean"?

Many thanks for your help! Bye

+4
source share
1 answer

The closest thing you can achieve to achieve exactly the same hooks

 <f:view beforePhase="#{bean.beforePhase}" afterPhase="#{bean.afterPhase}"> 

with

 public void beforePhase(PhaseEvent event) { if (event.getPhaseId == PhaseId. RENDER_RESPONSE) { // ... } } public void afterPhase(PhaseEvent event) { if (event.getPhaseId == PhaseId. RENDER_RESPONSE) { // ... } } 

preRender can be made simpler, place it anywhere:

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

with

 public void preRenderView(ComponentSystemEvent event) { // ... } 

(the argument is optional, it can be omitted if it is not used)


There is no such thing as postRenderView , but you can easily create custom events. For instance.

 @NamedEvent(shortName="postRenderView") public class PostRenderViewEvent extends ComponentSystemEvent { public PostRenderViewEvent(UIComponent component) { super(component); } } 

and

 public class PostRenderViewListener implements PhaseListener { @Override public PhaseId getPhaseId() { return PhaseId.RENDER_RESPONSE; } @Override public void beforePhase(PhaseEvent event) { // NOOP. } @Override public void afterPhase(PhaseEvent event) { FacesContext context = FacesContext.getCurrentInstance(); context.getApplication().publishEvent(context, PostRenderViewEvent.class, context.getViewRoot()); } } 

which you register in faces-config.xml as

 <lifecycle> <phase-listener>com.example.PostRenderViewListener</phase-listener> </lifecycle> 

then you can finally use

 <f:event type="postRenderView" listener="#{bean.postRenderView}" /> 

with

 public void postRenderView(ComponentSystemEvent event) { // ... } 
+7
source

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


All Articles