Package org.omnifaces.context
Class OmniPartialViewContext
- java.lang.Object
-
- jakarta.faces.context.PartialViewContext
-
- jakarta.faces.context.PartialViewContextWrapper
-
- org.omnifaces.context.OmniPartialViewContext
-
- All Implemented Interfaces:
FacesWrapper<PartialViewContext>
public class OmniPartialViewContext extends PartialViewContextWrapper
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
ViewExpiredException
occurs 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:
OmniPartialViewContextFactory
,FullAjaxExceptionHandler
,WebXml
,Ajax
,Json
-
-
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
Constructors Constructor Description OmniPartialViewContext(PartialViewContext wrapped)
Construct a new OmniFaces partial view context around the given wrapped partial view context.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addArgument(String name, Object value)
Add an argument to the partial response.void
addCallbackScript(String callbackScript)
Add a callback script to the partial response.void
closePartialResponse()
Close the partial response.static OmniPartialViewContext
getCurrentInstance()
Returns the current instance of the OmniFaces partial view context.static OmniPartialViewContext
getCurrentInstance(FacesContext context)
Returns the current instance of the OmniFaces partial view context from the given faces context.PartialResponseWriter
getPartialResponseWriter()
void
processPartial(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.void
resetPartialResponse()
Reset the partial response.-
Methods inherited from class jakarta.faces.context.PartialViewContextWrapper
getEvalScripts, getExecuteIds, getRenderIds, getWrapped, isAjaxRequest, isExecuteAll, isPartialRequest, isRenderAll, isResetValues, release, setPartialRequest, setRenderAll
-
-
-
-
Constructor Detail
-
OmniPartialViewContext
public OmniPartialViewContext(PartialViewContext wrapped)
Construct a new OmniFaces partial view context around the given wrapped partial view context.- Parameters:
wrapped
- The wrapped partial view context.
-
-
Method Detail
-
getPartialResponseWriter
public PartialResponseWriter getPartialResponseWriter()
- Overrides:
getPartialResponseWriter
in classPartialViewContextWrapper
-
processPartial
public void processPartial(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. Otherwise the enduser ends up with an ajax response containing only the new view state without any form of visual feedback.- Overrides:
processPartial
in classPartialViewContextWrapper
-
addArgument
public void addArgument(String name, Object value)
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 anIllegalArgumentException
will be thrown during end of render response.- Parameters:
name
- The argument name.value
- The argument value.
-
addCallbackScript
public void addCallbackScript(String callbackScript)
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:
FullAjaxExceptionHandler
-
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:
FullAjaxExceptionHandler
-
getCurrentInstance
public static OmniPartialViewContext 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 theOmniPartialViewContextFactory
is not properly registered, or when there's anotherPartialViewContext
implementation which doesn't properly delegate through the wrapped instance.
-
getCurrentInstance
public static OmniPartialViewContext getCurrentInstance(FacesContext context)
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 theOmniPartialViewContextFactory
is not properly registered, or when there's anotherPartialViewContext
implementation which doesn't properly delegate through the wrapped instance.
-
-