Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rendering with data #83

Closed
kicktipp opened this issue Nov 23, 2017 · 4 comments
Closed

Rendering with data #83

kicktipp opened this issue Nov 23, 2017 · 4 comments

Comments

@kicktipp
Copy link
Contributor

kicktipp commented Nov 23, 2017

j2html is great, easy and fast. But I think it could be even faster and consume less memory with the following approach. Maybe it is not a good idea so I am asking for feedback here first.

Take a look at this code:

String headline = "My Headline";
String imgSrc = "img/hello.png";
body().with(
    h1(headline).withClass("example"),
    img().withSrc(imgSrc)
).render(); 

This template generates the DomContent each and every time I render this page. This involves - with a bigger template - a lot of new ContainerTag statements (which are hidden by static imports).

It would be nice to build a DomContent Tree with some self written ContainerTags first and then let it render with a model.

Therefor we need a second render method render(Object model). The model is passed down the line and each Tag or Attribute can pick up its model if needed for rendering. Object would usually be a map like in Spring MVC.

This way I can reuse the DomContent for each and every page. I don't need to build it and I don't need the GC to collect it.

This would be fairly easy when we add two methods to DomContent (and one method to Attribute)

public abstract String render(Object model) ;
public void render(Appendable writer, Object model);

If you think this is a good idea I can send a patch request.

@kicktipp
Copy link
Contributor Author

@tipsy
Copy link
Owner

tipsy commented Nov 23, 2017

I'm (pleasantly) surprised that you need this kind of performance. If you can provide a backwards compatible implementation with some test/examples to show the increased performance, I would be happy to merge it.

@tipsy
Copy link
Owner

tipsy commented Nov 27, 2017

@kicktipp I'm planning to release a new version soon, do you want this included?

@kicktipp
Copy link
Contributor Author

kicktipp commented Nov 27, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants