B4J Question Another Java web framework

aeric

Expert
Licensed User
Longtime User
I tried to search for HTML builder library and found j2html. It claimed that it is 1000x faster than Velocity.
That's about a thousand times faster than Apache 'Velocity'

It's github page is created by Javalin. This web framework also look interesting. It is a lightweight framework that works with Jetty, websocket and Vue frontend.

I don't think I have extra time to explore these projects. See if anyone is interested to wrap them or explore further.
 

teddybear

Well-Known Member
Licensed User
I tried to search for HTML builder library and found j2html. It claimed that it is 1000x faster than Velocity.
They are different things, there is no comparison between the two, Velocity is a Java-based template engine, while j2html just is a HTML builder.
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
They are different things, there is no comparison between the two, Velocity is a Java-based template engine, while j2html just is a HTML builder.
Yes!
Different approach to build web frontend.
It is like HTMX is different from using the popular Web framework. Depend on individual preference. Maybe some people scared seeing html tags.
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
With j2html, one will write like this:
B4X:
body(
    h1("Hello, World!"),
    img().withSrc("/img/hello.png")
).render()

and it will produce:
HTML:
<body>
    <h1>Hello, World!</h1>
    <img src="/img/hello.png">
</body>
 
Upvote 0

MicroDrie

Well-Known Member
Licensed User
Longtime User
I don't think I have extra time to explore these projects. See if anyone is interested to wrap them or explore further.
Well, it has a hugely extensive command set and a single example. But which solution should I consider? Now I have gotten some things working, but... Because if you look at an HTML header, for example, it is different for every web page. A wrapper I made with my header solution that I needed may not be interesting at all for someone else.
 
Upvote 0

Sandman

Expert
Licensed User
Longtime User
With j2html, one will write like this:
B4X:
body(
h1("Hello, World!"),
img().withSrc("/img/hello.png")
).render()
For what it's worth, that example (including more html tags) seems simple to make as a native B4X solution. (I haven't looked at what other things j2html can do.)
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
may not be interesting at all for someone else.
I can imagine that a set of preset templates will be useful as reusable components. It will work like code snippets that save someone time to create them every time.
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
With j2html, one will write like this:
B4X:
body(
    h1("Hello, World!"),
    img().withSrc("/img/hello.png")
).render()

and it will produce:
HTML:
<body>
    <h1>Hello, World!</h1>
    <img src="/img/hello.png">
</body>

I will try to make my own library without relying on the j2html.
Currently it looks like this:

B4X:
Dim html As MiniHtml
html.Initialize

html.Tag1("body")
html.TabsIncrease
html.Tag("h1", Array(CreateMap("text": "Hello, World!")))
html.Tag2("img", Array(CreateMap("src": "/img/hello.png")))
html.Tagx("body")

Dim content As String = html.ToString
File.WriteString(File.DirApp, "hello.vm", content)

In future I will try make a version that allow tag to add children, auto close and auto indent.
 
Upvote 0

Magma

Expert
Licensed User
Longtime User
With j2html, one will write like this:
B4X:
body(
    h1("Hello, World!"),
    img().withSrc("/img/hello.png")
).render()

and it will produce:
HTML:
<body>
    <h1>Hello, World!</h1>
    <img src="/img/hello.png">
</body>
...Explain me why not use html direct... then... ?
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
I will try to make my own library without relying on the j2html.
Currently it looks like this:

B4X:
Dim html As MiniHtml
html.Initialize

html.Tag1("body")
html.TabsIncrease
html.Tag("h1", Array(CreateMap("text": "Hello, World!")))
html.Tag2("img", Array(CreateMap("src": "/img/hello.png")))
html.Tagx("body")

Dim content As String = html.ToString
File.WriteString(File.DirApp, "hello.vm", content)

In future I will try make a version that allow tag to add children, auto close and auto indent.

Update to MiniHTML

B4X:
html.Body
html.H1("Hello, World!")
html.Img("/img/hello.png")
html.Bodyx
 
Upvote 0
Top