Loading...
Important Notice - Forums is archived

To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Product icon
TUTORIAL

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.

Displaying Vaadin application/components in a JSP

Aladdin Özenir
1 decade ago Apr 15, 2010 7:59am

Hello,

I have a Web application based on the Struts2 framework and I am using JSPs for the view.
The test applications that I have created, to see what I can do using the Vaadin framework is great.
My test applications were standalone applications until now.

Now I need to integrate/display the components I have created in my existing JSPs. Does that work?

I experimented with the custom layouts, which works fine.
In that case, I had to use "html" files and integrate the Vaadin components using "<div location="component_id"></div>"
I have also tried it using the custom layout with the FileInputStream parameter and a JSP file, but it does not render the JSP. That means, the JSP file is loaded, but it's treated as a standard HTML file.

What I want to do is, I want do render my JSPs (so all the Struts2 and JSTL tags should work) and display the Vaadin applications components.

Is this possible somehow?
Or do I misundestand something with the technik/architecture?

Aladdin Özenir
1 decade ago Apr 20, 2010 10:30am

Hello again,

currently I'm thinking about my issue again.

I'm asking myself the questions and some of the answers:

  • Do I really need JSPs and dynamich content in these JSPs?
  • I think, we have to implement our functionality (that would be our Vaadin application) on the server, which is why we use Vaadin
  • My dynamic content is boundt to my components (ex. using Containers to tables, trees, ...etc), so the logic is running in the Vaadin application on the server... Automatically via AJAX, thanks to Vaadin!
  • This means, I do NOT need JSPs. It is sufficient for my custom layout file(s) to be html files, which only define "placeholders" for my components (which are data containers)

Is this the correct way of thinking?
Or, does anybody see the need for JSPs and dynamic content in them?

Dmitri Livotov
1 decade ago Apr 20, 2010 1:19pm

Aladdin, yes, you cannot run JSP login in custom layouts as well as cannot access Vaadin components from JSP tags, e.g. mix JSP and Vaadin. However, you can embed Vaadin apps into your JSP pages - this is done the same way as embedding Vaadin apps to HTML page, which is described in the Book of Vaadin.

But that is useful only if you do not want to drop your existing JSP app and enhance it with some Vaadin UI (in form of stand-alone small apps embedded).

Dmitri

Aladdin Özenir
1 decade ago Apr 21, 2010 12:37pm

Dmitri Livotov: But that is useful only if you do not want to drop your existing JSP app and enhance it with some Vaadin UI (in form of stand-alone small apps embedded).Dmitri

When I think about such small apps, I would embed these using IFrames. Is this the approach you prefer?
Or is there another way, how you would embed them?

Dmitri Livotov
1 decade ago Apr 21, 2010 12:39pm

You can also embed using <div> elements, however this restricts you for only one such app per page

Aladdin Özenir
1 decade ago Apr 21, 2010 12:49pm

Yes, using a div, I could embed one application.
I think, I want to embed severel small applications in one page. I will see, if I need that.

I also need to check, how I can make these different applications "speak" to eachother and share/send/receive data.
This also concerns the JSP page I think.

When I click a Link on the JSP page, it usually creates an AJAX-Request to the server and the response will be displayed in another part of the page (ex. in a div, no page-reload). Now this is all in the world of JSP.

What if I have my JSP page with this link and a Vaadin appliaction (or several ones)? When I click this link, it will create the AJAX-Request. The response will be displayed in the div (as usual) AND I want to send the response to my Vaadin application(s) as well.

Is this possible somehow? If yes, how?
If my scenario doesn't make any sense, tell me that as well ;)

Dmitri Livotov
1 decade ago Apr 21, 2010 1:01pm

Hmm, communicating between apps is an interesting thing :)

as what comes to my mind immideately is that action from jsp page can send a JMS message which could be then received by a listeners (vaadin apps) and vice-verca - this, of ocurse, is true when you use JEE on server side.

