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.

clientside-debugging.asciidoc 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. ---
  2. title: Debugging Client-Side Code
  3. order: 6
  4. layout: page
  5. ---
  6. [[clientside.debugging]]
  7. = Debugging Client-Side Code
  8. Vaadin currently includes SuperDevMode for debugging client-side code right in
  9. the browser.
  10. The predecessor of SuperDevMode, the GWT Development Mode, no longer works in
  11. recent versions of Firefox and Chrome, because of certain API changes in the
  12. browsers. There exists workarounds on some platforms, but for the sake of
  13. simplicity, we recommend using the SuperDevMode.
  14. ifdef::web[]
  15. [[clientside.debugging.devmode]]
  16. == Launching Development Mode
  17. The Development Mode launches the application in the browser, compiles the
  18. client-side module (or widget set) when the page is loaded, and allows debugging
  19. the client-side code in Eclipse. You can launch the Development Mode by running
  20. the [classname]#com.google.gwt.dev.DevMode# class. It requires some parameters,
  21. as described later.
  22. The Vaadin Plugin for Eclipse can create a launch configuration for the
  23. Development Mode. In the Vaadin section of project properties, click the
  24. [guibutton]#Create development mode launch# button. This creates a new launch
  25. configuration in the project. You can edit the launch configuration in "Run >
  26. Run Configurations".
  27. ----
  28. -noserver -war WebContent/VAADIN/widgetsets com.example.myproject.widgetset.MyWidgetSet -startupUrl http://localhost:8080/myproject -bindAddress 127.0.0.1
  29. ----
  30. The parameters are as follows:
  31. [parameter]#-noserver#:: Normally, the Development Mode launches its own Jetty server for hosting the content. If you are developing the application under an IDE that deploys it to a server, such as Eclipse, you can disable the Development Mode server with this option.
  32. [parameter]#-war#:: Specifies path to the location where the JavaScript is to be compiled. When developing a pure client-side module, this could be the [filename]#WebContent# (in Eclipse) or some other folder under it. When compiling widget sets, it must be [filename]#WebContent/VAADIN/widgetsets#.
  33. [parameter]#-startupUrl#:: Specifies the address of the loader page for the application. For server-side Vaadin applications, this should be the path to the Vaadin application servlet, as defined in the deployment. For pure client-side widgets, it should be the page where the application is included.
  34. [parameter]#-bindAddress#:: This is the IP address of the host in which the Development Mode runs. For debugging on the development workstation, it can be just [literal]#++127.0.0.1++#. Setting it as the proper IP address of the host enables remote debugging.
  35. endif::web[]
  36. [[clientside.debugging.superdevmode]]
  37. == Launching SuperDevMode
  38. The SuperDevMode is much like the old Development Mode, except that it does not
  39. require a browser plugin. Compilation from Java to JavaScript is done
  40. incrementally, reducing the compilation time significantly. It also allows
  41. debugging JavaScript and even Java right in the browser (currently only
  42. supported in Chrome).
  43. You can enable SuperDevMode as follows:
  44. . You need to set a redirect property in the [filename]#.gwt.xml# module
  45. descriptor as follows:
  46. +
  47. ----
  48. <set-configuration-property name="devModeRedirectEnabled" value="true" />
  49. ----
  50. +
  51. In addition, you need the [literal]#++xsiframe++# linker. It is included in the
  52. [classname]#com.vaadin.DefaultWidgetSet# as well as in the
  53. [classname]#com.vaadin.Vaadin# module. Otherwise, you need to include it with:
  54. +
  55. ----
  56. <add-linker name="xsiframe" />
  57. ----
  58. . Compile the module (that is, the widget set), for example by clicking the button in Eclipse.
  59. . If you are using Eclipse, create a launch configuration for the SuperDevMode by
  60. clicking the [guibutton]#Create SuperDevMode launch# in the [guilabel]#Vaadin#
  61. section of the project properties.
  62. .. The main class to execute should be [classname]#com.google.gwt.dev.codeserver.CodeServer#.
  63. .. The application takes the fully-qualified class name of the module (or widget set) as parameter, for example, [classname]#com.example.myproject.widgetset.MyprojectWidgetset#.
  64. .. Add project sources to the class path of the launch if they are not in the project class path.
  65. The above configuration only needs to be done once to enable the SuperDevMode.
  66. After that, you can launch the mode as follows:
  67. . Run the SuperDevMode Code Server with the launch configuration that you created above. This perfoms the initial compilation of your module or widget set.
  68. . Launch the servlet container for your application, for example, Tomcat.
  69. . Open your browser with the application URL and add [literal]#++?superdevmode++# parameter to the URL (see the notice below if you are not extending [classname]#DefaultWidgetSet#). This recompiles the code, after which the page is reloaded with the SuperDevMode. You can also use the [literal]#++?debug++# parameter and then click the [guibutton]#SDev# button in the debug console.
  70. If you make changes to the client-side code and refresh the page in the browser,
  71. the client-side is recompiled and you see the results immediately.
  72. The Step 3 above assumes that you extend [classname]#DefaultWidgetSet# in your
  73. module. If that is not the case, you need to add the following at the start of
  74. the [methodname]#onModuleLoad()# method of the module:
  75. ----
  76. if (SuperDevMode.enableBasedOnParameter()) { return; }
  77. ----
  78. Alternatively, you can use the bookmarklets provided by the code server. Go to
  79. http://localhost:9876/ and drag the bookmarklets " [guilabel]#Dev Mode On#" and
  80. " [guilabel]#Dev Mode Off#" to the bookmarks bar
  81. [[clientside.debugging.chrome]]
  82. == Debugging Java Code in Chrome
  83. Chrome supports source maps, which allow debugging Java source code from which
  84. the JavaScript was compiled.
  85. Open the Chrome Inspector by right-clicking and selecting [guilabel]#Inspect
  86. Element#. Click the settings icon in the upper right corner of the window and check
  87. the "Scripts > Enable source maps" option. Refresh the page with the Inspector
  88. open, and you will see Java code instead of JavaScript in the scripts tab.