Basil Bourque
Basil Bourque

Reputation: 339332

What are "actions" in Vaadin 14?

In Vaadin 14, while looking at the Login component, specifically the source code for AbstractLogin.java, I noticed:

I understand making an object of mine a listener for LoginEvent by registering with the login widget via AbstractLogin::addLoginListener.

But this “action” seems to be an alternative way to work instead of event listeners.

Can someone tell me more about actions and how they work in Vaadin Flow?

I searched the Vaadin Docs for the word action but found nothing there.

Upvotes: 2

Views: 347

Answers (2)

Archie
Archie

Reputation: 5421

Love how they give you almost zero information. There should at least be a few breadcrumbs on the LoginForm page.

The phrase "action" here has nothing to do with Java events. Instead, it refers to the "action" attribute of the HTML <form> tag, i.e., where the browser should POST the form data.

Review how Spring Security's Form Login works here. It's default URI path for posting the username and password is /login. That's why setAction("login") works.

Upvotes: 1

Tatu Lund
Tatu Lund

Reputation: 10643

The HTML API of the LoginForm specifies the following

action: string | null | undefined= null notify

If set, a synchronous POST call will be fired to the path defined. The login event is also dispatched, so event.preventDefault() can be called to prevent the POST call.

I understand that, with this option you can configure the login form to post the data login processing or e.g. to external authentication service. Useful use case is to set it "login" when using Vaadin with Spring security. This case is shown in Bakery App Starter.

Upvotes: 2

Related Questions