I think, something similar could be arranged by using a singleton (for a webapp) class and it's own message (event) queue.

Aladdin Özenir
1 decade ago Apr 21, 2010 1:22pm

This sounds interesting, and challenging.
It's always good to have some ideas and different approaches to problems, doesn't matter if they are easy or difficult.

Maybe I can give that a try sometime. :)

Joonas Lehtinen
1 decade ago Apr 21, 2010 1:32pm

Dmitri Livotov: You can also embed using <div> elements, however this restricts you for only one such app per page

Actually - you can use multiple Vaadin applications per page as long as they share common theme and widgetset.

Joonas Lehtinen
1 decade ago Apr 21, 2010 1:38pm

Aladdin Özenir: I also need to check, how I can make these different applications "speak" to eachother and share/send/receive data. This also concerns the JSP page I think.

If all the JSP:s and Vaadin applications are part of one web application (in same WAR), you can communicate directly on the server-side by calling methods. See http://vaadin.com/api/com/vaadin/terminal/gwt/server/WebApplicationContext.html#getApplicationContext(javax.servlet.http.HttpSession) as a starting point for getting application reference.

Aladdin Özenir
1 decade ago Apr 21, 2010 1:38pm

Joonas Lehtinen: Actually - you can use multiple Vaadin applications per page as long as they share common theme and widgetset.

Do you mean, by defining as many servlets as the number of applications and by configuring one different servlet-mapping for each application?

Joonas Lehtinen
1 decade ago Apr 21, 2010 1:48pm

Aladdin Özenir:

Joonas Lehtinen: Actually - you can use multiple Vaadin applications per page as long as they share common theme and widgetset.

Do you mean, by defining as many servlets as the number of applications and by configuring one different servlet-mapping for each application?

yes.

Dmitri Livotov
1 decade ago Apr 21, 2010 2:29pm

Joonas Lehtinen: If all the JSP:s and Vaadin applications are part of one web application (in same WAR), you can communicate directly on the server-side by calling methods. See http://vaadin.com/api/com/vaadin/terminal/gwt/server/WebApplicationContext.html#getApplicationContext(javax.servlet.http.HttpSession) as a starting point for getting application reference.

wow, did not think about this possibility ! :)

Jouni Koivuviita
1 decade ago Apr 22, 2010 8:11am

And remember that there's also the native JS API that you can use if you need to sync data to the client after some JSP Ajax-call:

javascript: vaadin.forceSync();

Don't know what it does with multiple application instances, though. I guess they all should get synced.

Aladdin Özenir
1 decade ago Apr 22, 2010 8:22am

Loading a Vaadin application into an IFrame works fine. And it looks great. :)

However, using a div and loading the Vaadin application into that div, does not work.
All I get is a blank page. When I look at the page source of that blank page, it's all there. (The sourcode of my JSP-Application)
I have also analyzed it using the FireBug plugin.

To achieve what I wanted, I did the following:
- Create a div
- Create a Link (<a>)
- Registered an onClick() to this Link and call a jQuery fuction
- Using jQuery, load the Vaadin application into the div
So, it's all JavaScript functionality and a Http-Get to load the Vaadin application
PS: To make sure that the jQuery JavaScript is working, I've loaded static content and also one of my JSPs into this div. Works fine.

Now, when I click the link, FireBug shows that the Vaadin application is loading.
On the FireBug Console, I see some errors:
- "vaadin is not defined" and
- "l.body is null"
And the Network says, it has made a JavaScript GET request to:
http://host:port/ctx/VAADIN/widgetsets/com.vaadin.terminal.gwt.DefaultWidgetSet/com.vaadin.terminal.gwt.DefaultWidgetSet.nocache.js?1271923582234
(PS: I have changed the real URI to "host:port/ctx")

The question is, did I do something wrong, or does the loading into a div not work.

PS: This is just an information.
As I can use Vaadin applications in IFrames, everything is OK for me ;)