Skip to content

Commit 6e9eb1c

Browse files
authored
Merge branch 'latest' into docs/replace-hilla-nonnull-usages
2 parents a5d73c1 + 3a6f188 commit 6e9eb1c

File tree

12 files changed

+438
-265
lines changed

12 files changed

+438
-265
lines changed

articles/building-apps/cookbook.adoc

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
title: Cookbook
3+
page-title: Vaadin Cookbook | Code snippets for common tasks
4+
description: Code snippets for common tasks
5+
meta-description: A collection of solutions to common use cases you run into when developing business web applications with Vaadin.
6+
order: 50
7+
---
8+
9+
10+
= Vaadin Cookbook
11+
12+
[IMPORTANT]
13+
Some solutions in this cookbook may not follow the latest best practices.
14+
15+
The https://cookbook.vaadin.com/[Vaadin Cookbook] is a collection of solutions for common challenges in business web application development with Vaadin.
16+
17+
Solutions are implemented using Java, TypeScript, or a combination of both, depending on what's most suitable. The emphasis is on solving the problem, rather than the implementation details.
18+
19+
https://cookbook.vaadin.com/[Open Cookbook, role="button primary water"]

articles/hilla/guides/uploads-downloads.adoc

+33-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,42 @@
11
---
2-
title: File Downloading
3-
page-title: How to implement file downloading in Hilla React applications | Vaadin
4-
description: How to implement file downloading in Hilla React applications.
5-
meta-description: Learn how to implement file downloading in Vaadin Hilla.
2+
title: Uploading pass:[&] Downloading
3+
page-title: How to implement file uploading and downloading in Hilla React applications | Vaadin
4+
description: How to implement file uploading and downloading in Hilla React applications.
5+
meta-description: Learn how to implement file uploading and downloading in Vaadin Hilla.
66
order: 73
77
---
88

99

10-
# Downloading Files
10+
= Uploading & Downloading Files
1111

12-
Hilla endpoints only respond to POST requests and don't support file downloads. Since Hilla applications use Spring, though, you can leverage Spring's capabilities to implement file downloading.
12+
Transferring files between the client and server is a common requirement in web applications. This page demonstrates how to implement file uploading and downloading in Hilla React applications.
13+
14+
15+
[role="since:com.vaadin:[email protected]"]
16+
== Uploading Files
17+
18+
Hilla supports the https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/multipart/MultipartFile.html[MultipartFile] class from Spring to handle file uploads. It maps to the standard https://developer.mozilla.org/en-US/docs/Web/API/File[File] interface in the generated TypeScript code.
19+
20+
The following example demonstrates how to implement such a service and connect it to the <</components/upload#,Upload>> component in a view:
21+
22+
[.example]
23+
--
24+
[source,tsx]
25+
.`upload.tsx`
26+
----
27+
include::{root}/frontend/demo/fusion/forms/upload/upload.tsx[tags=snippet,indent=0]
28+
----
29+
[source,java]
30+
.`UploadService.java`
31+
----
32+
include::{root}/src/main/java/com/vaadin/demo/fusion/upload/UploadService.java[tags=snippet,indent=0]
33+
----
34+
--
35+
36+
37+
== Downloading Files
38+
39+
Hilla endpoints only respond to `POST` requests and don't support file downloads. Since Hilla applications use Spring, though, you can leverage Spring's capabilities to implement file downloading.
1340

1441
Select the server mapping that best suits your application. Then create an ad-hoc endpoint to handle file downloads.
1542

articles/hilla/lit/guides/endpoints.adoc

+25
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,31 @@ When a request is cancelled programmatically, the endpoint call promise resolves
417417
endif::[]
418418

419419

420+
== Request Options
421+
422+
All regular Hilla requests support some options as the last parameter. They're listed in the sections here.
423+
424+
425+
=== Abort Signal
426+
427+
You can pass an https://developer.mozilla.org/en-US/docs/Web/API/AbortController/signal[AbortSignal] object to the call to cancel a request. This is useful when you want to cancel a request, perhaps because you've decide you don't need it after all or because it's taking too long.
428+
429+
[source,typescript]
430+
----
431+
include::{root}{root-fix}/frontend/demo/fusion/options/request-options.ts[tag=abort,indent=0]
432+
----
433+
434+
435+
=== Suppress Connection State
436+
437+
By default, when a request takes too long, Hilla shows a progress bar to the user at the top of the page. You can suppress this by setting the `mute` option to `true`.
438+
439+
[source,typescript]
440+
----
441+
include::{root}{root-fix}/frontend/demo/fusion/options/request-options.ts[tag=mute,indent=0]
442+
----
443+
444+
420445
== Code Completion in IDEs
421446

422447
As you can see in the earlier [filename]`CounterEndpoint.ts` example, the Javadoc for the `@Endpoint` class is copied to the generated TypeScript file, and the type definitions are maintained. This helps code completion to work -- at least in Visual Studio Code and IntelliJ IDEA Ultimate Edition.

articles/tools/designer/getting-started/build-your-contact-form.adoc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Build Contact Form
3-
page-title: How to use build a contact form with Vaadin Designer
3+
page-title: How to build a contact form with Vaadin Designer
44
meta-description: Learn how to build a contact form with Vaadin Designer. Follow this step-by-step guide to create visually stunning UIs with ease.
55
order: 7
66
---
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import {
2+
Notification,
3+
Upload,
4+
type UploadElement,
5+
type UploadRequestEvent,
6+
} from '@vaadin/react-components';
7+
import { UploadService } from 'Frontend/generated/endpoints';
8+
9+
export default function UploadView() {
10+
// tag::snippet[]
11+
const handleUploadRequest = async (e: UploadRequestEvent) => {
12+
e.preventDefault();
13+
14+
const uploadRef = e.target as UploadElement;
15+
16+
const fileId = await UploadService.uploadFile(e.detail.file);
17+
uploadRef.files = uploadRef.files.map((file) => {
18+
file.status = '';
19+
file.complete = true;
20+
return file;
21+
});
22+
23+
Notification.show(`Received file: ${fileId}`);
24+
};
25+
26+
return <Upload maxFiles={1} onUploadRequest={handleUploadRequest} />;
27+
// end::snippet[]
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { SlowService } from 'Frontend/generated/endpoints';
2+
3+
export function abortCall() {
4+
// tag::abort[]
5+
const controller = new AbortController();
6+
7+
SlowService.takesTime({ signal: controller.signal }).then((msg) => console.log(msg));
8+
9+
// The `AbortController` can be used to abort the request, for example after a timeout
10+
// or an user action like a button click
11+
const timeoutId = setTimeout(() => {
12+
controller.abort();
13+
}, 5000);
14+
// end::abort[]
15+
16+
return () => clearTimeout(timeoutId);
17+
}
18+
19+
export function muteCall() {
20+
// tag::mute[]
21+
SlowService.takesTime({ mute: true }).then((msg) => console.log(msg));
22+
// end::mute[]
23+
}

0 commit comments

Comments
 (0)