Hot questions for Using GlassFish in vaadin

Question:

I've been tasked to refactor an old application, which used to create DAO's all over the place, by using the new keyword, and local managed entitymanager.

Now I'm supposed to use JTA to manage the connections. For what I can understand, I should use CDI for that. So far it haven't been a problems. My views are CDI views, and i @Inject all my DAO's, or in other cases whole controllers that use the DAO's, like the following example.

@CDIView(value = TestView.VIEW_ID)
public class TestView extends Test implements View {
public static final String VIEW_ID = "testviewer";

@Inject
private
TestInterface testInterface;

public void viewLogic() {

    ...
}

While all this works fine, I'm starting to get worry. Because behind the scenes there is a lot of threads, running simultaneously. These threads would need their own instances of objects, and therefore just cannot be injected - or can they? An example would be:

@Stateless
public class TestInterface {

@Inject
TestDAO testDAO;



private List<TestRunner> getTestRunners(Test test, ToplevelTest tlt){
    List<TestRunner> runners = new ArrayList<>();
    for(SomeThing st : getTestSomethings()){
        if(st.condition())
            runners.add(new AbstractTestRunner());
        else runners.add(new FancyTestRunner());

    }
}

private SomeDataAccess(){
    testDAO.save(new Test());
}

This example code would the execute within a managed bean, which is fine (I think!), but these testrunners would also need to have access to the dataccesslayer. But I need (a variable) multiple instances of these.

I've read that you can use CDI.current().get(MySingletonClass.class) Is it a good idea (and possible?) to obtain a singleton repository to use as dataccess within these testrunners, and then just "new" the testrunners as before?

Or is there a better way to handle all this?

All suggestions are warmly received. I'm rather new to CDI.

Best regards


Answer:

You could use the more "primitive" method of dependency injection, pass an instance of MySingletonClass into the TestRunners constructor.

Question:

I do not really know how can I add a new page to a Vaadin project. As an experiment I renamed one page:

I renamed this:

@WebServlet(value = "/*", asyncSupported = true)

To:

@WebServlet(value = "/blabla1", asyncSupported = true)

However, I want a new page:

@WebServlet(value = "/blabla2", asyncSupported = true)

Unfortunatley, when I renamed the first, I get this message in Chrome:

failed to load bootstrap javascript vaadin

How do I add a second web page, given that the above renaming of the example seems to be failing?


Answer:

André´s answer is not entirely correct. While simple Vaadin applications can behave like single page applications where you only modify contents of UI without changing url, applications are usually more complex than that and require a different approach.

Signgle page applications with single url have a several disadvantages. Application usually consists of many parts and states and normally those have their own urls. User can navigate directly to desired component or state, bookmark it to visit it directly later, can use back and froward buttons etc.

In Vaadin this is achieved throug Navigator. Each UI consists of number of Views. Navigator is then used to navigate between views. Each view has its unique url represented by URL fragment, so users can navigate there, bookmart it etc.

You can read detailed tutorial about navigation here in book of vaadin.

Plain Vaadin applications do not have normal web page navigation as they usually run on a single page, as all Ajax applications do. Quite commonly, however, applications have different views between which the user should be able to navigate. The Navigator in Vaadin can be used for most cases of navigation. Views managed by the navigator automatically get a distinct URI fragment, which can be used to be able to bookmark the views and their states and to go back and forward in the browser history.

Question:

Utilities: IntelliJ, Glassfish server, Vaadin API

EDIT: I should mention that this is my first time using Vaadin

I have a simple Vaadin application that I'm trying to launch as a test. If I run it on the command line (with Maven) and launch it from the Glassfish Applications panel in the admin console, it works perfectly. When I try to use the same code in IntelliJ, I get a 404 error. I want to use IntelliJ for debugging purposes, so it's important that I get it to work from there as well. Here is the code I am using:

@Title("test")
@Theme("valo")
public class MyVaadinApplication extends UI {
    private String user;
    private String pwd;

    @WebServlet(value = "/*", asyncSupported = false)
    @VaadinServletConfiguration(productionMode = false, ui = MyVaadinApplication.class)
    public static class Servlet extends VaadinServlet {
    }

