GithubHelp home page GithubHelp logo

cdi's Introduction

Published on Vaadin  Directory Stars on Vaadin Directory

Vaadin CDI

This is the official CDI integration for Vaadin Flow.

This branch is compatible with upcoming Vaadin platform versions. See other branches for other Vaadin versions:

  • 15.0 for Vaadin 24
  • 14.1 for Vaadin 23.3
  • 13.1 for Vaadin 22.1
  • 11.3 for Vaadin 14.10
  • 10.0 for Vaadin 10
  • 3.0 for Vaadin 8.2+
  • 2.0 for Vaadin Framework 8.0...8.1 versions
  • 1.0 for Vaadin Framework 7 versions

Using with Vaadin 10

To use CDI with Vaadin 10, you need to add the following dependency to your pom.xml:

<dependency>
  <groupdId>com.vaadin</groupId>
  <artifactId>vaadin-cdi</artifactId>
  <version>10.0.0.beta1</version> <!-- Or the LATEST version -->
</dependency>

Since the current release version is a prerelease, you need to also include the prerelease Maven repository:

<repositories>
  <repository>
    <id>Vaadin prereleases</id>
    <url>https://maven.vaadin.com/vaadin-prereleases</url>
  </repository>
</repositories>

Getting started

NOTE: This is still WIP. The easiest way for starting a project is to go to vaadin.com/start and select the Project Base with CDI to get an empty project with everything setup ready for you.

NOTE: This is still WIP. There is a tutorial also available in https://github.com/vaadin/flow-cdi-tutorial that helps you get started with Vaadin 10 and CDI.

Building the project

Execute mvn clean install -DskipTests in the root directory to build vaadin-cdi.

Run integration tests

Execute mvn -pl vaadin-cdi-itest -Ptomee verify in the root directory to run integration tests.

Test can be executed against the following containers, activating the specific profile:

  • Wildfly Jakarta EE 9: -Pwidfly
  • Wildfly Jakarta EE 10: -Pwidfly,jakartaee-10
  • OpenLiberty Jakarta EE 9: -Pliberty
  • OpenLiberty Jakarta EE 10: -Pliberty,jakartaee-10
  • Payara Jakarta EE 10: -Ppayara (Payara does not support Jakarta EE 9)
  • TomEE Jakarta EE 9: -Ptomee (TomEE does not yet support Jakarta EE 10)

Issue tracking

If you find an issue, please report it in the GitHub issue tracker.

Contributions

The contributing docs can be found here: https://vaadin.com/docs-beta/latest/guide/contributing/overview/

cdi's People

Contributors

adambien avatar artur- avatar binbalenci avatar bwackninja avatar caalador avatar dependabot[bot] avatar enver-haase avatar gilberto-torrezan avatar haijian-vaadin avatar hesara avatar jumic avatar juusovalli avatar klenkes74 avatar kumm avatar legioth avatar manolo avatar marcinvaadin avatar marcushellberg avatar mcollovati avatar mehdi-vaadin avatar mshabarov avatar peterl1084 avatar pleku avatar roeltje25 avatar sknitelius avatar taefi avatar tepi avatar tsuoanttila avatar zch avatar zhesun88 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cdi's Issues

build fails ....

cloned the repo, ran mvn clean install:

[ERROR] Failed to execute goal org.codehaus.mojo:properties-maven-plugin:1.0-alpha-2:read-project-properties (default) on project vaadin-cdi: Execution default of goal org.codehaus.mojo:properties-maven-plugin:1.0-alpha-2:read-project-properties failed. NullPointerException -> [Help 1]

"Ambiguous injectinon point" error with vaadin-cdi-integration and Seam Solder - Produces

JaasTools contains:

@produces
@RequestScoped
public static HttpServletRequest getCurrentRequest() {
HttpServletRequest request = VaadinServletService
.getCurrentServletRequest();
getLogger().info("Getting request " + request);

    return request;
}

