UI instance with embedded Jetty

Hello community,

I’am new at using Vaadin and not a professional java developer now.

I write a Application using Vaadin 7. I use Vaadin as View for my Application. At the moment i use a embedded Jetty server to run the application with the web.xml.


private static String CONTEXT_PATH = "/";
    private static String RESOURCE_BASE = "WebContent";
//-----------------------------------------------------------------------------------

server = new Server(port);

	webAppContext = new WebAppContext();
	webAppContext.setContextPath(CONTEXT_PATH);
	webAppContext.setResourceBase(RESOURCE_BASE);
	webAppContext.setParentLoaderPriority(true);
	webAppContext.setClassLoader(Thread.currentThread().getContextClassLoader());

	server.setHandler(webAppContext);

But i need to get the instance of my class which inharits the UI to call some of its methodes to add some components or data out of my main controller while the Application is running.
Is this possible and how?

Hope someone could help me with this problem.

Florian

I thought I could save and use the first generated object of the UI (Singleton). I hoped to change and add content with this instance.
But it does not work completely.

I’ll be happy for any help/hints.

I actually might not have understood your problem… but the current instance of the UI can be obtained using UI.getCurrent().

Thanks for the response.
How to use this static UI.getCurrent()? Because it seames like, no matter when or where it returns just null.

I might try to explain my problem better.

I have one normal java class which is my Main Controller. This class extends a class from a other Projekt for some data connections.
This class has got a other class. The WebAppCtrl. This class should be able to start and stop my server with the WebApp (the class which is extending the UI). Also (and this is the Problem) I should have the Object of my UI class to access it. Because in the WebAppCtrl I have to add some Content to the WebApp like a layout with a table (in this table are some entries which change while executing the Application (measuring something). So the WebAppCtrl needs a attribute WebApp webApp = “the Object which is generated by connecting the server with a client”.

I hope you understood my Problem.
The question is: Is this possible? And how?
or What is a better way to reach this?

Sounds like broken design …

If the Server is started by your application, it is probably running in another thread than the rest of your application. Therefore there is either no UI-instance yet or it is bound to the server’s thread and therefore not accessible. You will have to use some other way to exchange the needed data, for example a database or XML.

I also thougt of a database before. So thanks for affirmation.
I designed it basically like i were using Swing.