You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/getting-started/quick-start/index.adoc
+50-62Lines changed: 50 additions & 62 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -60,28 +60,17 @@ public class MainView extends VerticalLayout { // <3>
60
60
61
61
== Run the Application
62
62
63
-
You can run the application <<../dev-environment/run#,directly from your IDE>> or from the command line. To run it from the command line, open a terminal in the project directory and run the following command:
63
+
To get the best development experience, run your application from your IDE with *hotswap* enabled. Hotswap automatically applies your code changes to the running application without restarting it, which saves a lot of time during this tutorial.
64
64
65
-
[.example]
66
-
--
67
-
.Terminal
68
-
[source,terminal,subs="+attributes"]
69
-
----
70
-
<source-info group="macOS / Linux"></source-info>
71
-
./mvnw
72
-
----
65
+
To enable hotswap, install the *Vaadin plugin* for your IDE and use it to start the application. You can find IDE-specific instructions here:
* <<../dev-environment/run/vscode#,Visual Studio Code>>
69
+
* <<../dev-environment/run/eclipse#,Eclipse IDE>>
70
+
* <<../dev-environment/run/netbeans#,NetBeans>>
81
71
82
-
.Command Line Limitations
83
-
[TIP]
84
-
When you run the project from the command line, you have to restart the application every time you make a change to the code. If you run the application <<../dev-environment/run#,from your IDE>> you can use *hot swapping*, which automatically applies changes to your running application without restarting.
72
+
[IMPORTANT]
73
+
Even if you are already familiar with your IDE, follow the instructions above. Running the application with hotswap requires the *Vaadin plugin*, which you may not have installed yet.
85
74
86
75
The first startup may take a while as Maven and npm download the required dependencies.
87
76
@@ -96,7 +85,7 @@ It should look like this:
96
85
[.device]
97
86
image::images/first-view.png[The first Vaadin view displaying a greeting message]
98
87
99
-
The [guilabel]*}>* button in the bottom-right corner is the *Copilot menu*, which is visible when running in development mode. You'll learn more about it later.
88
+
The toolbar in the bottom-right corner is the *Copilot toolbar*, which is visible when running in development mode. See the <</tools/copilot#,Copilot documentation>> for details.
<1> This line creates a new Button with the label "Say Hello". When clicked, it triggers a lambda function that adds a new `Span` with the message "Hello, Vaadin!" to the view. A span corresponds to the HTML `<span>` element, which is an inline container for text.
122
+
<1> This line creates a new Button with the label "Say Hello". When clicked, it triggers a lambda function that adds a new `Paragraph` with the message "Hello, Vaadin!" to the view.
134
123
135
124
This programming model is typical for Vaadin applications. You construct the UI from components, and define behavior using event listeners. If you have used Swing or JavaFX before, this should feel familiar.
136
125
137
-
If you started the application from your IDE with <<../dev-environment/run#,hotswap (automatic code reload) enabled>>, the changes should be reflected automatically. If not, restart the application and refresh the browser. Click the button to see what happens:
126
+
If you set up hotswap as instructed earlier, the changes are applied automatically. Just switch to the browser and click the button to see what happens:
138
127
139
128
[.device]
140
129
image::images/second-view.png[The updated Vaadin view with a button and a text span]
141
130
142
-
The text is added to the end of the view, below the button. If you click multiple times, new texts are added each time.
131
+
The paragraph is added to the end of the view, below the button. If you click multiple times, new paragraphs are added each time.
<1> Creates a `TextField` component with a label prompting the user for their name.
182
-
<2> Adds a new `Span` with a personalized greeting message to the view.
171
+
<2> Adds a new `Paragraph` with a personalized greeting message to the view.
183
172
184
173
Now the browser view should look like this:
185
174
@@ -195,7 +184,7 @@ Vaadin takes care of input sanitization and escaping to prevent security vulnera
195
184
196
185
== Update a Component
197
186
198
-
The problem with the current implementation is that each time you click the button, a new text is added. Instead, you want to add a single `Span` and update its content on every click. Modify the `MainView` class as follows:
187
+
The problem with the current implementation is that each time you click the button, a new paragraph is added. Instead, you want to add a single `Paragraph` and update its content on every click. Modify the `MainView` class as follows:
@@ -218,7 +207,7 @@ public class MainView extends VerticalLayout {
218
207
var nameField = new TextField("What is your name?");
219
208
add(nameField);
220
209
// tag::snippet[]
221
-
var greeting = new Span(); // <1>
210
+
var greeting = new Paragraph(); // <1>
222
211
add(greeting);
223
212
// end::snippet[]
224
213
add(new Button("Say Hello", event ->
@@ -229,15 +218,15 @@ public class MainView extends VerticalLayout {
229
218
}
230
219
}
231
220
----
232
-
<1> Creates a `Span` component to hold the greeting message and adds it to the view above the button.
233
-
<2> Updates the text of the existing `Span` instead of adding a new one.
221
+
<1> Creates a `Paragraph` component to hold the greeting message and adds it to the view above the button.
222
+
<2> Updates the text of the existing `Paragraph` instead of adding a new one.
234
223
235
224
If you now try the application again, you'll see that there is some extra space between the text field and the button:
236
225
237
226
[.device]
238
227
image::images/fourth-view.png[The Vaadin view with a button to generate a QR code]
239
228
240
-
This is because the `Span` component is initially empty but still occupies space in the layout. You can fix that by hiding the `Span` when it has no content. Update the code as follows:
229
+
This is because the `Paragraph` component is initially empty but still occupies space in the layout. You can fix that by hiding the `Paragraph` when it has no content. Update the code as follows:
@@ -259,7 +248,7 @@ public class MainView extends VerticalLayout {
259
248
add(new H1("Hello, Vaadin!"));
260
249
var nameField = new TextField("What is your name?");
261
250
add(nameField);
262
-
var greeting = new Span();
251
+
var greeting = new Paragraph();
263
252
// tag::snippet[]
264
253
greeting.setVisible(false); // <1>
265
254
// end::snippet[]
@@ -273,8 +262,8 @@ public class MainView extends VerticalLayout {
273
262
}
274
263
}
275
264
----
276
-
<1> Hides the `Span` component initially since it has no content.
277
-
<2> Sets the visibility of the `Span` based on whether the `TextField` is empty or not.
265
+
<1> Hides the `Paragraph` component initially since it has no content.
266
+
<2> Sets the visibility of the `Paragraph` based on whether the `TextField` is empty or not. By default, a text field is empty if its value is an empty string.
278
267
279
268
If you now enter your name and click the button, you'll see that the greeting message updates in place each time you click the button. If you clear the text field and click the button, the greeting message disappears and no extra space is occupied.
@@ -361,39 +356,32 @@ public class MainView extends VerticalLayout {
361
356
// end::snippet[]
362
357
}
363
358
----
364
-
<1> The image source can be either a URL or a `DownloadHandler`. Vaadin serves server-generated content using the `DownloadHandler` interface.
365
-
<2> The QR code is generated and written to the output stream as a PNG image.
359
+
<1> Sets an error message on the text field and marks it as invalid, which displays the error to the user.
360
+
<2> The image source can be either a URL or a `DownloadHandler`. Vaadin serves server-generated content using the `DownloadHandler` interface.
361
+
<3> The QR code is generated and written to the output stream as a PNG image.
366
362
367
-
Because you have added new dependencies to the project, you have to restart the application for the changes to take effect. After restarting, enter a name and click the [guibutton]*Generate QR Code* button. A QR code representing the entered name will be displayed below the button:
363
+
Because you have added new dependencies to the project, you have to stop and restart the application from your IDE for the changes to take effect. After restarting, enter a name and click the [guibutton]*Generate QR Code* button. A QR code representing the entered name is displayed below the button:
368
364
369
365
[.device]
370
366
image::images/fifth-view.png[The Vaadin view with a button to generate a QR code]
371
367
368
+
If you click the button with an empty text field, an error message is shown instead.
369
+
372
370
Having access to the entire Java ecosystem allows you to leverage existing libraries and tools in your Vaadin applications, making development faster and easier.
373
371
374
372
375
373
== Make a Production Build
376
374
377
375
Up to this point, you have been running the application in development mode, which is optimized for fast feedback during development. Before deploying your application to production, you should create a production build that is optimized for performance.
378
376
379
-
Execute the Maven `package` goal to create a production build. You can do it from the command line like this:
377
+
Execute the Maven `package` goal to create a production build. Stop the application in your IDE, then run the following command from the project directory:
380
378
381
-
[.example]
382
-
--
383
-
.Terminal
384
-
[source,bash,subs="+attributes"]
379
+
[source,terminal]
385
380
----
386
-
<source-info group="macOS / Linux"></source-info>
387
-
./mvnw clean package
381
+
mvn clean package
388
382
----
389
383
390
-
.PowerShell
391
-
[source,powershell,subs="+attributes"]
392
-
----
393
-
<source-info group="Windows"></source-info>
394
-
mvnw clean package
395
-
----
396
-
--
384
+
TIP: If you don't have Maven installed, you can use the Maven Wrapper included in the project instead: `./mvnw clean package`.
397
385
398
386
After the build completes, check the `target` directory in your project. You should find a JAR file named `app-1.0-SNAPSHOT.jar` (assuming your project is named `app`).
399
387
You can run the production build using the following command:
@@ -404,7 +392,7 @@ You can run the production build using the following command:
404
392
java -jar target/app-1.0-SNAPSHOT.jar
405
393
----
406
394
407
-
Open your browser and navigate to http://localhost:8080 to see your application running in production mode. You'll notice that the [guilabel]*}>* button is no longer visible.
395
+
Open your browser and navigate to http://localhost:8080 to see your application running in production mode. You'll notice that the Copilot toolbar is no longer visible.
0 commit comments