The @produces allows the following, for instance:
@Inject HttpServletRequest request;

However, if any other part of the app (Seam Solder, in my case) also produces that, the app won't start (see Exception below). There's no way around it that I know of , without either changing the source of vaadin-cdi-integration or Seam Solder.

Is the @produces really needed here? (I don't see any @Inject usages). If it is deemed needed, perhaps it could be qualified? It would be nice to allow Seam Solder to be used along side vaadin-cdi, and Seam solder is not likely to remove it, I think...

Exceptions:
org.jboss.weld.exceptions.DeploymentException: WELD-001409 Ambiguous dependencies for type [HttpServletRequest] with qualifiers [@default] at injection point [[field] @Inject private org.jboss.solder.servlet.http.RequestParamProducer.request]. Possible dependencies [[Producer Method [HttpServletRequest] with qualifiers [@Any @default] declared as [[method] @produces @typed @RequestScoped protected org.jboss.solder.servlet.http.ImplicitHttpServletObjectsProducer.getHttpServletRequest()], Producer Method [HttpServletRequest] with qualifiers [@Any @default] declared as [[method] @produces @RequestScoped public static com.vaadin.cdi.component.JaasTools.getCurrentRequest()]]]

@Postconstruct not called

Originally by ronald.vermeire


In vaadin-cdi-example InjectableLayout initLayout() is not called when run with mvn tomee:run

When run with mvn jboss-as:run it gives a NullPointerException in InjectableLayout constructor. I could workaround this by adding @CDIUI to InjectableLayout.


Imported from https://dev.vaadin.com/ issue #11594

Views supporting parameters currently have too heavy restrictions on their names

Let's say I have two views, with the following URLs:

  • /myapp/#!users - shows all the users
  • /myapp/#!user/123 - shows only the user with the ID 123

In this case, the view name of the first view would be users with no support for parameters and the view name of the second view would be user with support for parameters. However, currently Vaadin CDI would find both of the views when looking for the first view. This is because it looks for candidate views by checking if the URL fragment starts with the view name. In this case the fragment #!users starts with both user and users.

The code should be changed so that if view parameters are allowed, they are stripped from the fragment in some way and then the complete view name is used when looking for candidates.

java.lang.IllegalStateException: UI id has already been defined after VaadinSession.close

I've implemented a logout method according to the vaadin Book (4.7.7 Closing a Session).
The method redirects the browser to another page, and close the vaadin session.

    private void logout() {
        getPage().setLocation("/myapp/hello.html");
        getSession().close();
    }

After logout, while navigating back to my UI i get this Exception:

SEVERE: java.lang.IllegalStateException: UI id has already been defined
    at com.vaadin.ui.UI.doInit(UI.java:519)
    at com.vaadin.server.AbstractCommunicationManager.getBrowserDetailsUI(AbstractCommunicationManager.java:2468)
    at com.vaadin.server.AbstractCommunicationManager.handleBrowserDetailsRequest(AbstractCommunicationManager.java:2362)
    at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:325)
    at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:201)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:770)

My workaround is to close the underlying http session too.

getSession().getSession().invalidate();

This way UIScopedContext destroyed, and my UI can reload.

I think UIScopedContext should destroy automatically on VaadinSession.close.

Closing the UI does not trigger @UIScope destruction

Originally by @Artur-


Using the following simple UI causes strange effects when invalidating the VaadinSession or HTTP session:

@CDIUI
public class CditestUI extends UI {

    @Override
    protected void init(VaadinRequest request) {
        final VerticalLayout layout = new VerticalLayout();
        layout.setMargin(true);
        setContent(layout);
        Button closeUI = new Button("Close UI");
        closeUI.addClickListener(new Button.ClickListener() {
            @Override
            public void buttonClick(ClickEvent event) {
                close();
            }
        });
        layout.addComponent(closeUI);

        Button closeSession = new Button("Close VaadinSession");
        closeSession.addClickListener(new Button.ClickListener() {
            @Override
            public void buttonClick(ClickEvent event) {
                getSession().close();
            }
        });
        layout.addComponent(closeSession);

        Button invalidate = new Button("Invalidate session");
        invalidate.addClickListener(new Button.ClickListener() {
            @Override
            public void buttonClick(ClickEvent event) {
                getSession().getSession().invalidate();
            }
        });
        layout.addComponent(invalidate);
    }

