use of jakarta.faces.event.ActionEvent in project myfaces by apache.
the class UIViewAction method broadcast.
@Override
public void broadcast(FacesEvent event) throws AbortProcessingException {
super.broadcast(event);
FacesContext context = getFacesContext();
if (context.getResponseComplete()) {
return;
}
UIComponent c = event.getComponent();
UIViewRoot sourceViewRoot = null;
do {
if (c instanceof UIViewRoot) {
sourceViewRoot = (UIViewRoot) c;
break;
} else {
c = c.getParent();
}
} while (c != null);
if (!context.getViewRoot().equals(sourceViewRoot)) {
return;
}
if (event instanceof ActionEvent) {
ActionListener defaultActionListener = context.getApplication().getActionListener();
if (defaultActionListener != null) {
String viewIdBeforeAction = context.getViewRoot().getViewId();
Boolean oldBroadcastProcessing = (Boolean) context.getAttributes().get(BROADCAST_PROCESSING_KEY);
try {
context.getAttributes().put(BROADCAST_PROCESSING_KEY, Boolean.TRUE);
ViewActionFacesContextWrapper wrappedFacesContext = new ViewActionFacesContextWrapper(context);
try {
wrappedFacesContext.setWrapperAsCurrentFacesContext();
if (event instanceof ViewActionEvent) {
((ViewActionEvent) event).setFacesContext(wrappedFacesContext);
}
defaultActionListener.processAction((ActionEvent) event);
// Decrement count
Integer count = (Integer) context.getAttributes().get(EVENT_COUNT_KEY);
count = (count == null) ? 0 : count - 1;
context.getAttributes().put(EVENT_COUNT_KEY, count);
} finally {
wrappedFacesContext.restoreCurrentFacesContext();
}
} finally {
context.getAttributes().put(BROADCAST_PROCESSING_KEY, oldBroadcastProcessing == null ? Boolean.FALSE : oldBroadcastProcessing);
}
if (context.getResponseComplete()) {
return;
} else {
Integer count = (Integer) context.getAttributes().get(EVENT_COUNT_KEY);
count = (count == null) ? 0 : count;
String viewIdAfterAction = context.getViewRoot().getViewId();
if (viewIdBeforeAction.equals(viewIdAfterAction) && count == 0) {
context.renderResponse();
}
// "... Otherwise, execute the lifecycle on the new UIViewRoot ..."
// Note these words are implemented in the NavigationHandler, but
// the original proposal from seam s:viewAction did a trick here
// to restart the JSF lifecycle.
}
}
}
}
use of jakarta.faces.event.ActionEvent in project myfaces by apache.
the class UIViewAction method decode.
@Override
public void decode(FacesContext context) {
super.decode(context);
if (context.isPostback() && !isOnPostback()) {
return;
}
if (!isRendered()) {
return;
}
ActionEvent evt = new ViewActionEvent(this);
String phase = getPhase();
PhaseId phaseId = phase != null ? PhaseId.phaseIdValueOf(phase) : isImmediate() ? PhaseId.APPLY_REQUEST_VALUES : PhaseId.INVOKE_APPLICATION;
evt.setPhaseId(phaseId);
this.queueEvent(evt);
// "... Keep track of the number of events that are queued in this way
// on this run through the lifecycle. ...". The are two options:
// 1. Use an attribute over FacesContext attribute map
// 2. Use an attribute over the component
// If the view is recreated again with the same viewId, the component
// state get lost, so the option 1 is preferred.
Integer count = (Integer) context.getAttributes().get(EVENT_COUNT_KEY);
count = (count == null) ? 1 : count + 1;
context.getAttributes().put(EVENT_COUNT_KEY, count);
}
use of jakarta.faces.event.ActionEvent in project myfaces by apache.
the class UICommand method broadcast.
@Override
public void broadcast(FacesEvent event) throws AbortProcessingException {
super.broadcast(event);
if (event instanceof ActionEvent) {
FacesContext context = getFacesContext();
ActionListener defaultActionListener = context.getApplication().getActionListener();
if (defaultActionListener != null) {
defaultActionListener.processAction((ActionEvent) event);
}
}
}
use of jakarta.faces.event.ActionEvent in project myfaces by apache.
the class HtmlLinkRendererBase method decode.
@Override
public void decode(FacesContext facesContext, UIComponent component) {
// check for NP
super.decode(facesContext, component);
if (component instanceof UICommand) {
String clientId = component.getClientId(facesContext);
UIForm form = ComponentUtils.findClosest(UIForm.class, component);
boolean disabled = HtmlRendererUtils.isDisabled(component);
// MYFACES-3960 Decode, decode client behavior and queue action event at the end
boolean activateActionEvent = false;
if (form != null && !disabled) {
String reqValue = (String) facesContext.getExternalContext().getRequestParameterMap().get(HtmlRendererUtils.getHiddenCommandLinkFieldName(form, facesContext));
activateActionEvent = reqValue != null && reqValue.equals(clientId) || HtmlRendererUtils.isPartialOrBehaviorSubmit(facesContext, clientId);
}
if (component instanceof ClientBehaviorHolder && !disabled) {
ClientBehaviorRendererUtils.decodeClientBehaviors(facesContext, component);
}
if (activateActionEvent) {
component.queueEvent(new ActionEvent(component));
}
} else if (component instanceof UIOutput) {
// do nothing
if (component instanceof ClientBehaviorHolder && !HtmlRendererUtils.isDisabled(component)) {
ClientBehaviorRendererUtils.decodeClientBehaviors(facesContext, component);
}
} else {
throw new IllegalArgumentException("Unsupported component class " + component.getClass().getName());
}
}
use of jakarta.faces.event.ActionEvent in project myfaces by apache.
the class HtmlButtonRendererBase method decode.
@Override
public void decode(FacesContext facesContext, UIComponent uiComponent) {
RendererUtils.checkParamValidity(facesContext, uiComponent, UICommand.class);
// super.decode must not be called, because value is handled here
boolean disabled = isDisabled(facesContext, uiComponent);
// MYFACES-3960 Decode, decode client behavior and queue action event at the end
boolean activateActionEvent = !isReset(uiComponent) && isSubmitted(facesContext, uiComponent) && !disabled;
if (uiComponent instanceof ClientBehaviorHolder && !disabled) {
ClientBehaviorRendererUtils.decodeClientBehaviors(facesContext, uiComponent);
}
if (activateActionEvent) {
uiComponent.queueEvent(new ActionEvent(uiComponent));
}
}
Aggregations