Can't embed UI in JSP

Dear,

I am trying to embed Vaadin UI into my existed JSP pages. However, I failed to get it done, and I don’t know where I am wrong. Here are my codes:



web.xml:




RequestController
RequestController
com.mycompany.servlet.RequestController


MyUIServlet
com.mycompany.vaadin.MyUIServlet


RequestController
/rc/


MyUIServlet
/vaadin/




MyUIServlet.java:


public class MyUIServlet extends VaadinServlet {
@Override protected void servletInitialized() throws ServletException {
super.servletInitialized();
getService().addSessionInitListener( new SessionInitListener() {
@Override public void sessionInit( SessionInitEvent event ) throws ServiceException {
event.getSession().addUIProvider( new MyUIProvider() );
}
} );
}
}



MUIProvider.java:


public class MyUIProvider extends UIProvider {
@Override public Class< ? extends UI > getUIClass( UIClassSelectionEvent event ) {
return MyUI.class;
}
}



MyUI.java:


public class MyUI extends UI {
@Override public void init( VaadinRequest request ) {
final VerticalLayout layout = new VerticalLayout();
final TextField name = new TextField();
name.setCaption( “Type your name here:” );
Button button = new Button( “Click Me” );
button.addClickListener( new Button.ClickListener() {
public void buttonClick( Button.ClickEvent e ) {
layout.addComponent( new Label( "Thanks " + name.getValue() + “, it really works!” ) );
}
} );
layout.addComponents( new Component { name , button } );
layout.setMargin( true );
layout.setSpacing( true );
this.setContent( layout );
}
}



Test.jsp:


<%@ taglib uri=“/WEB-INF/tlds/vaadin.tld” prefix=“vaadin” %>

Index

Vaadin UI TEST

When I set the url: “/rc?command=file&file=Test.jsp”, the browser shows only “Vaadin UI TEST”, but no vaadin UI I expected. I am new to Vaadin development, adn sorry for such detailed elaboration. Please kindly advise where I might get wrong.

Many thanks,
Joey

Usually the path names are case sensitive here, so try this

MyUIServlet /VAADIN/*

And since your servlet-name is in web.xml “MyUIServlet”, your test.jsp should be as follows (note you can rename this what you want, does not need to be same as the class name)

Vaadin UI TEST

Many thanks to you advices. I can get the Vaadin UI displayed within my JSP. However, when I click the button, the page showed some error as attached file. Why does it say “Server connection lost…”? How should MyUI.java be modifiled to allow the button click event to work properly? Sorry for my beginner’s question.

Warm regards,
Joey
33601.png

Have you tried to replace <vaadin:ui url=“/MyUIServlet”/> with standard iframe . I do not know what your /WEB-INF/tlds/vaadin.tld does. It could interfere communication with multiple servlets.

It’s jsp integration add-on downloaded from Vaadin web. I also found that, if I create a VAADIN directory in the web content, everything works well. I don’t know why. Is that VAADIN directory essential to Vaadin web deployment? What if I want to change the directory name from VAADIN to, say WEB-VAADIN, how to configure that?

Many thanks,
Joey