<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>JAVA on Flowing Code</title><link>https://www.flowingcode.com/en/category/java/</link><description>Recent content in JAVA on Flowing Code</description><generator>Hugo</generator><language>en-US</language><lastBuildDate>Thu, 07 May 2020 15:22:02 +0000</lastBuildDate><atom:link href="https://www.flowingcode.com/en/category/java/index.xml" rel="self" type="application/rss+xml"/><item><title>Lazy, Filtered and Sorted Vaadin Grid using External Data Source</title><link>https://www.flowingcode.com/en/lazy-filtered-and-sorted-vaadin-grid-using-external-data-source/</link><pubDate>Wed, 24 Apr 2019 18:06:00 +0000</pubDate><guid>https://www.flowingcode.com/en/lazy-filtered-and-sorted-vaadin-grid-using-external-data-source/</guid><description>&lt;div style="clear: both; text-align: center;">&lt;img alt="" class="alignnone size-full wp-image-391" height="340" loading="lazy" src="https://www.flowingcode.com/images/uploads/2019/04/Lazy-Filtered-and-Sorted-Vaadin-Grid-using-External-Data-Source.png" width="760"/>&lt;/div>
&lt;div>&lt;/div>
&lt;div style="text-align: justify;">In large enterprise application development projects, it’s usual to code use cases that, as the main requirement, define to show the user huge amounts of data in a tabular way. For this kind of scenarios, there is a particular web component that comes really handy: a Grid. Given that we like Vaadin’s framework, we are going to describe how to configure it in such a way that doesn’t restrict you about performance issues when doing that.&lt;/div>
&lt;div style="text-align: justify;">This post assumes that you have some knowledge of web application development using the Vaadin Framework and the Java Platform. But we’ll try to explain everything as much as possible. The version that we used to write this application is Vaadin 13, but this part of the API is almost the same since Vaadin 8, so it should be possible to use the same approach in older versions.&lt;/div>
&lt;div style="text-align: justify;">Setting up a Vaadin Grid, is really easy, just create an instance and then customize the columns, or even skip that part if your Pojo is sufficiently self-descriptive.&lt;/div>
&lt;div style="text-align: justify;">As an example, let’s assume that we want to show a grid with data for a person, which we can define as a simplified entity like this:&lt;/div>
&lt;p>&lt;/p></description></item><item><title>Creating a Vaadin Flow Server-Side API for a Javascript component</title><link>https://www.flowingcode.com/en/creating-a-vaadin-flow-server-side-api-for-a-javascript-component/</link><pubDate>Tue, 08 Jan 2019 19:50:00 +0000</pubDate><guid>https://www.flowingcode.com/en/creating-a-vaadin-flow-server-side-api-for-a-javascript-component/</guid><description>&lt;div style="clear: both; text-align: center;">&lt;/div>
&lt;div>&lt;img alt="" class="alignnone size-full wp-image-394" height="340" loading="lazy" src="https://www.flowingcode.com/images/uploads/2019/01/Creating-a-Vaadin-Flow-Server-Side-API-for-a-Javascript-component.png" width="760"/>&lt;/div>
&lt;div style="text-align: justify;">Today we are going to explore some tips about how to create a Java server-side wrapper for a regular javascript component using &lt;a href="https://vaadin.com/flow" rel="nofollow noopener noreferrer" target="_blank">Vaadin Flow&lt;/a>. As you might notice, this popular framework has good documentation about how to integrate an existing Polymer Component, but there is no much info about how to integrate a regular Javascript component, so we will show you one easy approach of doing that.&lt;/div>
&lt;div style="text-align: justify;">What we want to do is, to show you how to create a nice Java API around a typical javascript component, so you can easily integrate it in your java applications.&lt;/div>
&lt;div style="text-align: justify;">Of course, there are many ways to build javascript visual components around there, we will focus on the ones that use this common pattern: &lt;i>you create a html element (like a Div), and then you instruct the library to “enhance” it&lt;/i>.&lt;/div>
&lt;div style="text-align: justify;">Then we have one important feature that is usually wanted: &lt;b>bidirectional communication between the server and the client&lt;/b>.&lt;/div>
&lt;div style="text-align: justify;">For this short tutorial we want to build a Vaadin Flow wrapper around one interesting library that is able to draw time line graphs: &lt;a href="http://visjs.org/" rel="nofollow noopener noreferrer" target="_blank">vis.js&lt;/a>. This library is based on the previous premise: to enhance (in this case) a div html tag.&lt;/div>
&lt;div style="text-align: justify;">Let’s start.&lt;/div>
&lt;h3>Step 1: Overview of your component&lt;/h3>
&lt;div style="text-align: justify;">First, it’s a good idea to use a starter to build a project based on Vaadin. We will use this one, which is perfect for creating a new component. Because it’s mandatory to specify a base GitHub project, just leave the one that is offered, you can change that later.&lt;/div>
&lt;div style="text-align: justify;">We want our component to be easy to use; hence, following Vaadin conventions, we will create a simple class that will extend a Div component. This class will be able to render the component in the client side, exposing some methods that will give the developer the ability for interacting with it in several ways:&lt;/div>
&lt;p>&lt;/p></description></item><item><title>Vaadin’s Grid editing capabilities</title><link>https://www.flowingcode.com/en/vaadins-grid-editing-capabilities/</link><pubDate>Mon, 30 Oct 2017 14:15:00 +0000</pubDate><guid>https://www.flowingcode.com/en/vaadins-grid-editing-capabilities/</guid><description>&lt;div>&lt;img alt="" class="alignnone size-full wp-image-442" height="340" loading="lazy" src="https://www.flowingcode.com/images/uploads/2017/10/Vaadins-Grid-editing-capabilities.png" width="760"/>&lt;/div>
&lt;div style="text-align: justify;">This time I’d like to talk a little bit about something that I believe is one of the most powerful capabilities of Vaadin Grid component: the editing feature. The default view of the component is a read-only view, of the tabular data loaded in the component. But if you enable the editor, you can visually edit the grid’s cells and change the data that the grid is holding in the server’s memory. Let’s dig in some difficulties to use this feature and how to overcome them.&lt;/div>
&lt;h3>Inline editing&lt;/h3>
&lt;div style="text-align: justify;">If you look at the demo sampler application, you’ll see that the Item Editor, is like a little form that opens whenever you double click a row. That’s different than the previous component in older Vaadin versions (Table). With Table, when you double click on it, the entire row turn into read/write mode, without changing the row into a “mini form” as grid does now. Of course this behavior is configurable, you can disable it just by calling &lt;span style="background-color: white; color: #464440; font-size: 14px;">&lt;span style="font-family: 'courier new' , 'courier' , monospace;">&lt;b>setBuffered(false)&lt;/b>&lt;/span>&lt;/span>&lt;span style="background-color: white; color: #464440; font-family: 'helvetica neue' , 'helvetica' , 'arial' , 'microsoft yahei new' , 'microsoft yahei' , 'simsun' , 'stxihei' , sans-serif; font-size: 14px; font-style: italic;">.&lt;/span>&lt;/div>
&lt;div style="text-align: justify;">Despite of being somehow more visual, this new conduct, could be an undesirable behavior for enterprise applications that happens to use the keyboard a lot, and not depending so much on the mouse, to handle the table or grid.&lt;/div>
&lt;div style="text-align: justify;">If your users desire that kind of grid management, then the &lt;a href="https://vaadin.com/directory#!addon/gridfastnavigation-add-on" rel="noopener noreferrer" target="_blank">Grid Fast Navigation Addon&lt;/a> is for you. It uses the &lt;a href="https://vaadin.com/docs/-/part/framework/gwt/gwt-extension.html" rel="noopener noreferrer" target="_blank">Component Extension feature&lt;/a>, to give the grid a new look, that makes the editing much more easier, and transforms it in a sort of excel style facility.&lt;/div>
&lt;table align="center" cellpadding="0" cellspacing="0" style="margin-left: auto; margin-right: auto; text-align: center;">
&lt;tbody>
&lt;tr>
&lt;td style="text-align: center;">&lt;a href="https://www.flowingcode.com/wp-content/uploads/2017/10/FastNavigation.gif" style="margin-left: auto; margin-right: auto;">&lt;img border="0" loading="lazy" src="https://www.flowingcode.com/images/uploads/2017/10/FastNavigation.gif"/>&lt;/a>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td style="font-size: 12.8px;">Grid Fast Navigation Addon in action&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;h3>Components&lt;/h3>
&lt;div style="text-align: justify;">Another thing that prevented some developers to stop using Table and starting to use grid, was that you couldn’t use a standard component inside a cell of a Grid. If you wanted to, for example, use checkboxes inside a cell, you had to create a special class, called “renderer”, that should handle the server and the client side of that cell.&lt;/div>
&lt;div style="text-align: justify;">Luckily there are some addons that may help you with that task. The one that stands out is the &lt;a href="https://vaadin.com/directory#!addon/grid-renderers-collection-for-vaadin7" rel="noopener noreferrer" target="_blank">Grid renderes collection&lt;/a> (it exists for Vaadin 7 and 8 versions). It provides a lot of components that let you handle select, checkbox, images, etc.&lt;/div>
&lt;div style="text-align: justify;">In the &lt;a href="https://vaadin.com/blog/-/blogs/vaadin-8-1-beta-is-out" rel="noopener noreferrer" target="_blank">last version of Vaadin&lt;/a>, one of the most interesting features, is a new Renderer, that adds the capability to render a Vaadin component inside a cell of a grid. You can see a preview &lt;a href="https://demo.vaadin.com/sampler/#ui/grids-and-trees/grid/component-renderer" rel="noopener noreferrer" target="_blank">in the sampler application&lt;/a>.&lt;/div>
&lt;div style="text-align: justify;">If you are using Vaadin 7, although, you could use a experimental version of that feature, installing the &lt;a href="https://vaadin.com/directory#!addon/componentrenderer" rel="noopener noreferrer" target="_blank">Component Renderer Addon&lt;/a>.&lt;br/>
Happy coding!&lt;/div>
&lt;div style="text-align: justify;">&lt;/div></description></item></channel></rss>