Java Magazine, July/August 2018
ORACLE COM JAVAMAGAZINE JULY AUGUST 2018 31 libraries methods such as head body and div are represented with an instance of ContainerTag within the library ContainerTag stores the name of the tag along with its children referenced as List DomContent DomContent is the abstract class that refers either to text or tags used inside the HTML document ContainerTag implements the interface Renderable as well which defines the content that can be represented as a string and it provides a default implementation for the render methods The Attribute class defines the attributes of HTML elements and they can be implemented by the with method syntax for example withRel withHref and withClass as I did in Listing 4 Deep Dive j2html provides various approaches for HTML generation and I will try to address some of them in this section Appending texts and tags to each other is easy with the join method with which you can concatenate input elements in a given order separated by a space The method also removes spaces before periods and commas An example is shown in Listing 6 DomContent Figure 1 Important part of the class hierarchy C C C C C I C C Renderable Attribute Tag Text UnescapedText ContainerTag EmptyTag
You must have JavaScript enabled to view digital editions.