    @PostConstruct
    public void postConstruct() {
        System.out.println("postConstruct");
    }

    @PreDestroy
    public void preDestroy() {
        System.out.println("preDestroy");
    }
}

Open the UI, click "Close UI". Note that the preDestroy method is never called. Refreshing until a new UI is shown does not trigger preDestroy either.


Imported from https://dev.vaadin.com/ issue #11792

ContextDeployer breaks VaadinServlet configurability

See here for some details: Vaadin forum

Basically I want to be able to do stuff like

  • provide my own SystemMessagesProvider
  • programmatically configure production mode

In a regular Vaadin app I can do all that by subclassing the VaadinServlet. However, since the instantiation of VaadinServlet is hardcoded in ContextDeployer I have no way of providing my own subclass.

Permission check in CDIViewProvider

In order to be able to use other security mechanism than the default JavaEE one (for example Apache Shiro), it is necessary that the method

private boolean isUserHavingAccessToView(Bean<?> viewBean)

is protected and not private, so that it can be overwritten.

java.lang.IllegalStateException: UI id has already been defined after VaadinSession.close

Originally by kumm0307


I've implemented a logout method according to the vaadin Book (4.7.7 Closing a Session).
The method redirects the browser to another page, and close the vaadin session.

private void logout() {
        getPage().setLocation("/myapp/hello.html");
        getSession().close();
    }

After logout, while navigating back to my UI i get this Exception:

SEVERE: java.lang.IllegalStateException: UI id has already been defined
    at com.vaadin.ui.UI.doInit(UI.java:519)
    at com.vaadin.server.AbstractCommunicationManager.getBrowserDetailsUI(AbstractCommunicationManager.java:2468)
    at com.vaadin.server.AbstractCommunicationManager.handleBrowserDetailsRequest(AbstractCommunicationManager.java:2362)
    at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:325)
    at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:201)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:770)

My workaround is to close the underlying http session too.

getSession().getSession().invalidate();

This way UIScopedContext destroyed, and my UI can reload.

I think UIScopedContext should destroy automatically on VaadinSession.close.


Imported from https://dev.vaadin.com/ issue #11418

.project checked in although listed in .gitignore

