Thursday, 8 February 2018
Vaadin Spring Annotations
@SpringComponent: it is an alias of @Component; for Vaadin has already defined a component interface in usage. It declares a Vaadin bean it can be injected from Spring IoC.
@SpringUI: let the Vaadin Spring plugin know which UI's should be accessible to the user and how they should be mapped. It accepts one optional String parameter indicating the UI path. If an explicit path is not provided or an empty string is used as the path, the UI will be mapped to the context root.
@SpringView: annotating views, so as to be found by SpringViewProvider
@SpringViewDisplay: to define where in the UI the views are to be shown, a bean or a class implementing ViewDisplay or extending (Single)ComponentContainer should be annotated with @SpringviewDisplay.
Single Component Container: Window, Panel, and UI.
@UIScope: an annotation is specific to Vaadin Spring. Getting the same instance within the same UI, but injecting different instance as in different UI.
@ViewScope: it makes a life cycle of this injected bean view specific.
@VaadinSessionScope: Objects in VaadinSeesionScope is unique, and shared between all UIs open in the session. This is the most basic scope in Vaadin applications, useful for accessing data for the user associated with the session.
Standard Spring scopes can be used with some restrictions. Most commonly,
@Scope("prototype") to inject a new instance every time that bean is injected. The following cannot be used for Vaadin Components.
@Scope("singleton") can be used for thread-safe background services, the request and session scope of Spring do not match exactly the Vaadin session and do not work in background threads such as in operations even when using Ui.access()
Saturday, 3 February 2018
Converting image from File to byte array
private byte[] image2byte(File file, String mimeType) {
if (!mimeType.contains("image")) {
return null;
}
byte[] imageByte = null;
String formatName = getFormatName(mimeType);
BufferedImage bi;
try {
bi = ImageIO.read(file);
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
boolean done = ImageIO.write(bi, formatName, baos);
baos.flush();
imageByte = baos.toByteArray();
}
} catch (IOException ex) {
logger.error(ex.getMessage());
}
return imageByte;
}
OR
try {
// Write the image to a buffer
imagebuffer = new ByteArrayOutputStream();
ImageIO.write(image, "png", imagebuffer);
// Return a stream from the buffer
return new ByteArrayInputStream(
imagebuffer.toByteArray());
} catch (IOException e) {
return null;
}
Subscribe to:
Posts (Atom)
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...
-
Could not extract response: no suitable HttpMessageConverter found for response type [class dk.enettet.evu.core.model.Address] and content ...
-
First time met this hibernate exception. I think this issue should due to one to one relationship. One driver has one car; one car has on...
-
A large object refers to the entity property that is modified by @Lob. It may be persisted in several records. However, in database manage...