Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

CreatingABasicApplication.asciidoc 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. ---
  2. title: Creating A Basic Application
  3. order: 10
  4. layout: page
  5. ---
  6. [[creating-a-basic-application]]
  7. = Creating a basic application
  8. To create a Vaadin application you need two files. A class that extends
  9. UI which is your main view and entry point to the application as well as
  10. a web.xml referring to the UI.
  11. With Eclipse and the Vaadin plugin you will get all of this
  12. automatically by opening the New wizard (File -> New -> Other) and
  13. choosing Vaadin -> Vaadin Project. From there you can give the new
  14. project a name and the wizard takes care of the rest.
  15. In other environments you can create the standard java web application
  16. project. Create one file which extends UI into the source folder. Let's
  17. call it MyApplicationUI:
  18. [source,java]
  19. ....
  20. package com.example.myexampleproject;
  21. import com.vaadin.server.VaadinRequest;
  22. import com.vaadin.ui.UI;
  23. import com.vaadin.ui.VerticalLayout;
  24. import com.vaadin.ui.Label;
  25. public class MyApplicationUI extends UI {
  26. @Override
  27. protected void init(VaadinRequest request) {
  28. VerticalLayout view = new VerticalLayout();
  29. view.addComponent(new Label("Hello Vaadin!"));
  30. setContent(view);
  31. }
  32. }
  33. ....
  34. This application creates a new main layout to the UI and adds the text
  35. "Hello Vaadin!" into it.
  36. Your web deployment descriptor, web.xml, has to point at your UI as
  37. well. This is done with an defining a Vaadin servlet and giving the UI
  38. as a parameter to it:
  39. [source,xml]
  40. ....
  41. <?xml version="1.0" encoding="UTF-8"?>
  42. <web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
  43. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  44. xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
  45. <display-name>MyApplication</display-name>
  46. <context-param>
  47. <description>Vaadin production mode</description>
  48. <param-name>productionMode</param-name>
  49. <param-value>false</param-value>
  50. </context-param>
  51. <servlet>
  52. <servlet-name>My Vaadin App</servlet-name>
  53. <servlet-class>com.vaadin.server.VaadinServlet</servlet-class>
  54. <init-param>
  55. <description>Vaadin UI</description>
  56. <param-name>UI</param-name>
  57. <param-value>com.example.myexampleproject.MyApplicationUI</param-value>
  58. </init-param>
  59. </servlet>
  60. <servlet-mapping>
  61. <servlet-name>My Vaadin App</servlet-name>
  62. <url-pattern>/*</url-pattern>
  63. </servlet-mapping>
  64. </web-app>
  65. ....
  66. Now you're able to package your application into a war and deploy it on
  67. a servlet container.