Thymeleaf CDI Integration

An extension for Thymeleaf that allows referencing CDI @Named beans as top-level objects in expressions.

Лицензия

Лицензия

Категории

Категории

Leaf Данные Базы данных
Группа

Группа

hu.inbuss
Идентификатор

Идентификатор

thymeleaf-cdi
Последняя версия

Последняя версия

0.0.9
Дата

Дата

Тип

Тип

jar
Описание

Описание

Thymeleaf CDI Integration
An extension for Thymeleaf that allows referencing CDI @Named beans as top-level objects in expressions.
Ссылка на сайт

Ссылка на сайт

https://github.com/inbuss/thymeleaf-cdi
Система контроля версий

Система контроля версий

http://github.com/inbuss/thymeleaf-cdi/tree/master

Скачать thymeleaf-cdi

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/hu.inbuss/thymeleaf-cdi/ -->
<dependency>
    <groupId>hu.inbuss</groupId>
    <artifactId>thymeleaf-cdi</artifactId>
    <version>0.0.9</version>
</dependency>
// https://jarcasting.com/artifacts/hu.inbuss/thymeleaf-cdi/
implementation 'hu.inbuss:thymeleaf-cdi:0.0.9'
// https://jarcasting.com/artifacts/hu.inbuss/thymeleaf-cdi/
implementation ("hu.inbuss:thymeleaf-cdi:0.0.9")
'hu.inbuss:thymeleaf-cdi:jar:0.0.9'
<dependency org="hu.inbuss" name="thymeleaf-cdi" rev="0.0.9">
  <artifact name="thymeleaf-cdi" type="jar" />
</dependency>
@Grapes(
@Grab(group='hu.inbuss', module='thymeleaf-cdi', version='0.0.9')
)
libraryDependencies += "hu.inbuss" % "thymeleaf-cdi" % "0.0.9"
[hu.inbuss/thymeleaf-cdi "0.0.9"]

Зависимости

compile (1)

Идентификатор библиотеки Тип Версия
org.thymeleaf : thymeleaf jar 3.0.2.RELEASE

provided (2)

Идентификатор библиотеки Тип Версия
javax.servlet : servlet-api jar 2.5
javax.enterprise : cdi-api jar 1.2

Модули Проекта

Данный проект не имеет модулей.

thymeleaf-cdi

An extension for Thymeleaf that allows referencing CDI named beans as top-level objects in expressions. This works with the Standard Dialect and its OGNL-based expression language - Spring users would probably not be interested in CDI integration anyway.

Dependencies

This extension is a bridge between the CDI standard and Thymeleaf; your project should already contain both Thymeleaf and the CDI API.

The extension targets the CDI 1.2 standard. It may run on earlier versions as well, but this was not tested. An implementation of the standard must be provided by the environment or the application at runtime. (The extension was tested using Weld 2.3.5, but any compliant implementation should work.)

The Thymeleaf side is written against the Thymeleaf 3 API. Earlier versions cannot be reasonably supported due to the lack of lazy context variable evaluation.

Usage

  1. Include the library in your project. For example with Maven:

        <dependency>
            <groupId>hu.inbuss</groupId>
            <artifactId>thymeleaf-cdi</artifactId>
            <version>0.0.9</version>
        </dependency>

    or with Gradle:

    dependencies {
        compile 'hu.inbuss:thymeleaf-cdi:0.0.9'
    }
  2. When you invoke TemplateEngine.process(), you have to pass in an IContext object. Instead of constructing a new instance of Thymeleaf's WebContext class, get a reference to a CDIWebContextFactory bean (probably via dependency injection) and get a CDIWebContext instance from it. For example:

    import hu.inbuss.thymeleaf.cdi.CDIWebContextFactory;
    import javax.inject.Inject;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import org.thymeleaf.TemplateEngine;
    import org.thymeleaf.context.IWebContext;
    
    public class Example extends HttpServlet {
        @Inject private CDIWebContextFactory ctxFactory;
    
        public void doGet(HttpServletRequest req, HttpServletResponse resp) {
            final IWebContext ctx = ctxFactory.create(req, resp);
            final TemplateEngine engine = /* ... */;
            engine.process(/* template name */, ctx, resp.getWriter());
        }
    }

    (If your project was using plain Context instead of WebContext, replace it with a CDIContext instance obtained from the CDIContextFactory bean.)

  3. You're ready. Define CDI named beans, e.g.

    @javax.enterprise.context.SessionScoped
    @javax.inject.Named("cart")
    public class ShoppingCart implements java.io.Serializable {
        public int getItemCount() {
            /* ... */     
        }
        /* ... */
    }

    then reference them from a template:

    <span>You have <em th:text="${cart.itemCount}">many</em> products in your cart.</span>
hu.inbuss

INBUSS Kft.

Версии библиотеки

Версия
0.0.9
0.0.1