DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

The Latest Popular Topics

article thumbnail
How to Get Started With Vaadin Flow
In this blog, I will show you how I got started with Vaadin Flow. With Vaadin Flow, you can create web apps without HTML or JavaScript, but entirely with Java. Let’s get started! 1. Introduction For some time, I have been curious about Vaadin Flow. I am not very good in frontend developement but sometimes I try to get myself together and then I take a look at a frontend framework. In a previous post, I looked at React for example. Although the React introduction was a nice experience, I still did not think I could create a frontend with React before investing a serious amount of time. At Twitter, I often saw posts coming by about Vaadin and this took my interest. So, I put Vaadin on my blog todo list. A few weeks ago, I started to take a closer look at Vaadin, and more specifically at Vaadin Flow. Reading some blogs and examples, it reminded me about Java Swing but where Java Swing would create a traditional desktop application, Vaadin will create a web application for me. That sounds cool, because now I probably do not have a very steep learning curve and I can continue working in my Java IDE. Besides that, it also seems to integrate quite well with Spring, which I also already know. Enough prerequisites which should lead to a succes story for me. During my research I came up to the following interesting articles: Why I (still) love Vaadin, by Nicolas Fränkel; 5 Reasons Why Enterprises Use Vaadin For Their Web Application UI Needs, by Ankurman Shrestha Vaadin also takes care of the communication between frontend and backend. But when you are using a First API approach, you can call the API from the Vaadin backend part preventing duplication in your code. 2. Vaadin Flow Tutorial The easiest way to get started, is by following the Vaadin Flow Tutorial. Beware that you select the correct version of Vaadin Flow. At the time of writing, Vaadin 14 is the LTS version and is the one you should use when running in production, Vaadin 22 is the latest non-LTS version with new features to experiment with. I am most interested in the current production status and follow the Vaadin 14 Tutorial. The tutorial contains a basic project which you will enhance each time with code snippets which are provided. Also, the concepts and code snippets are clearly explained. Some basic components are used, login is added and it is also shown how you can write tests for the application. The latter is a great advantage because automated testing of a frontend application is always difficult to execute. It takes about 3-4 hours to complete the tutorial, but after that, you already have a good basis for creating your own project. The only disadvantage for me is that the tutorial is mainly copying of code snippets. This way, you miss certain details when trying to use Vaadin Flow yourself. 3. Own Project Let’s see whether I am able to create a frontend for a simple application. The application I create is quite basic and contains of a list of Shows for which ShowEvents can be created. A Show consists out of a title and a ShowEvent consists out of a date and the Show the event is for. The sources for this project can be found at GitHub. I will not explain the entire application, but I will mention some highlights how I built the application. 3.1 Get Started In order to get a quick start, I navigated to start.vaadin.com. Here you can configure the basic setup for the application. I chose an Empty template and added two views: one for the Shows and one for the ShowEvents. In the Settings tab, I changed the Project, the Group ID and decided to use Java 17. When ready configuring, I clicked the Download button and opened the project in my favorite IDE. In the pom, I changed the vaadin dependency to vaadin-core. Reason for this is that I only want to use free components and this should be more than enough for the basic application I want to build. XML com.vaadin vaadin-core ... Next, I wanted to run the application by running the main method of the Application class. Remember, Vaadin integrates well with Spring, so we are talking about a Spring Boot application here. However, this gave the following exception: Shell java.lang.IllegalStateException: The compatibility mode is explicitly set to 'false', but there are neither 'flow-build-info.json' nor 'webpack.config.js' file available in the project/work I was a little too enthusiastic, I had to build the application first. Shell $ mvn clean package After this, the application started successfully. 3.2 Creating the Application I started with creating the data package and copying the AbstractEntity of the tutorial into it. This required adding the spring-boot-starter-data-jpa dependency to the pom. OK, I know I wrote that by copying you miss some details and now I do it myself, but there is nothing wrong with a smart copy now and then. XML org.springframework.boot spring-boot-starter-data-jpa Next, I created the Show and ShowEvent entities and added the JPA repositories. Vaadin also provides a dependency for generating example data. This way, you can generate data into your application for testing purposes. Therefore, I added the exampledata dependency and created the DataGenerator class. XML com.vaadin exampledata 4.1.0 In order to get this working, I had to remove the NotEmpty annotation because of the following exception. I did not investigate this exception any further. Shell No validator could be found for constraint 'javax.validation.constraints.NotEmpty' validating type 'java.time.LocalDate' Next, I created the ShowService and added the H2 database as a dependency to the pom. XML com.h2database h2 Building and starting the application was successfull again and after that, I implemented the ShowsView, ShowEventsView and the ShowEventForm. The first two are for displaying the Shows and ShowEvents into a grid and the ShowEventForm will allow us to change and delete a ShowEvent. To give you an impression, some screenshots are shown here. The Shows page. The ShowEvents page. The ShowEvent form. 3.3 Lazy Loading In the DataGenerator the number of ShowEvents was initially set to 50, but when I increase this to 1000, then a problem occurs in the ShowEvents page. The whole list of ShowEvents is retrieved and loaded into memory. This will get worse when the list grows even further. The solution is provided in the documentation. First, I needed to change to ShowEventRepository by extending it from PagingAndSortingRepository instead of JpaRepository. Java public interface ShowEventRepository extends PagingAndSortingRepository { } Following the instructions of the documentation worked just fine when I scrolled slowly through the list, but when I scrolled a bit faster an IndexOutOfBoundsException was thrown. Shell java.lang.IndexOutOfBoundsException: Index 50 out of bounds for length 50 In order to explain why this exception occurs, we need to take a look at the code for fetching the results. Java private void updateList() { DataProvider dataProvider = DataProvider.fromCallbacks( // First callback fetches items based on a query query -> { // The index of the first item to load int offset = query.getOffset(); // The number of items to load int limit = query.getLimit(); List showEvents = showService.fetchShowEvents(offset, limit); return showEvents.stream(); }, // Second callback fetches the total number of items currently in the Grid. // The grid can then use it to properly adjust the scrollbars. query -> showService.countShowEvents()); grid.setDataProvider(dataProvider); } The offset and the limit (number of items to load) are retrieved from the query provided by Vaadin. However, JPA pagination needs a page and a limit. Therefore, the page needs to be calculated by dividing the offset by the limit. Initially, I just used the offset directly for the page and this caused the error. Java public List fetchShowEvents(int offset, int limit) { return showEventRepository.findAll(PageRequest.of(offset / limit, limit)).stream().toList(); } 4. Conclusion My first experience with Vaadin is quite positive. In most cases, I just need a frontend for an administrator or a limited set of users. With Vaadin I can make use of my Java experience and still provide a fancy web application. Also, the idea that I am able to create tests appeals me a lot. The free components will be most of the time enough for these kind of applications and if not, also some more advanced components are provided by means of a license.
March 16, 2022
by Gunter Rotsaert DZone Core CORE
· 2,914 Views · 2 Likes
article thumbnail
Java on Raspberry Pi
In this post, follow an overview of resources with information and examples of Java projects to control electronic components on the Raspberry Pi.
March 16, 2022
by Frank Delporte
· 10,487 Views · 7 Likes
article thumbnail
Where Spring Boot Meets Machine Learning Services: A Study
In this post, learn more about how the Deep Java Library brings Java developers into the machine learning (ML) game.
March 16, 2022
by John Vester DZone Core CORE
· 48,161 Views · 6 Likes
article thumbnail
Spring Boot: How To Use Java Persistence Query Language (JPQL)
In this Spring Boot video tutorial, take a closer look at how to use Java Persistence Query Language(JPQL), RESTful Web Services.
March 15, 2022
by Ram N
· 4,866 Views · 7 Likes
article thumbnail
Devoxx UK 2022: Designing Your Best Architecture Diagrams
Learn about a workshop that explores how diagramming is one of the most important communication tools to use for sharing your project and architectural ideas.
March 15, 2022
by Eric D. Schabell DZone Core CORE
· 2,397 Views · 4 Likes
article thumbnail
The Rise of the Data Reliability Engineer
With ever-growing complexity in the data driving today's dashboards and learning models, maintaining data quality and availability depends on the DRE.
March 15, 2022
by Alvin Lee DZone Core CORE
· 9,303 Views · 7 Likes
article thumbnail
What Devs Need To Teach CEOs About AI With Lexion’s Emad Elwany
Lexion's CTO and Co-Founder Emad Elwany gives a crash course on the current status of AI technology and what we can all expect in the future.
March 14, 2022
by Dan Lines
· 5,212 Views · 4 Likes
article thumbnail
Deploying AI With an Event-Driven Platform
Explore advantages of an event-driven platform for model deployment of your platform and create greater accessibility to your model classifications results.
March 14, 2022
by Tim Spann DZone Core CORE
· 8,814 Views · 3 Likes
article thumbnail
Tech Radar: What It Is and Why Tech Teams Need to Have One
Learn how Tech Radar can improve your team's experience, as well as avoid headaches in your organization's architecture.
March 13, 2022
by Otavio Santana DZone Core CORE
· 13,167 Views · 5 Likes
article thumbnail
MLOps for Enterprise AI
MLOps has started to emerge as a new trending keyword. This article provides an assessment of current trends, tools, and maturity models for MLOps.
March 12, 2022
by Sibanjan Das
· 11,247 Views · 3 Likes
article thumbnail
What Does AIOps Mean for SREs? It’s Complicated
While AIOps can bring some value to SREs, it’s important to maintain a healthy perspective and remember that AIOps also comes with limitations.
March 11, 2022
by JJ Tang
· 14,569 Views · 2 Likes
article thumbnail
Guide to Enterprise AI Platform Selection
Assessing business needs to focus on the right direction? Building it yourself, or buying from a vendor? Gain tools to make the right choice for your use case.
March 11, 2022
by Thomas Jardinet DZone Core CORE
· 7,322 Views · 4 Likes
article thumbnail
How to Easily Add CSV Import to Your React App
How do you easily convert CSV data for your app, MVP, or SaaS? What alternatives to free CSV parsers do you have? One solution is UseCSV. Read more here.
Updated March 11, 2022
by Aphinya Dechalert
· 6,658 Views · 2 Likes
article thumbnail
Typescript Tuples: How They Work
Let's look at how Typescript Tuples work.
March 11, 2022
by Johnny Simpson
· 7,345 Views · 5 Likes
article thumbnail
How to Configure Selenium in Eclipse
This article discusses how to configure Selenium in Eclipse to use Selenium for Java.
March 11, 2022
by Garima Tiwari
· 4,317 Views · 2 Likes
article thumbnail
What Is Breadth-First Search?
Breadth-First Search and Depth-First Search are 2 common algorithms used when working with graphs. Here we'll look at the first of those, Breadth-First Search.
March 11, 2022
by Dave Saunders
· 7,012 Views · 4 Likes
article thumbnail
The Top 11 AWS Certificates You Need to Know
For Software Engineers, mastery of AWS Cloud is one of the most attractive niches in the market today. AWS courses are the best route to career growth in this industry.
March 11, 2022
by Anthony Neto
· 7,068 Views · 5 Likes
article thumbnail
Spring Boot: JUnit Integration Test
In this Spring Boot video tutorial, take a closer look at the JUnit Integration Test and testing JWT Tokens and UserID (RESTful Web Services).
March 10, 2022
by Ram N
· 5,287 Views · 5 Likes
article thumbnail
Xamarin vs React Native: Which One Wins The Race?
Confused in the battle of Xamarin vs React Native to decide which framework is better for your project? In this post, learn various factors to help decide.
Updated March 10, 2022
by Riley Tony
· 7,132 Views · 2 Likes
article thumbnail
Binary Search in Python
In this article, we will look at what binary search is, how it is derived, and how it's faster than linear search.
March 10, 2022
by Sonia Mathias
· 6,724 Views · 4 Likes
  • Previous
  • ...
  • 283
  • 284
  • 285
  • 286
  • 287
  • 288
  • 289
  • 290
  • 291
  • 292
  • ...
  • Next
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook
×