Comments (2)
Here's a working demo
Your error boils down to mixing APIs in an unsupported way.
If you have a look at the documentation for PostProcessors you will see that it states:
Pre-processors and post-processors are different to processors in that instead of executing on a single event or on an event model (a fragment of a template), they apply to the entire template execution process as an additional step in the engine’s processing chain. Therefore they follow an API completely different to that of processors, much more event-oriented, defined by the lower-level
ITemplateHandler
interface.
a) ITextProcessor
cannot be used in conjunction with IPostProcessorDialect
.
b) The method getHandlerClass()
defines the implementation of your PostProcessor
, so it fails in your case because of
return ITemplateHandler.class;
ITemplateHandler is an interface and does not have a constructor, thus the exception java.lang.NoSuchMethodException: org.thymeleaf.engine.ITemplateHandler.<init>()
How can it be fixed?
public class StripElementWhiteSpaceDialect implements IPostProcessorDialect {
Set<IPostProcessor> processors = new HashSet<>();
{
processors.add(new PostProcessor(TemplateMode.HTML, StripElementWhiteSpaceHandler.class, Integer.MAX_VALUE));
}
@Override
public int getDialectPostProcessorPrecedence() {
return 0;
}
@Override
public Set<IPostProcessor> getPostProcessors() {
return processors;
}
@Override
public String getName() {
return "Minifier";
}
public static class StripElementWhiteSpaceHandler extends AbstractTemplateHandler {
@Override
public void handleText(IText textNode) {
//update the text
super.handleText(...);
}
}
}
from thymeleaf.
@duoduobingbing thanks for the demo. But actually textNode.getText() is not the final complete processed output but rather chuncks. So doesnt fit what i was looking for. Thanks very much anyway.
from thymeleaf.
Related Issues (20)
- Switch context lost when using div inside th:case
- Using both Thymeleaf and JSP HOT 1
- Thymeleaf generated text in TEXT mode replaces CRLF with LF?
- Outputting a JS array outside th:inline script tag HOT 4
- Block to add attributes to included fragments HOT 1
- Do you support CSS3 styles? Like flexbox layout HOT 1
- How to prevent SSTI injection when using hypoleaf in inheriting DispatcherServlet?
- [BUG] using th:field does not work in th:each HOT 1
- GraalVM potential missing reachability metadata
- th:replace by POST response view HOT 1
- BUG: problem with passing Number and String data type to javascript function in thymeleaf looping th:each HOT 3
- Error "Cannot build an application for a request which servlet context does not match with the application that it is being built for." HOT 4
- Cannot use java.util.Currency in expressions
- Migration issue Thymeleaf 3.0.10RELEASE to 3.1.2RELEASE
- when using java 9 modules it doesn't find the template resolver
- Any solution for BDSA-2023-1804? HOT 3
- HTMX integration section in Thymeleaf documentation
- Request for posting of Maven signing key(s) HOT 1
- Replace Variables with issue as empty String HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from thymeleaf.