public interface ThymeleafReplaceInterceptor
Component
annotation might be useful. @Component public class CustomInterceptor extends ThymeleafReplaceInterceptorBase { public boolean intercept(ITemplateContext context, IProcessableElementTag tag, AttributeName attributeName, String attributeValue, IElementTagStructureHandler structureHandler, ThymeleafStandardReplaceTagProcessorCaller tagProcessor) { if (attributeValue.contains("::datacell")) { // we want to replace each call of datacell with our own fragment attributeValue = attributeValue.replace("::datacell", "customtemplate.html::datacell_custom"); // proceed processing with our customized attribute value tagProcessor.callStandardDoProcess(context, tag, attributeName, attributeValue, structureHandler); // tell the replace tag processor that this intereptor already triggered the // processing return true; } // tell the replace tag processor that this interceptor did not intercept return false; } // add all needed template file names for this interceptor public CollectiongetAdditionalTemplateResourceNames() { Set resources = Sets.newHashSet(); resources.add("personregister.html"); return resources; } }
Modifier and Type | Method and Description |
---|---|
Collection<String> |
getAdditionalTemplateResourceNames()
With this method the interceptor can define additional template files which
should be added to the template engine that custom fragments are available
during processing
|
default int |
getPriority()
In case that an application has different interceptors intercepting on the
same replace call, the first interceptor will win.
|
boolean |
intercept(org.thymeleaf.context.ITemplateContext context,
org.thymeleaf.model.IProcessableElementTag tag,
org.thymeleaf.engine.AttributeName attributeName,
String attributeValue,
org.thymeleaf.processor.element.IElementTagStructureHandler structureHandler,
ThymeleafStandardReplaceTagProcessorCaller tagProcessor)
This method is called from the
ReplaceTagProcessor before executing
the ordinary replace logic as implemented by the
StandardReplaceTagProcessor . |
boolean intercept(org.thymeleaf.context.ITemplateContext context, org.thymeleaf.model.IProcessableElementTag tag, org.thymeleaf.engine.AttributeName attributeName, String attributeValue, org.thymeleaf.processor.element.IElementTagStructureHandler structureHandler, ThymeleafStandardReplaceTagProcessorCaller tagProcessor)
ReplaceTagProcessor
before executing
the ordinary replace logic as implemented by the
StandardReplaceTagProcessor
. With this method the interceptor can
decide to overwrite the attribute value of the replace tag to call another
target fragment instead.
Probably the interceptor also has to add additional variables to the context
if the other target fragment has parameters which does not exist in the given
context
If the interceptor wants to intercept, it has to modify the attributeValue
and call the doProcess method of the given tagProcessor. It has to return
true to indicate that processing was done within this interception to avoid
another processing by the ReplaceTagProcessor
context
- tag
- attributeName
- attributeValue
- structureHandler
- tagProcessor
- Collection<String> getAdditionalTemplateResourceNames()
default int getPriority()
Copyright © 2011–2019 aiticon GmbH. All rights reserved.