- cdi
- components
- contexts
- converters
- el
- eventlisteners
- exceptionhandlers
- facesviews
- filters
- functions
- managedbeans
- push
- resourcehandlers
- search
- servlets
- taghandlers
- utils
- validators
- viewhandlers
- - FacesRequestLogger
- InvokeActionEventListener
- ResetInputAjaxActionListener
- cdi
- components
- contexts
- converters
- el
- eventlisteners
- exceptionhandlers
- facesviews
- filters
- functions
- managedbeans
- push
- resourcehandlers
- search
- servlets
- taghandlers
- utils
- validators
- viewhandlers
- FacesRequestLogger
- InvokeActionEventListener
- ResetInputAjaxActionListener
The InvokeActionEventListener
will add support for new <f:event>
types preInvokeAction
and postInvokeAction
. Those events are published during the beforephase and afterphase of INVOKE_APPLICATION
respectively. This actually offers a better hook on invoking actions after the <f:viewParam>
values been set than the preRenderView
event. In some circumstances the preRenderView
event might be too late. For example, when you need to set a faces message in the flash scope and send a redirect. Also, it won't be invoked when the validations phase has failed for one of the <f:viewParam>
values, in contrary to the preRenderView
event.
Note that the upcoming JSF 2.2 will come with a <f:viewAction>
tag which should actually solve the concrete functional requirement for which a <f:event type="preRenderView">
workaround is often been used in JSF 2.0 and 2.1.
This event is supported on any UIComponent
, including UIViewRoot
, UIForm
, UIInput
and UICommand
components. This thus also provides the possibility to invoke multiple action listeners on a single UIInput
and UICommand
component on an easy manner.
As this phase listener has totally no impact on a webapp's default behavior, this phase listener is already registered by OmniFaces own faces-config.xml
and thus gets auto-initialized when the OmniFaces JAR is bundled in a webapp, so endusers do not need to register this phase listener explicitly themselves.
Replacement for preRenderView
event
Clicking this link with a "test" request parameter
should force a redirect with a faces message in the flash scope which should appear below. This wouldn't
have worked when preRenderView
event is been used.
Message:
Invoking multiple action listeners in UIInput
and UICommand
components
Typing in the input field and clicking the submit button of the below demo form should invoke several action listeners which should each set a global faces message.
<f:metadata>
<f:viewParam name="param" value="#{invokeActionBean.param}" />
<f:event type="postInvokeAction" listener="#{invokeActionBean.initParam}" />
</f:metadata>
<h3>Replacement for <code>preRenderView</code> event</h3>
<p>
Clicking <h:link value="this link" outcome="#{view.viewId}?param=test" /> with a "test" request parameter
should force a redirect with a faces message in the flash scope which should appear below. This wouldn't
have worked when <code>preRenderView</code> event is been used.
</p>
<p>
Message: <h:message for="param" />
</p>
<hr />
<h3>Invoking multiple action listeners in <code>UIInput</code> and <code>UICommand</code> components</h3>
<p>
Typing in the input field and clicking the submit button of the below demo form should invoke several
action listeners which should each set a global faces message.
</p>
<h:form>
<h:inputText value="#{invokeActionBean.input}">
<f:ajax event="keyup" execute="@this" listener="#{invokeActionBean.inputListener()}" render=":messages" />
<f:event type="preInvokeAction" listener="#{invokeActionBean.preInvokeAction}" />
<f:event type="postInvokeAction" listener="#{invokeActionBean.postInvokeAction}" />
</h:inputText>
<h:commandButton value="submit" action="#{invokeActionBean.submit}">
<f:ajax execute="@form" render=":messages" />
<f:event type="preInvokeAction" listener="#{invokeActionBean.preInvokeAction}" />
<f:event type="postInvokeAction" listener="#{invokeActionBean.postInvokeAction}" />
</h:commandButton>
</h:form>
<h:messages id="messages" globalOnly="true" />
package org.omnifaces.showcase.eventlisteners;
import static org.omnifaces.util.Utils.isEmpty;
import java.io.IOException;
import java.io.Serializable;
import javax.faces.event.ComponentSystemEvent;
import javax.inject.Named;
import org.omnifaces.cdi.ViewScoped;
import org.omnifaces.util.Faces;
import org.omnifaces.util.Messages;
@Named
@ViewScoped
public class InvokeActionBean implements Serializable {
private static final long serialVersionUID = 1L;
private String param;
private String input;
public void initParam() throws IOException {
if (!isEmpty(param)) {
System.out.println("InvokeActionBean.initParam() " + Faces.getCurrentPhaseId());
Messages.addFlashInfo("param", "Param \"{0}\" is successfully set and you have been redirected!", param);
Faces.refresh();
}
}
public void inputListener() {
Messages.addGlobalInfo("Input entered so far: {0}", input);
}
public void submit() {
Messages.addGlobalInfo("Form submitted with input: {0}", input);
}
public void preInvokeAction(ComponentSystemEvent event) {
Messages.addGlobalInfo("preInvokeAction event executed on component: {0}", event.getComponent());
}
public void postInvokeAction(ComponentSystemEvent event) {
Messages.addGlobalInfo("postInvokeAction event executed on component: {0}", event.getComponent());
}
public String getParam() {
return param;
}
public void setParam(String param) {
this.param = param;
}
public String getInput() {
return input;
}
public void setInput(String input) {
this.input = input;
}
}