Monday, 28 August 2017

How Vaadin manage navigation in Spring Boot

Using Vaadin(GWT) front-end in the Spring boot.

Vaadin UI : it is a single component container, which holds a single layout component.
Vaadin View: it is a CustomComponent or a layout, while implementing vaadin view interface.

When using Vaadin with Spring boot, the above should be annotated by
@SpringUI and @SpringView respectively; so that it will be picked up in the Spring context.

When navigating between pages in Vaadin,  actually it is partially replaced by another view or the whole UI is replaced by another UI.

A Vaadin UI holds a navigator, and a SpringNavigatorProvider that manages the Vaadin views.
Navigator should be declared and instantiated in the UI. It should be associated with the
SpringNavigatorProvider.

As using Spring boot, SpringNavigatorProvider is auto-wired(injected).
Views will be automatically registered in the provider.





Vaadin Spring

Vaadin Spring Add-on

Vaadin Navigator Problem

View and Navigation

Vaadin Spring Code Example

Github vaadin-valo-demo

Wednesday, 23 August 2017

How to recover contributor in Github

One of my repository in the Github lost its contributor. I didn't see my avatar on the each commit.
The reason is due to I didn't give each commit a correct email address and name.

So I found the following URL;  by its instructions, I solved the problem.


Github Change Author Information

How to convert an image into byte array

Sometime we need to convert an image into byte array in order to persist it into database.

import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import javax.imageio.ImageIO;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author YNZ
 */
public class Image2Array {

    public static void main(String[] args) {
        byte[] imageArray = null;
        BufferedImage image = null;
        File file = new File("./src/tmp", "hit.jpg");
        try {
            image = ImageIO.read(file);
            try (ByteArrayOutputStream baos = new ByteArrayOutputStream(1024)) {
                System.out.println("write to buffer" + ImageIO.write(image, "jpg", baos));
                imageArray = baos.toByteArray();
                System.out.println("size of array " + imageArray.length);
                baos.flush();
            }

        } catch (IOException ex) {
            Logger.getLogger(Image2Array.class.getName()).log(Level.SEVERE, null, ex);
        }

    }

}

Sunday, 20 August 2017

Can Jackson Deserialize Java Time ZonedDateTime

Yes, but must include JSR310. Thus ZonedDateTime can be deserialized directly from JSON response to POJO field. <dependency> <g...