Skip to content
Snippets Groups Projects
Commit 7095a4dc authored by Simon Urli's avatar Simon Urli
Browse files

XWIKI-17338: Handle getting cached async content with JSX with an AJAX request

  * Add a boolean in AsyncRendererConfiguration to allow forcing to send
    back a placeholder even if the data are available already
  * Use that boolean in the default existing renderer executors to
    return the placeholder if it's forced
  * Consider the execution as async if the placeholder is forced.
parent 96f3a696
No related branches found
No related tags found
No related merge requests found
......@@ -40,6 +40,8 @@ public class AsyncRendererConfiguration
protected boolean secureSet;
protected boolean placeHolderForced;
/**
* @return the list of context entries to take remember for the execution
*/
......@@ -90,4 +92,28 @@ public void setSecureReference(DocumentReference documentReference, DocumentRefe
this.secureAuthorReference = authorReference;
this.secureSet = true;
}
/**
* @return {@code true} if the renderer should display a placeholder even if the data is already available.
* @see #setPlaceHolderForced(boolean).
* @since 12.5RC1
*/
public boolean isPlaceHolderForced()
{
return placeHolderForced;
}
/**
* Set to {@code true} to force the renderer to return an async placeholder even if the data is available.
* This allows to use easily the Async rendering framework with AJAX requests: we can force the async renderers
* in an AJAX request to return always placeholders, so they are resolved once added in the current DOM by using
* Javascript.
*
* @param placeHolderForced {@code true} to force using a placeholder.
* @since 12.5RC1
*/
public void setPlaceHolderForced(boolean placeHolderForced)
{
this.placeHolderForced = placeHolderForced;
}
}
......@@ -127,7 +127,7 @@ public Block execute(BlockAsyncRenderer renderer, AsyncRendererConfiguration con
// Get result
BlockAsyncRendererResult result = (BlockAsyncRendererResult) response.getStatus().getResult();
if (result != null) {
if (result != null && !configuration.isPlaceHolderForced()) {
return result.getBlock();
}
......@@ -156,7 +156,7 @@ public String render(BlockAsyncRenderer renderer, AsyncRendererConfiguration con
// Get result
BlockAsyncRendererResult result = (BlockAsyncRendererResult) response.getStatus().getResult();
if (result != null) {
if (result != null && !configuration.isPlaceHolderForced()) {
return result.getResult();
}
......
......@@ -150,7 +150,9 @@ public AsyncRendererJobStatus getAsyncStatus(List<String> id, String clientId, l
public AsyncRendererExecutorResponse render(AsyncRenderer renderer, AsyncRendererConfiguration configuration)
throws JobException, RenderingException
{
boolean asyncAllowed = renderer.isAsyncAllowed() && this.asyncContext.isEnabled();
// if placeholder is forced, then we always consider it as async.
boolean asyncAllowed = configuration.isPlaceHolderForced()
|| (renderer.isAsyncAllowed() && this.asyncContext.isEnabled());
boolean cacheAllowed = renderer.isCacheAllowed();
// Get context and job id
......@@ -167,7 +169,7 @@ public AsyncRendererExecutorResponse render(AsyncRenderer renderer, AsyncRendere
if (status != null
&& (status.getEndDate() == null || this.cacheControl.isCacheReadAllowed(status.getEndDate()))) {
if (status.getResult() != null) {
if (status.getResult() != null && !configuration.isPlaceHolderForced()) {
// Available cached result, return it
injectUses(status);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment