Hi Weijan,
In Portofino 4, the frontend and backend parts of the application live in the same webapp, so you can use @Button.
In Portofino 5, this is not the case; frontend and backend are two separate applications that can be deployed together, but use different technologies. This has some advantages, because you can now replace the frontend with another one (e.g. using React, or a native app on mobile, etc.), however it also means that adding a button is a bit more complicated.
First, you have to add a REST method to the action class defined action.groovy, as you did in P4 with @Button, but using JAX-RS instead of Stripes MVC. You don't have to use @Button anymore, Portofino will discover the method automatically. Once you have the method, you have to invoke it from the UI, with a custom button.
The "right" way to add a button to the UI is to build your web application from source using Maven, and modify and rebuild the Angular application that lives in src/main/frontend. However, unless you already have such a setup and already know some Angular, that requires a long learning curve.
page.customButtonAction = function () {
page.http.get(...);
};
That requires you to learn and use the HTTP client (and RxJS as a consequence) which may look intimidating; on the bright side, it already handles authentication automatically, so it will send the authentication token for each request and will prompt for a username and password if the session is expired. It's also already integrated with the application's notification system, so in case of an error the user will be notified.
Last but not least, since your objective is to have the user download a file, and the request happens over AJAX, you'll have to take extra steps to make the browser download the response as a file. There are solutions on Stack Overflow using a blob for example. You'll have to do your own research.
I know this all sounds more complicated than it should, but today's web technologies are like that, and Portofino can only do so much.
Cheers,
Alessio