    @Override
    protected void init(VaadinRequest request) {

        FormLayout form = new FormLayout();
        setContent(form);

        TextField nameField = new TextField("Name:");
        PasswordField passField = new PasswordField("Password:");
        Button button = new Button("Login");

        form.addComponent(nameField);
        form.addComponent(passField);
        form.addComponent(button);

        button.addClickListener(new Button.ClickListener() {
            public void buttonClick(ClickEvent event) {
                user = nameField.getValue();
                pwd = passField.getValue();
            }
        });

    }
}

Here is the web.xml (it's pretty empty and irrelevant). From my understanding, if you use the @WebServlet and @VaadinServletConfiguration annotations, you do not need to specify any mappings/servlets in the web.xml file. Somebody please correct me if I'm wrong.

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>test</display-name>

<security-role>
    <role-name>admin</role-name>
</security-role>

<security-role>
    <role-name>user</role-name>
</security-role>

And finally my Maven pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>gov.bnl.cad</groupId>
<artifactId>test</artifactId>
<version>1.0</version>
<packaging>war</packaging>
<properties>
    <vaadin.version>7.4.2</vaadin.version>
    <vaadin.plugin.version>${vaadin.version}</vaadin.plugin.version>
    <jetty.plugin.version>9.2.3.v20140905</jetty.plugin.version>
    <project.source.version>1.8</project.source.version>
    <project.target.version>1.8</project.target.version>
    <project.encoding>UTF-8</project.encoding>
</properties>
<distributionManagement>
    <repository>
        <id>CAD Repo</id>
        <url>file:///usr/common/jar/cad-repo</url>
    </repository>
    <site>
        <id>${project.artifactId}</id>
        <url>/usr/common/jar/cad-repo/${project.artifactId}</url>
    </site>
</distributionManagement>
<repositories>
    <repository>
        <id>CAD Repo</id>
        <url>file:///usr/common/jar/cad-repo/</url>
    </repository>
    <repository>
        <id>vaadin-addons</id>
        <url>http://maven.vaadin.com/vaadin-addons</url>
    </repository>
    <repository>
        <id>vaadin-snapshots</id>
        <url>https://oss.sonatype.org/content/repositories/vaadin-snapshots/</url>
        <releases>
            <enabled>false</enabled>
        </releases>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
</repositories>

<dependencies>
    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-api</artifactId>
        <version>6.0</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.0.1</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>com.vaadin</groupId>
        <artifactId>vaadin-server</artifactId>
        <version>${vaadin.version}</version>
    </dependency>
    <dependency>
        <groupId>com.vaadin</groupId>
        <artifactId>vaadin-themes</artifactId>
        <version>${vaadin.version}</version>
    </dependency>
    <dependency>
        <groupId>com.vaadin</groupId>
        <artifactId>vaadin-push</artifactId>
        <version>${vaadin.version}</version>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>3.0-alpha-1</version>
    </dependency>
    <dependency>
        <groupId>com.vaadin</groupId>
        <artifactId>vaadin-client</artifactId>
        <version>${vaadin.version}</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>com.vaadin</groupId>
        <artifactId>vaadin-client-compiled</artifactId>
        <version>${vaadin.version}</version>
    </dependency>
    <dependency>
        <groupId>com.vaadin</groupId>
        <artifactId>vaadin-client-compiler</artifactId>
        <version>${vaadin.version}</version>
    </dependency>
    <dependency>
        <groupId>gov.bnl.cad</groupId>
        <artifactId>pageParser</artifactId>
        <version>1.0-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>gov.bnl.cad</groupId>
        <artifactId>rcs-cad</artifactId>
        <version>1.0-SNAPSHOT</version>
    </dependency>
</dependencies>


<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.4.0</version>
                <executions>
                    <execution>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>java</goal>
                        </goals>
                        <configuration>
                            <classpathScope>compile</classpathScope>
                            <mainClass>com.vaadin.sass.SassCompiler</mainClass>
                            <arguments>
                                <argument>src/main/webapp/VAADIN/themes/dashbuilder/styles.scss</argument>
                            </arguments>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.0</version>
                <configuration>
                    <encoding>${project.encoding}</encoding>
                    <source>${project.source.version}</source>
                    <target>${project.target.version}</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <version>2.6</version>
                <configuration>
                    <encoding>${project.encoding}</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.3</version>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                    <!-- Exclude some unnecessary files generated by the GWT compiler. -->
                    <packagingExcludes>WEB-INF/classes/VAADIN/gwt-unitCache/**,
                        WEB-INF/classes/VAADIN/widgetsets/WEB-INF/**</packagingExcludes>
                </configuration>
            </plugin>
            <plugin>
                <groupId>com.vaadin</groupId>
                <artifactId>vaadin-maven-plugin</artifactId>
                <version>${vaadin.plugin.version}</version>
                <configuration>
                    <extraJvmArgs>-Xmx512M -Xss1024k</extraJvmArgs>
                    <webappDirectory>${basedir}/target/classes/VAADIN/widgetsets</webappDirectory>
                    <draftCompile>false</draftCompile>
                    <compileReport>false</compileReport>
                    <style>OBF</style>
                    <strict>true</strict>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>clean</goal>
                            <goal>resources</goal>
                            <goal>update-theme</goal>
                            <goal>update-widgetset</goal>
                            <goal>compile-theme</goal>
                            <goal>compile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <version>2.4</version>
            </plugin>

            <!-- The Jetty plugin allows us to easily test the development build by
                running jetty:run on the command line. -->
            <plugin>
                <groupId>org.eclipse.jetty</groupId>
                <artifactId>jetty-maven-plugin</artifactId>
                <version>${jetty.plugin.version}</version>
                <configuration>
                    <scanIntervalSeconds>2</scanIntervalSeconds>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
</build>

Any help is greatly appreciated. Thank you!


Answer:

With Servlet 3+ you don't need to use web.xml at all, given annotations are provided in your code. So you can just delete that file if you want. If you use web.xml it will override your annotated settings.

So delete your web.xml file and change value = "/*" to urlPatterns = "/*" in @WebServlet annotation then try again.

If it still doesn't work, you need to check your IntelliJ run configurations explicitly. Your server might not be configured properly in the IDE.

Question:

I've JDK 1.8 and using NetBeans IDE 8.0 to develop my vaadin 7.5.3 application. No idea whats causing this exception.

Detail of the Exception

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x000000006fc26a6b, pid=6200, tid=12848
#
# JRE version: Java(TM) SE Runtime Environment (8.0-b132) (build 1.8.0-b132)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.0-b70 mixed mode windows-amd64 compressed oops)
# Problematic frame:
# V  [jvm.dll+0x2b6a6b]
#
# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
#
# An error report file with more information is saved as:
# C:\Program Files\glassfish-4.0\glassfish\domains\domain1\config\hs_err_pid6200.log
Compiled method (c1) 1102730  563       2       java.lang.NullPointerException::<init> (5 bytes)
 total in heap  [0x0000000002dc4290,0x0000000002dc4600] = 880
 relocation     [0x0000000002dc43b0,0x0000000002dc43e8] = 56
 main code      [0x0000000002dc4400,0x0000000002dc44c0] = 192
 stub code      [0x0000000002dc44c0,0x0000000002dc4568] = 168
 metadata       [0x0000000002dc4568,0x0000000002dc4588] = 32
 scopes data    [0x0000000002dc4588,0x0000000002dc45b0] = 40
 scopes pcs     [0x0000000002dc45b0,0x0000000002dc45f0] = 64
 dependencies   [0x0000000002dc45f0,0x0000000002dc4600] = 16
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.sun.com/bugreport/crash.jsp
#
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=192m; support was removed in 8.0

Update

here is hs_err_pid6200.log file http://pastebin.com/RNGkvvtQ

And I'm using jRebel and xrebel

here is my JVM options:


Answer:

the Xrebel trial period was over and apparently the glassfish server start crashing often after tht, I've removed the xrebel from my JVM options and currently there is no JRE exception So I think the problem was with the out dated Xrebel. hope this helps someone