Showing posts with label web framework. Show all posts
Showing posts with label web framework. Show all posts

Sunday, 7 July 2024

Upgrading to Angular 18

Upgrading Javascript things is always a chore.

That's why these blogposts keep appearing.

% ng version

     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/


Angular CLI: 16.2.5
Node: 18.16.1
Package Manager: npm 9.7.2
OS: darwin x64

Angular: 16.2.8
... animations, common, compiler, compiler-cli, core, forms
... localize, platform-browser, platform-browser-dynamic, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1602.5
@angular-devkit/build-angular   16.2.5
@angular-devkit/core            16.2.5
@angular-devkit/schematics      16.2.5
@angular/cli                    16.2.5
@schematics/angular             16.2.5
rxjs                            7.5.7
typescript                      4.9.5
zone.js                         0.13.1

So I've used the tool in [2] to check my dependency requirements but there's also [1] if you're interested.

Upgrading node.js

cd ~
rm nodejs
tar zxvf ~/Downloads/node-v20.15.0-darwin-arm64.tar.gz
ln -s node-v20.15.0-darwin-arm64 nodejs

Upgrading typescript

Upgrading typescript using "npm install -g typescript@latest".

Upgrading zone.js

I'm hoping Angular does this for me.

Upgrading Angular

For my "personal" project.

npm install -g @angular/cli@18

ng update @angular/core@17 @angular/cli@17

ng update @angular/core@18 @angular/cli@18 @ng-bootstrap/ng-bootstrap@17 ngx-cookie-service@18

For my "admin" project, the thing below only worked after upgrading cdk and material to 17.

ng update @angular/core@18 @angular/cli@18 @ng-bootstrap/ng-bootstrap@17 ngx-cookie-service@18 @angular/cdk@18 @angular/material@18

Upgrading dependencies

ng update bootstrap bootswatch material-icons

My dependencies for "personal" project

@kolkov/angular-editor
the editor I use in my webapps
@ng-bootstrap/ng-bootstrap
integration between angular and bootstrap
@popperjs/core
this is used for tooltips by ng-bootstrap
bootstrap
bootstrap, is awesome
bootswatch
free themes for bootstrap, I like/use "cyborg" as a darkmode theme.
material-icons
latest icon fonts and CSS for self-hosting material design icons.
ngx-cookie-service
Angular service to read, set and delete browser cookies.
ng update @angular/cdk@16 @angular/material@16
ng update @angular/cdk@17 @angular/material@17

My dependencies for "admin" project

@angular/material
for creating of a virtual scroller
@angular/cdk
for creation of a virtual scroller
@ng-bootstrap/ng-bootstrap
integration between angular and bootstrap
@popperjs/core
this is used for tooltips by ng-bootstrap
bootstrap
bootstrap, is awesome
bootswatch
free themes for bootstrap, I like/use "cyborg" as a darkmode theme.
material-icons
latest icon fonts and CSS for self-hosting material design icons.
ngx-cookie-service
Angular service to read, set and delete browser cookies.

Things I noticed

Migrate application projects to the new build system.
You can read more about this, including known issues and limitations, here: https://angular.dev/tools/cli/build-system-migration The output location of the browser build has been updated from "../webapp" to "../webapp/browser". You might need to adjust your deployment pipeline or, as an alternative, set outputPath.browser to "" in order to maintain the previous functionality.
Replace deprecated HTTP related modules with provider functions.
HttpClientModule replaced with provideHttpClient, withInterceptorsFromDi

Error messages when upgrading

Package "@ng-bootstrap/ng-bootstrap" has an incompatible peer dependency to "@angular/common" (requires "^16.0.0" (extended), would install "18.0.6").
[WARNING] Polyfill for "@angular/localize/init" was added automatically. [plugin angular-polyfills]

  In the future, this functionality will be removed. Please add this polyfill in the "polyfills" section of your "angular.json" instead.

I found the answer to this one in [3] on StackOverflow.

[WARNING] Unable to locate stylesheet: /assets/css/bootstrap.min.css
[WARNING] Unable to locate stylesheet: /assets/css/karchan.css

Replaced this with a ThemeService (which is nice) which I found at [4].

And removed the hardcoded stylesheets in index.html. These are now added by the ThemeService.

Final result

% ng version

     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/


Angular CLI: 18.0.7
Node: 20.15.0
Package Manager: npm 10.8.1
OS: darwin arm64

Angular: 18.0.6
... animations, cdk, common, compiler, compiler-cli, core, forms
... localize, material, platform-browser
... platform-browser-dynamic, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1800.7
@angular-devkit/build-angular   18.0.7
@angular-devkit/core            18.0.7
@angular-devkit/schematics      18.0.7
@angular/cli                    18.0.7
@schematics/angular             18.0.7
rxjs                            7.5.7
typescript                      5.4.5
zone.js                         0.14.7

