This is an automated email from the ASF dual-hosted git repository.

pedrosans pushed a commit to branch wicket-9.x
in repository https://gitbox.apache.org/repos/asf/wicket.git

commit a64b163402b5a914b8763cc5dd128e63b1836d4a
Author: Pedro Santos <[email protected]>
AuthorDate: Tue Sep 8 16:32:12 2026 -0300

    Document the CDI integration in the user guide
    
    The enterprise integration chapter covered EJB and Spring but not
    wicket-cdi. Add a section on it between the Spring and the JSR-330
    sections, showing the CdiConfiguration setup and the injection example
    from wicket-examples.
    
    The section also states what the module is designed for: injecting
    passivation capable CDI beans, and lists which beans the CDI
    specification says those are. wicket-cdi does not use the proxies of
    wicket-ioc but the container's own mechanism, a client proxy for a
    normal-scoped bean and the instance itself for a @Dependent one, which
    is passivation capable only if serializable. The container's
    InjectionTarget can also inject other resources through the container's
    injection services, such as @EJB, @PersistenceContext or @Resource
    fields, and those are neither handled by wicket-ioc nor guaranteed to be
    serializable. So it is up to the application to inject only passivation
    capable beans into its components, or to keep anything else out of the
    serialized page, by making it serializable or by using a transient
    field, which stays null after deserialization since the module never
    injects a component twice. The same is said on CdiConfiguration,
    where someone deciding what is safe to inject will look.
    
    The chapter summary presented the Byte Buddy proxies as if every
    integration used them; it now names wicket-spring and wicket-guice.
    
    Co-Authored-By: Claude Fable 5.1 <[email protected]>
    (cherry picked from commit 788c0c3091102d1127b936dfd368d0bd2308e9e5)
---
 .../org/apache/wicket/cdi/CdiConfiguration.java    | 13 ++++++
 wicket-user-guide/src/main/asciidoc/jee/jee_3.adoc | 52 +++++++++++++++++++---
 wicket-user-guide/src/main/asciidoc/jee/jee_4.adoc | 24 +++-------
 .../main/asciidoc/jee/{jee_4.adoc => jee_5.adoc}   |  2 +-
 wicket-user-guide/src/main/asciidoc/single.adoc    |  8 +++-
 5 files changed, 74 insertions(+), 25 deletions(-)

