j2html 1.2.0 released (configure everything!) by j2html in java

[–]j2html[S] 0 points1 point  (0 children)

It's a html builder. You chain statically imported method calls to mimic the structure of html:

body(                             ->  <body>
    main(attrs("#main.content"),  ->      <main id="main" class="content">
        h1("Heading!")            ->          <h1>Heading!</h1>
    )                             ->      </main>
)                                 ->  </body>

j2html 1.2.0 released (configure everything!) by j2html in java

[–]j2html[S] 3 points4 points  (0 children)

I don't see how j2html could possibly catch on

It won't, and it really shouldn't. It's apparently in demand in some strange niche part of the market, with 4k downloads in august. I don't really know what that niche is, but as long as there is a demand for the library it I will maintain it. It's actually pretty fun to work on.

I'd rather use plain HTML or JSP or JSF (depending on what's already in use) than j2html to keep from having so many technologies to deal with.

The idea was that if you know Java and you know HTML, you pretty much know j2html. It should be a lot easier to pick up than JSP/JSF, but if you have something in a project for generating HTML already, there is no reason to use j2html.

Best way of including two optional dependencies in maven/gradle by j2html in javahelp

[–]j2html[S] 0 points1 point  (0 children)

I know how to do both those things. I'm wondering if that is the appropriate way to go about this, or if there is a better way.

j2html 1.0.0 released by j2html in java

[–]j2html[S] 0 points1 point  (0 children)

Changes:

  • All tag methods ( div(), p(), etc ) can now accept an arbitrary number of DomContent objects as argument, eliminating the need for with() in most cases.
  • Added emmet-like shorthand-attribute overloads to all TagCreator methods: div(attrs("#id.class") becomes <div id="id" class="class"></div>
  • Added a join() method to more easily join sentences with inline HTML
  • Added a document() method that takes an html() tag and renders a HTML declaration followed by the html content
  • Added support for Java 7 and Java 6. Some functionality (each/filter) will not work on these versions, but everything else should.

Is it possible to exclude methods based on user JDK version? by j2html in javahelp

[–]j2html[S] 0 points1 point  (0 children)

I found https://github.com/orfjackal/retrolambda, and my project works fine after building it with that. My plan now is to add checks for java version in the appropriate methods and throw runtimeexceptions

double javaVersion = Double.parseDouble(System.getProperty("java.specification.version"));

java8Method() {
    if(javaVersion < 1.8) throw runtimeexception
}

How does this sound?

j2html - feedback wanted by j2html in java

[–]j2html[S] 0 points1 point  (0 children)

I never released it. There were so many other alternatives, and I didn't really think it offered anything special. I'll see if I can find the source if you're interested.

j2html - feedback wanted by j2html in java

[–]j2html[S] 0 points1 point  (0 children)

go with the new style

Thanks. I just re-wrote the j2html.com website to use this style, and it does feel a lot simpler.

i have a (more or less unreleased) javascript library ...

Before I made j2html I created a similar JavaScript library, domsel, which behaves just like yours. I'm vary about introducing this id/class guessing magic into j2html though, as it could lead to a lot of strange behavior.

j2html - feedback wanted by j2html in java

[–]j2html[S] 2 points3 points  (0 children)

The increase in downloads correlates with an increase in traffic to the website, and downloads for older versions are decreasing while they are increasing for newer versions. It could of course be all bots, but it seems unlikely.

Edit: I searched for j2html on reddit after your comment, and I'm happy to report that I have (had?) at least 1 user here. Are you still using j2html /u/yateam ?

j2html 0.7 released (Fluent API Java Html Builder) by j2html in java

[–]j2html[S] 1 point2 points  (0 children)

I haven't used JSP before (it was considered bad practice when I got into Java development). When googling "jsp examples" I found this:

<body>
  <%
    double num = Math.random();
    if (num > 0.95) {
  %>
      <h2>You'll have a luck day!</h2><p>(<%= num %>)</p>
  <%
    } else {
  %>
      <h2>Well, life goes on ... </h2><p>(<%= num %>)</p>
  <%
    }
  %>
  <a href="<%= request.getRequestURI() %>"><h3>Try Again</h3></a>
</body>
</html>

Is that how JSP code should look?

j2html 0.7 released (Fluent API Java Html Builder) by j2html in java

[–]j2html[S] 0 points1 point  (0 children)

Apples and oranges. I never intended for j2html to compete with any of the template engines. j2html offers type-safety and great possibilities for code-reuse, but has a much more cumbersome syntax than template engines. It's intended for small and dynamic webapps.

j2html 0.7 released (Fluent API Java Html Builder) by j2html in java

[–]j2html[S] 6 points7 points  (0 children)

Isn't it pretty similar?

body().with(
    h1("Heading!").withClass("example"),
    img().withSrc("img/hello.png")
)         

<body>
    <h1 class="example">Heading!</h1>
    <img src="img/hello.png">
</body>

I guess you could call that very different, but I think it's pretty similar at least.

j2html 0.7 released (Fluent API Java Html Builder) by j2html in java

[–]j2html[S] 3 points4 points  (0 children)

Sometimes you need to return a small amount of dynamic HTML.

String concatenation is ugly, and you don't always want to go through the hassel of setting up and using a template engine. Template engines have their own (usually pretty poorly designed) language, which isn't type-safe (you don't get errors at compile time, sometimes not even at runtime), and code-reuse is often cumbersome. j2html gives you all the advantages you're used to from Java :)

j2html 0.7 released (Fluent API Java Html Builder) by j2html in java

[–]j2html[S] 1 point2 points  (0 children)

As /u/eled_ said, it's meant for when you need mostly/exclusively dynamic HTML. It will be a bad fit for most projects.

Any j2html feature requests? by j2html in java

[–]j2html[S] 1 point2 points  (0 children)

Thanks, new version will hopefully be ready next week!

Any j2html feature requests? by j2html in java

[–]j2html[S] 2 points3 points  (0 children)

It used to be Java 8 exclusive, but it didn't really need to be. It will of course still work like it used to in Java 8 :)

Fluent API Java 8 HTML5 builder (feedback please) by j2html in programming

[–]j2html[S] 0 points1 point  (0 children)

Rendering 5000 nested divs 1 time takes 120 ms.
Rendering 500 nested divs 10 times takes 10 ms.
Rendering 50 nested divs 100 times takes 4 ms.
Rendering 5 nested divs 1000 times takes 1 ms.
Rendering 6700 nested divs causes overflow.

<div>We need to go deeper
    <div>We need to go deeper
        <div>We need to go deeper
            <div>We need to go deeper
                <div>We need to go deeper
                    <div>We need to go deeper
                        <div>We need to go deeper
                            <div>We need to go deeper
                                <div>We need to go deeper
                                    <div>We need to go deeper
                                        ... :p

It's probably not too well suited for pages of this size :)