the root .gitignore marks .project as ignored, but still the repo lists a .project file (twice to be precise, one in root, one in sub-project cdi-integration.
Wouldn't it be cleaner to remove them?

Recent renaming VaadinUI to CDIUI is misleading

The name CDIUI and CDIView (prefix CDI) is misleading. The class it not a CDIView (CDI does not have any views). VaadinUI was better, but longer. I would rename it back to VaadinUI or just straight to UI.

Support for slashes in view names

Right now, a slash in the view name seems to indicate that the text to the right of the slash consists of parameters and is not a part of the view name. However, it would be nice if slashes could be supported in the view names as well, since these could be used for namespacing. For example:

  • /myapp/#!people/users
  • /myapp/#!people/user/123
  • /myapp/#!people/contacts
  • /myapp/#!people/contacts/456

Enhancement: Support new "ViewScoped" scope to help with memory management for "one page apps"

In our "one page app" using vaadin-cdi-integration, users only ever use one "ShellUi" UI class and switch between high level functional views with a MenuBar and Navigator. I believe that a consequence of this is that each view bean will live throughout the lifecycle of the UI Bean, which could eventually lead to a large session size as the user traverses the app. It would be nice to have a narrower scope, such as "ViewScoped" (modeled after the JSF 2.0 ViewScoped, which I believe is conceptually somewhat similar), such that the view and its dependent beans would be cleaned up when the Navigator switches top level views.

Closing of VaadinSession does not trigger @UIScope destruction

Originally by @Artur-


Using the following simple UI causes strange effects when invalidating the VaadinSession or HTTP session:

@CDIUI
public class CditestUI extends UI {

    @Override
    protected void init(VaadinRequest request) {
        final VerticalLayout layout = new VerticalLayout();
        layout.setMargin(true);
        setContent(layout);

        Button closeSession = new Button("Close VaadinSession");
        closeSession.addClickListener(new Button.ClickListener() {
            @Override
            public void buttonClick(ClickEvent event) {
                getSession().close();
            }
        });
        layout.addComponent(closeSession);

        Button invalidate = new Button("Invalidate session");
        invalidate.addClickListener(new Button.ClickListener() {
            @Override
            public void buttonClick(ClickEvent event) {
                getSession().getSession().invalidate();
            }
        });
        layout.addComponent(invalidate);
    }

    @PostConstruct
    public void postConstruct() {
        System.out.println("postConstruct");
    }

    @PreDestroy
    public void preDestroy() {
        System.out.println("preDestroy");
    }
}

Open the UI, click "Close VaadinSession". Note that the preDestroy method is never called. Refreshing until a new UI is shown does not trigger preDestroy either.


Imported from https://dev.vaadin.com/ issue #11791

Lack of @Root

The @root annotation was removed. It means: any @CDIUI annotation with an empty value marks a root. With that you can very efficiently declare a single root (it actually happens only once), but we are loosing Convention over Configuration capabiltities: previously the URI was automatically derived from the CDIUI#getClass().getSimpleName().

Now you will have to declare the URI for all UIs. The behavior is actually not consistent with the JavaEE 6 API (EJBs, CDI, JPA).

Proposal: revival of the @root annotation.

Eliminate VaadinCDIServlet

Originally by @hesara


CDI should be possible to do with just CDIUIProvider without a custom servlet to use use it with other servlet classes than the default one.

This requires the UIProvider to be configured automatically for a new VaadinServlet by the context deployer (when no Vaadin servlets configured by the user).


Imported from https://dev.vaadin.com/ issue #11405

Ability to use custom servlets

Originally by @vaadin-kim


The current ContextDeployer implementation doesn't give much room for customization. For example, if I want to use a custom servlet, I would have to copy quite a lot of code since all the necessary methods are set as private.


Imported from https://dev.vaadin.com/ issue #11931

Mark @UIScoped as @Inherited

When using abstract UI/Component classes, it would eliminante a possible client mistake (I just made when using cdiutils).
If a parent component decides that the scope is UI, then the extending component should just go along with it

Remove @Root

Originally by @Artur-


There seem to be no need to have a @root annotation. Instead @CDIUI should by default map the UI to "/" (if there is no path defined). Multiple @CDIUIs with "/" mapping should cause an error.


Imported from https://dev.vaadin.com/ issue #11218

Turn vaadin-cdi in an OSGi citizien

Vaadin components are already bundles. Weld was ported to OSGi also. so to be able to use vaadin plus cdi in a OSGi environment we need to port vaadin-cdi too.

Remove automatic CDI view name generation

Originally by @hesara


CDI view names are currently generated automatically when not explicitly specified. This prevents easily registering a root view via @CDIView and desired view names rarely match the class names except in tests.

Automatic generation of view names should be removed so that no name specified means root (default) view.


Imported from https://dev.vaadin.com/ issue #11330

Support injecting Views into Navigator using CDI

Originally by @Legioth


With basic CDI support in the framework and Root instances managed by CDI (#9260), we could allow injecting a Navigator instance that would automatically inject and use View instances marked with a @VaadinView annotation.

@VaadinView would have two parameters to control the behavior. The first is name that is used to define the fragment name that should be used to navigate to the View. If no value is defined, getSimpleName() of the View class is used.

The second parameter is root that contains the Class of the Root to which the View should belong in case there are multiple Root classes in the Application (injecting Navigator instances). If no root parameter is provided, the View gets assigned to the Root that is configured to be served by requests to the Application's root path (if there's no such Root, an exception should be thrown as early as possible).

From a technical point of view, all the CDI integration should probably be defined in a custom ViewProvider.


Imported from https://dev.vaadin.com/ issue #9261

Producers for static helpers (UI.getCurrent(), ...)

Vaadin 7 provides a bunch of static helpers. While easy to use, those are hard to test/mock. In cdi context, we should provide producers like

@produces
@current
public UI getCurrentUI() {
return UI.getCurrent();
}
}