diff --git 
a/wicket-cdi/src/main/java/org/apache/wicket/cdi/CdiConfiguration.java 
b/wicket-cdi/src/main/java/org/apache/wicket/cdi/CdiConfiguration.java
index 8e6dfb4595..2c359a855d 100644
--- a/wicket-cdi/src/main/java/org/apache/wicket/cdi/CdiConfiguration.java
+++ b/wicket-cdi/src/main/java/org/apache/wicket/cdi/CdiConfiguration.java
@@ -24,6 +24,19 @@ import 
org.apache.wicket.request.cycle.RequestCycleListenerCollection;
 
 /**
  * Configures CDI integration
+ * <p>
+ * The module is designed to inject passivation capable CDI beans, which the 
CDI specification
+ * lists: normal-scoped beans, injected as client proxies that are 
serializable and resolve the bean
+ * again after deserialization; {@code @Dependent} beans that are serializable 
themselves;
+ * stateless and singleton session beans; resources declared through a 
producer field; and the
+ * built-in beans such as {@code BeanManager}, {@code Instance} and {@code 
Event}. The container's
+ * {@link javax.enterprise.inject.spi.InjectionTarget} it uses can also inject 
other resources
+ * through the container's injection services, such as {@code @EJB} or {@code 
@Resource} fields.
+ * Those are neither handled by wicket-ioc nor necessarily serializable, so an 
application should
+ * inject only passivation capable beans into its components, or keep anything 
else out of the
+ * serialized page by making it serializable or injecting it into a transient 
field. A component is
+ * not injected again after deserialization, so a transient field is null on a 
page loaded from the
+ * store.
  * 
  * @author igor
  * 
diff --git a/wicket-user-guide/src/main/asciidoc/jee/jee_3.adoc 
b/wicket-user-guide/src/main/asciidoc/jee/jee_3.adoc
index ea383b6f02..dd4752b1b6 100644
--- a/wicket-user-guide/src/main/asciidoc/jee/jee_3.adoc
+++ b/wicket-user-guide/src/main/asciidoc/jee/jee_3.adoc
@@ -1,13 +1,55 @@
 
 
 
-Spring (and Guice) users can use standard  
http://jcp.org/en/jsr/detail?id=330[JSR-330] annotations to wire their 
dependencies. This will make their code more interoperable with other 
containers that support this standard:
+Module _wicket-cdi_ integrates Wicket with a CDI container. Its entry point is 
class _org.apache.wicket.cdi.CdiConfiguration_, which registers the listeners 
injecting components, behaviors and the session and propagates the CDI 
conversation across requests:
 
 [source,java]
 ----
-  //inject a bean specifying its name with JSR-330 annotations
-  @Inject 
-  @Named("anotherName")
-  private EnterpriseMessage enterpriseMessage;
+public class WicketApplication extends WebApplication
+{
+  //Constructor...
+
+  @Override
+  public void init()
+  {
+    super.init();
+
+    new CdiConfiguration().configure(this);
+  }
+}
+----
+
+The _BeanManager_ is looked up from JNDI or from the CDI provider, and it can 
also be set on the configuration. Once the application is configured, 
components inject beans with the standard _@Inject_ annotation. The following 
page, taken from module wicket-examples, injects an application scoped counter:
+
+[source,java]
 ----
+@ApplicationScoped
+public class ApplicationCounter extends Counter
+{
+  //...
+}
+
+public class InjectionPage extends CdiExamplePage
+{
+  @Inject
+  ApplicationCounter counter;
+
+  public InjectionPage()
+  {
+    add(new Label("count", new PropertyModel<Integer>(this, "counter.count")));
+  }
+}
+----
+
+Module _wicket-cdi_ is designed to inject passivation capable CDI beans, that 
is beans which can be serialized with the component holding them and resolved 
again after deserialization. The CDI specification lists which beans qualify:
+
+* beans with a normal scope (_@ApplicationScoped_, _@SessionScoped_, 
_@ConversationScoped_, _@RequestScoped_ or a custom normal scope), which the 
container injects as a client proxy required to be serializable and to look the 
bean up again when deserialized;
+* _@Dependent_ beans that are serializable themselves, since these are 
injected directly;
+* stateless and singleton session beans;
+* resources declared as beans through a producer field annotated with 
_@Resource_, _@EJB_, _@PersistenceContext_, _@PersistenceUnit_ or 
_@WebServiceRef_, for which the container provides a serializable reference;
+* the built-in beans, such as _BeanManager_, _Instance_ and _Event_.
 
+Unlike the Spring and Guice integrations, _wicket-cdi_ does not rely on the 
proxies of module wicket-ioc but on that container mechanism.
+The container's _InjectionTarget_ used by the module can inject more than CDI 
beans though. Through the container's injection services it also fills fields 
annotated with _@EJB_, _@PersistenceContext_ or _@Resource_ directly, without a 
bean declaring them, and those references are neither handled by wicket-ioc nor 
guaranteed to be serializable.
+So it is up to the application to inject only passivation capable beans into 
its components, or to keep anything else out of the serialized page, either by 
making it serializable or by injecting it into a transient field.
+Note that the module does not inject a component again after deserialization, 
so a transient field is null on a page loaded from the store and the component 
must not depend on it after its construction.
diff --git a/wicket-user-guide/src/main/asciidoc/jee/jee_4.adoc 
b/wicket-user-guide/src/main/asciidoc/jee/jee_4.adoc
index 46df4c8761..ea383b6f02 100644
--- a/wicket-user-guide/src/main/asciidoc/jee/jee_4.adoc
+++ b/wicket-user-guide/src/main/asciidoc/jee/jee_4.adoc
@@ -1,23 +1,13 @@
 
-During their lifecycle Wicket components are serialized into the session or 
some secondary storage.
-But in most cases injected dependencies are not serializable, as these are 
typically singletons like services and repositories.
-Because of this Wicket uses https://github.com/cglib/cglib[cglib] to generate 
proxies that are injected instead.
-These will serialize a replacement and re-lookup the dependency after 
deserialization.
 
-For compatibility with Java 15+ runtimes, Wicket 10.x will use 
https://bytebuddy.net/#/[Byte Buddy] instead
-- this proxy generation was backported to Wicket 9.x and can optionally be 
used by specifying the `wicket.ioc.useByteBuddy` environment variable:
 
-[source,bash]
+Spring (and Guice) users can use standard  
http://jcp.org/en/jsr/detail?id=330[JSR-330] annotations to wire their 
dependencies. This will make their code more interoperable with other 
containers that support this standard:
+
+[source,java]
 ----
--Dwicket.ioc.useByteBuddy=true
+  //inject a bean specifying its name with JSR-330 annotations
+  @Inject 
+  @Named("anotherName")
+  private EnterpriseMessage enterpriseMessage;
 ----
 
-NOTE: By default injected types need a default constructor without arguments, 
otherwise proxies can not be instantiated.
-You can remedy this limitation by adding http://objenesis.org[Objenesis] to 
your project depencencies.
-
-
-
-In this chapter we have seen how to integrate Wicket applications with Spring 
and with an EJB container. Module wicket-examples contains also an example of 
integration with Guice (see application class 
_org.apache.wicket.examples.guice.GuiceApplication_). 
-
-
-
diff --git a/wicket-user-guide/src/main/asciidoc/jee/jee_4.adoc 
b/wicket-user-guide/src/main/asciidoc/jee/jee_5.adoc
similarity index 88%
copy from wicket-user-guide/src/main/asciidoc/jee/jee_4.adoc
copy to wicket-user-guide/src/main/asciidoc/jee/jee_5.adoc
index 46df4c8761..09f97501bc 100644
--- a/wicket-user-guide/src/main/asciidoc/jee/jee_4.adoc
+++ b/wicket-user-guide/src/main/asciidoc/jee/jee_5.adoc
@@ -1,7 +1,7 @@
 
 During their lifecycle Wicket components are serialized into the session or 
some secondary storage.
 But in most cases injected dependencies are not serializable, as these are 
typically singletons like services and repositories.
-Because of this Wicket uses https://github.com/cglib/cglib[cglib] to generate 
proxies that are injected instead.
+Because of this modules wicket-spring and wicket-guice use 
https://github.com/cglib/cglib[cglib] to generate proxies that are injected 
instead.
 These will serialize a replacement and re-lookup the dependency after 
deserialization.
 
 For compatibility with Java 15+ runtimes, Wicket 10.x will use 
https://bytebuddy.net/#/[Byte Buddy] instead
diff --git a/wicket-user-guide/src/main/asciidoc/single.adoc 
b/wicket-user-guide/src/main/asciidoc/single.adoc
index b575f27ad1..fa52b2dfbb 100644
--- a/wicket-user-guide/src/main/asciidoc/single.adoc
+++ b/wicket-user-guide/src/main/asciidoc/single.adoc
@@ -603,14 +603,18 @@ include::jee/jee_1.adoc[leveloffset=+1]
 
 include::jee/jee_2.adoc[leveloffset=+1]
 
-=== JSR-330 annotations
+=== Integrating Wicket with CDI
 
 include::jee/jee_3.adoc[leveloffset=+1]
 
-=== Summary
+=== JSR-330 annotations
 
 include::jee/jee_4.adoc[leveloffset=+1]
 
+=== Summary
+
+include::jee/jee_5.adoc[leveloffset=+1]
+
 == Native WebSockets
 
 include::nativewebsockets.adoc[]

Reply via email to