You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

portal-ui.asciidoc 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. ---
  2. title: Portlet UI
  3. order: 2
  4. layout: page
  5. ---
  6. [[portal.ui]]
  7. = Portlet UI
  8. A portlet UI is just like in a regular Vaadin application, a class that extends
  9. [classname]#com.vaadin.ui.UI#.
  10. [source, java]
  11. ----
  12. @Theme("myportlet")
  13. public class MyportletUI extends UI {
  14. @Override
  15. protected void init(VaadinRequest request) {
  16. final VerticalLayout layout = new VerticalLayout();
  17. layout.setMargin(true);
  18. setContent(layout);
  19. Button button = new Button("Click Me");
  20. button.addClickListener(new Button.ClickListener() {
  21. public void buttonClick(ClickEvent event) {
  22. layout.addComponent(
  23. new Label("Thank you for clicking"));
  24. }
  25. });
  26. layout.addComponent(button);
  27. }
  28. }
  29. ----
  30. For OSGi portlets in Liferay 7, use additional annotations as described in
  31. <<portal-osgi#portal.osgi,"OSGi Portlets on Liferay 7">>.
  32. The portlet theme is defined with the [classname]#@Theme# annotation as usual.
  33. The theme for the UI must match a theme installed in the portal. You can use any
  34. of the built-in themes in Vaadin. If you use a custom theme, you need to
  35. compile it to CSS with the theme compiler and install it in the portal under the
  36. [filename]#VAADIN/themes# context to be served statically, or use the OSGi
  37. portlet mechanisms to publish the theme.
  38. In addition to the UI class, you need the portlet descriptor files, Vaadin
  39. libraries, and other files as described later.
  40. <<figure.portal.helloworld.project>> shows a complete project structure under
  41. Eclipse.
  42. [[figure.portal.helloworld.project]]
  43. .Portlet Project Structure in Eclipse
  44. image::img/liferay-project.png[]
  45. Installed as a portlet in Liferay from the [guilabel]#Add Application# menu, the
  46. application will show as illustrated in <<figure.portal.helloworld>>.
  47. [[figure.portal.helloworld]]
  48. .Hello World Portlet
  49. image::img/liferay-helloworld.png[]
  50. [[portal.ui.servlet]]
  51. == Testing Portlet UIs as Servlets
  52. If a portlet does not use any specific portlet APIs, deploying it as a servlet
  53. can make testing it easier than deploying it to a portal.
  54. If you created the project as a Servlet 3.0 project, the generated UI stub
  55. includes a static servlet class annotated with [classname]#@WebServlet#, as
  56. described in
  57. <<../getting-started/getting-started-first-project#getting-started.first-project.exploring,"Exploring
  58. the Project">>.
  59. Otherwise, the following snippet can be used.
  60. [source, java]
  61. ----
  62. @WebServlet(value = "/*", asyncSupported = true)
  63. @VaadinServletConfiguration(productionMode = false,
  64. ui = MyportletUI.class)
  65. public static class Servlet extends VaadinServlet {
  66. }
  67. ----