Small note

I am using the assets to store a normal bootstrap (bootstrap.min.css) and a darkmode bootstrap (bootstrap.darkmode.min.css).

These come from respectively node_modules/bootstrap/dist/css/bootstrap.min.css and node_modules/bootswatch/dist/cyborg/bootstrap.min.css.

References

[1] TechiDiaries - Upgrade to Angular 18
https://www.techiediaries.com/upgrade-angular-to-v18/
[2] Official Angular Updater Tool on the Web
https://update.angular.io/
[3] StackOverflow - Angular 18 Polyfills warning
https://stackoverflow.com/questions/78636168/angular-18-polyfills-warning
[4] Medium - Theme Switcher in Angular: From Dark to Light and Back Again
https://medium.com/@davdifr/theme-switcher-in-angular-from-dark-to-light-and-back-again-f42fc3f9fab0

Thursday, 7 January 2016

Vaadin 7

Vaadin1 is an open source framework for developing web applications2 running in your browser. What is interesting is that it uses Java to do it.

It feels like you're programming like Swing in Java, but the results are transferred to your webbrowser using Vaadin. Vaadin is able to do this with the help of the Google Web Toolkit3.

Vaadin can apparently be run on the Google App Engine, if you like.

Vaadin 7 supports the JSR-286 Portlet specification. Several portals are supported. Vaadin also has some deeper integration with Liferay Portal11, in which I am very interested, as it is the one that my website is running on.

I did find a youtube video12 that introduces Vaadin in combination with JEE and NetBeans.

Upgrading to Vaadin 7

One of the problems I encountered, when using Vaadin 74 is that most of the resources available are still referring to Vaadin 6. It is important to notice the differences.

The points in [4] that have been most relevant to me are:
  • com.vaadin.Application class no longer exists. The main entry point to your application is now a com.vaadin.ui.UI, which replaces Application and its main window.
  • Also com.vaadin.terminal.gwt.server.ApplicationServlet has been replaced with com.vaadin.server.VaadinServlet in web.xml and its parameter "application" with "UI" pointing to your UI class, and the application is ready to go. Of course you can use annotations, if you prefer.

Testing

As it is Java, I should have no problem Stubbing the Vaadin framework and junit-testing my code. This to me is a big bonus.

Persistence

Persistence in Vaadin is possible by using the JPAContainer5.

JEE and CDI

I use the Servlet to inject a lot of things I need, and then provide those injected things to my UI. Works flawlessly6.

JEE and JPA together in Vaadin

I found helpful information on how to create a EjbEntityProvider here at [7]. That I can use as a base class for EJBBeans that I can inject in my Servlet and henceforth use in my UI for the JPAContainer.

A full downloadable example is available at [8].

Debugging

I have not had to debug anything, everything just works. But, for those interested, you can find it at [9].

FAQ

I get a "Failed to load the bootstrap javascript: ./VAADIN/vaadinBootstrap.js?v=7.5.5"
See [10]. Extend the @WebServlet annotation withe more than one urlPattern. See the example above.

References

[1] Vaadin
https://vaadin.com/home
[2] Wikipedia - Vaadin
https://en.wikipedia.org/wiki/Vaadin
[3] Google Web Toolkit
http://www.gwtproject.org/
[4] Vaadin Wiki - Mirating from Vaadin 6 to Vaadin 7
https://vaadin.com/wiki/-/wiki/Main/Migrating+from+Vaadin+6+to+Vaadin+7
[5] Book of Vaadin - Chapter 19 - JPAContainer
https://vaadin.com/book
[6] Vaadin Wiki - JEE6 integration with Vaadin 7
https://vaadin.com/wiki/-/wiki/Main/JEE6+integration+with+Vaadin+7
[7] Using JPA Container 2.0 in a JEE6 server
https://vaadin.com/web/matti/blog/-/blogs/using-jpa-container-2-0-in-a-jee6-server
[8] Vaadin Forum - Unable to follow J6EE wiki - NullPointerException
https://vaadin.com/forum/#!/thread/386542/389263?_19_redirect
[9] Book of Vaadin - Chapter 11.3. Debug Mode and Window
https://vaadin.com/book/-/page/advanced.debug.html
[10] Book of Vaadin - 4.9. Deploying an Application
https://vaadin.com/book/-/page/application.environment.html
[11] Liferay
http://www.liferay.com/
[12] YouTube - Java EE 7 with NetBeans and Vaadin
https://www.youtube.com/watch?v=3TompuzySD8