スキップしてメイン コンテンツに移動

投稿

ラベル(layout)が付いた投稿を表示しています

Thymeleafのthymeleaf-layout-dialectライブラリはGraalVMで使えない (2023年2月時点)

筆者の開発しているプロジェクトでは、Spring BootのテンプレートエンジンにThymeleafを使っており、全画面共通のレイアウトテンプレートを定義するために thymeleaf-layout-dialect を利用していました。 このプロジェクトでGraalVMを使ってネイティブコードを生成しようと悪戦苦闘していたのですが、2023年2月時点では thymeleaf-layout-dialect がネイティブコンパイルに対応していないため無理という結論になりました。 native-imageのコマンド実行時にエラーになるクラスを --initialize-at-build-time 、 --initialize-at-run-time で手作業で追加していたのですが、追加する数が多すぎて無理でした。。。 それほどページ数は多くなかったので、泣く泣く thymeleaf-layout-dialect の利用をあきらめ、重複は増えてしまいますが、Thymeleaf標準機能だけで全テンプレートを書き換えました。 GitHub上のissueを見ていたところ、ライブラリの作成者も問題に気づいているようなので、今後対応されるかもしれません。 https://github.com/ultraq/thymeleaf-layout-dialect/issues/232

Html Layout by JSP

Introduction In this post, I will introduce how to achieve html layout by jsp. You just define layout and put piece of elements in each actual jsp. I won't explain details but just show you an quick example for sharing "header & footer" in all jsp pages. If you are interested in how & why it works, please refer jsp documentation (or googling). Code Simply you need to prepare a layout tag file and actual jsp files. Prepare layout.tag (actually name is not so important) and put it under WEB-INF/tags. Put header.jsp and footer.jsp under WEB-INF/views/ Create actual jsp which include taglib you previously defined above step. Ok now I will show you the actual codes. layout.tag A key part is using fragment feature. <%@tag description="Layout template" pageEncoding="UTF-8"%> <%@attribute name="main" fragment="true" %> <%@attribute name="head" fragment="true" %> <%@attribu