java.lang.Object
jakarta.faces.context.PartialViewContext
jakarta.faces.context.PartialViewContextWrapper
org.omnifaces.context.OmniPartialViewContext
- All Implemented Interfaces:
FacesWrapper<PartialViewContext>
This OmniFaces partial view context extends and improves the standard partial view context as follows:
- Support for executing callback scripts by
PartialResponseWriter.startEval(). - Support for adding arguments to an ajax response.
- Any XML tags which Mojarra and MyFaces has left open after an exception in rendering of an already committed ajax response, will now be properly closed. This prevents errors about malformed XML.
- Fixes the no-feedback problem when a
ViewExpiredExceptionoccurs during an ajax request on a page which is restricted byweb.xml<security-constraint>. The enduser will now properly be redirected to the login page instead of retrieving an ajax response with only a changed view state (and effectively thus no visual feedback at all).
Ajax utility class to easily add callback scripts and arguments.
This partial view context is already registered by OmniFaces' own faces-config.xml and thus gets
auto-initialized when the OmniFaces JAR is bundled in a web application, so end-users do not need to register this
partial view context explicitly themselves.
- Since:
- 1.2
- Author:
- Bauke Scholtz
- See Also:
-
Field Summary
Fields inherited from class jakarta.faces.context.PartialViewContext
ALL_PARTIAL_PHASE_CLIENT_IDS, PARTIAL_EVENT_PARAM_NAME, PARTIAL_EXECUTE_PARAM_NAME, PARTIAL_RENDER_PARAM_NAME, RESET_VALUES_PARAM_NAME -
Constructor Summary
ConstructorsConstructorDescriptionOmniPartialViewContext(PartialViewContext wrapped) Construct a new OmniFaces partial view context around the given wrapped partial view context. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddArgument(String name, Object value) Add an argument to the partial response.voidaddCallbackScript(String callbackScript) Add a callback script to the partial response.voidClose the partial response.static OmniPartialViewContextReturns the current instance of the OmniFaces partial view context.static OmniPartialViewContextgetCurrentInstance(FacesContext context) Returns the current instance of the OmniFaces partial view context from the given faces context.voidprocessPartial(PhaseId phaseId) An override which checks if the web.xml security constraint has been triggered during this ajax request (which can happen when the session has been timed out) and if so, then perform a redirect to the originally requested page.voidReset the partial response.Methods inherited from class jakarta.faces.context.PartialViewContextWrapper
getEvalScripts, getExecuteIds, getRenderIds, getWrapped, isAjaxRequest, isExecuteAll, isPartialRequest, isRenderAll, isResetValues, release, setPartialRequest, setRenderAll
-
Constructor Details
-
OmniPartialViewContext
Construct a new OmniFaces partial view context around the given wrapped partial view context.- Parameters:
wrapped- The wrapped partial view context.
-
-
Method Details
-
getPartialResponseWriter
- Overrides:
getPartialResponseWriterin classPartialViewContextWrapper
-
processPartial
An override which checks if the web.xml security constraint has been triggered during this ajax request (which can happen when the session has been timed out) and if so, then perform a redirect to the originally requested page. Otherwise the enduser ends up with an ajax response containing only the new view state without any form of visual feedback.- Overrides:
processPartialin classPartialViewContextWrapper
-
addArgument
Add an argument to the partial response. This is as JSON object available byOmniFaces.Ajax.data. For supported argument value types, readJson.encode(Object). If a given argument type is not supported, then anIllegalArgumentExceptionwill be thrown during end of render response.- Parameters:
name- The argument name.value- The argument value.
-
addCallbackScript
Add a callback script to the partial response. This script will be executed once the partial response is successfully retrieved at the client side.- Parameters:
callbackScript- The callback script to be added to the partial response.
-
resetPartialResponse
public void resetPartialResponse()Reset the partial response. This clears any JavaScript arguments and callbacks set any data written to thePartialResponseWriter.- See Also:
-
closePartialResponse
public void closePartialResponse()Close the partial response. If the writer is still in update phase, then end the update and the document. This fixes the Mojarra problem of incomplete ajax responses caused by exceptions during ajax render response.- See Also:
-
getCurrentInstance
Returns the current instance of the OmniFaces partial view context.- Returns:
- The current instance of the OmniFaces partial view context.
- Throws:
IllegalStateException- When there is no current instance of the OmniFaces partial view context. That can happen when theOmniPartialViewContextFactoryis not properly registered, or when there's anotherPartialViewContextimplementation which doesn't properly delegate through the wrapped instance.
-
getCurrentInstance
Returns the current instance of the OmniFaces partial view context from the given faces context.- Parameters:
context- The faces context to obtain the current instance of the OmniFaces partial view context from.- Returns:
- The current instance of the OmniFaces partial view context from the given faces context.
- Throws:
IllegalStateException- When there is no current instance of the OmniFaces partial view context. That can happen when theOmniPartialViewContextFactoryis not properly registered, or when there's anotherPartialViewContextimplementation which doesn't properly delegate through the wrapped instance.
-