Now we can just use

@Inject
@current
private Instance ui;

Those can be easily injected and combined and for testing/mocking I dont have to mess with the static methods.

RuntimeException when executing tests

The exception below is thrown when running the test on the vaadin-cdi project. I think it only happens, when there is no Vaadin-7.0-SNAPSHOT in the local maven repository. To fix it, I changed the version to 7.0.2 (the version the project currently depends on) in the ArchiveProvider class.

java.lang.RuntimeException: Could not invoke deployment method: public static org.jboss.shrinkwrap.api.spec.WebArchive com.vaadin.cdi.MultipleRootUIsIT.archiveWithMultipleRoots()
at org.jboss.shrinkwrap.impl.base.container.ContainerBase.addAsLibrary(ContainerBase.java:1534)
at org.jboss.shrinkwrap.impl.base.container.ContainerBase.addAsLibrary(ContainerBase.java:1476)
at org.jboss.shrinkwrap.impl.base.container.ContainerBase.addAsLibrary(ContainerBase.java:1450)
at org.jboss.shrinkwrap.impl.base.container.ContainerBase.addAsLibraries(ContainerBase.java:1612)
at com.vaadin.cdi.ArchiveProvider.base(ArchiveProvider.java:55)
at com.vaadin.cdi.ArchiveProvider.createWebArchive(ArchiveProvider.java:46)
at com.vaadin.cdi.MultipleRootUIsIT.archiveWithMultipleRoots(MultipleRootUIsIT.java:62)

Closing of VaadinSession is handled incorrectly in vaadin-cdi

Originally by @Artur-


Using the following simple UI causes strange effects when invalidating the VaadinSession or HTTP session:

@CDIUI
public class CditestUI extends UI {

    @Override
    protected void init(VaadinRequest request) {
        final VerticalLayout layout = new VerticalLayout();
        layout.setMargin(true);
        setContent(layout);

        Button closeSession = new Button("Close VaadinSession");
        closeSession.addClickListener(new Button.ClickListener() {
            @Override
            public void buttonClick(ClickEvent event) {
                getSession().close();
            }
        });
        layout.addComponent(closeSession);

        Button invalidate = new Button("Invalidate session");
        invalidate.addClickListener(new Button.ClickListener() {
            @Override
            public void buttonClick(ClickEvent event) {
                getSession().getSession().invalidate();
            }
        });
        layout.addComponent(invalidate);
    }

    @PostConstruct
    public void postConstruct() {
        System.out.println("postConstruct");
    }

    @PreDestroy
    public void preDestroy() {
        System.out.println("preDestroy");
    }
}

Open the UI, click "Close VaadinSession" and then refresh the browser

The result is

com.vaadin.server.ServiceException: java.lang.IllegalStateException: VaadinServiceSession has already been set. Old session: com.vaadin.server.VaadinSession@22c6bb6c for VaadinServlet. New session: com.vaadin.server.VaadinSession@2a2096d7 for VaadinServlet.

Click refresh again in the browser and the result is either the same or

com.vaadin.server.ServiceException: java.lang.IllegalStateException: UI id has already been defined

Click refresh a couple of more times and you will get a new UI.


Imported from https://dev.vaadin.com/ issue #11790

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.