How to add ICEPusher object to a vertical layout in Vaadin 13 - vaadin

I need to add pusher object to vertical layout in Vaadin 13
sources: https://vaadin.com/directory/component/icepush/samples
public class Playboard extends VerticalLayout
{
private ICEPush pusher;
public Playboard() throws ExecutionException, InterruptedException{
generateGUI();
}
private void generateGUI() throws ExecutionException, InterruptedException {
..................
.................
pusher = new ICEPush();
VerticalLayout playboard = new VerticalLayout();
playboard.add(pusher); //Cannot resolve method
...........
............
}

Why would you want to do so? It states at add-on page that
A component that adds push support to Vaadin!
Vaadin(both 7-8 versions as well as Flow 10+, which you are using) has a built-in support for Push currently, so there is no need to use a mentioned add-on. In the simplest case, all you need to do to get push working for your view is to add an annotation. There is a good official documentation on push:
Server Push Configuration
Asynchronous Updates
But,anyway, as mentioned in the previous answer you can't use the add-on with V13,since it's available only for Vaadin 6 and 7

You can't - this is for the so called Vaadin Platform (Vaadin 6-8). You have to find a web component replacement for that feature, write your own, or maybe sometime in the future there will be tooling to retrofit the old components into Vaadin Flow.

Related

Vaadin 23: extending VaadinServlet with spring boot results in dual sessions (VaadinSession and SpringVaadinSession) and inconsistent behaviour

Vaadin 23
A little background, I have just converted an existing Vaadin 23 project to SpringBoot.
The existing code extends VaadinServlet for the following reasons:
Inject user object to all requests on a ThreadLocal
Supply custom SystemMessagesProvider
Provide a number of #WebInitParam
Add Session Create/Destroy hooks
If there is a way to achieve all of these functions without extending VaadinSession, that would be the preferred option.
I discovered the problem after a lot of debugging trying to load an image from a resource
StreamResource imageResource = new StreamResource("logo.svg",
() -> {
InputStream resourceAsStream = getClass().getResourceAsStream("/images/logo.svg");
return resourceAsStream;
});
logo = new Image(imageResource, "Logo");
So it turns out that the resource is associated with the VaadinSession, but when the browser requests the image the Vaadin code goes looking for it on the SpringVaadinSession - which does not contain the resource.
I have attempted to extend SpringServlet instead, but I have not been able to find any current examples of how to do this and my naive attempt results in Excepitons at runtime.

UnsatisfiedLinkError using JSNI with vaadin

I have created a Vaadin project, and I used JSNI for scripting. But when execution reaches at JSNI script, it shows an error.
java.lang.UnsatisfiedLinkError: com.yty.cws.CiwsUI.jsniDemo()V
at com.yty.cws.CiwsUI.jsniDemo(Native Method) ~[classes/:na]
at com.yty.cws.CiwsUI.lambda$0(CwsUI.java:31) ~[classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_92]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_92]
The following is my sample code.
public class CiwsUI extends UI{
private static final long serialVersionUID = 5275145103992848572L;
VerticalLayout mainLayout=new VerticalLayout();
private TextField txtName=new TextField();
private Button btnJSNI=new Button("JSNI");
#Override
protected void init(VaadinRequest request) {
mainLayout.addComponents(txtName,btnJSNI);
setContent(mainLayout);
mainLayout.setComponentAlignment(txtName, Alignment.MIDDLE_CENTER);
mainLayout.setComponentAlignment(btnJSNI, Alignment.MIDDLE_CENTER);
btnJSNI.addClickListener(e->{
System.out.println("Clicked");
jsniDemo();
});
}
private native void jsniDemo()/*-{
$wnd.alert("Hai JSNI");
}-*/;
}
Any help is greatly appreciated.
If you look at the differences between GWT & Vaadin you'll notice that besides the cliend-side API, Vaadin also has a server-side API, and the code you posted falls into that category. Searching the Vaadin forum I found this question with your exact problem. Adding below the reply of Henry Sara from the Vaadin dev team:
JSNI is only usable in the client side widgets whereas you are working
on the server side.
Use Window.executeJavaScript("...") (Vaadin 6) or
Root.executeJavaScript("...") (Vaadin 7) if you need to execute
JavaScript from your server side application.
While things may have changed since the answer and Root.executeJavaScript("..."); is now probably JavaScript.getCurrent().execute(...)");, the Vaadin docs offer information on javascript interactions to and from the serverside as well as on js components and extensions and also, you can check the wiki for more examples.

Vaadin 7 how to check if scrollbar is visible or not

How to check in Vaadin 7 if scrollbar is visible or not for a certain component, for example for Panel
Any implementation of AbstractClientConnector can be extended with AbstractExtension: https://vaadin.com/api/com/vaadin/server/AbstractExtension.html
An extension is a possible way to extend the functionality of your component: https://vaadin.com/docs/-/part/framework/gwt/gwt-extension.html
Adding features to existing components by extending them by inheritance creates a problem when you want to combine such features. For example, one add-on could add spell-check to a TextField, while another could add client-side validation. Combining such add-on features would be difficult if not impossible. You might also want to add a feature to several or even to all components, but extending all of them by inheritance is not really an option. Vaadin includes a component plug-in mechanism for these purposes. Such plug-ins are simply called extensions.
In the client-side extension implementation you can write your custom GWT code like following (pseudo code):
#Override
protected void extend(ServerConnector target) {
// Get the extended widget
final Widget widget = ((ComponentConnector) target).getWidget();
// register RPCs
YourServerRpcImplementation serverRpc = getRpcProxy(YourServerRpcImplementation.class); // client to server
registerRpc(YourClientRpcImplementation.class, this); // server to client, unused in this example
// add listener and update server state
Window.addResizeHandler(new ResizeHandler() {
#Override
public void onResize(ResizeEvent event) {
boolean scrollbarVisible = widget.getElement().getScrollHeight() > widget.getElement().getClientHeight();
serverRpc.yourEventMethod(scrollbarVisible);
}
});
}
Passing events between server and client: https://vaadin.com/docs/-/part/framework/gwt/gwt-rpc.html

Vaadin : How to change favicon?

How can I change favicon of my pages in Vaadin ? I would like to change favicon of my pages but I have no idea where is the place to change it ? Has somebody experience on it ?
First, create a theme directory: /WebContent/VAADIN/themes/mynewtheme
Then, put your custom favicon.ico in this directory. You also need to set theme property in your application :
public class MyNewApplication extends Application {
#Override
public void init() {
...
...
setTheme("mynewtheme");
}
}
Here is a more detailed version of the similar Answer posted by Greg Ballot. My Answer here relates to Vaadin 7, current as of 7.5.3.
Custom Theme
In Vaadin 7.5, you can drop your favicon graphics image file into your own custom theme. If using the Vaadin plugin for various IDEs (NetBeans, Eclipse) or the Maven archetypes, a custom theme named mytheme should have already been created for you. Drop your image file into that mytheme folder.
The main part of your Vaadin 7 app, your subclass of UI, must specify that it uses your custom theme. Again, if using the IDE plugins and/or Maven archetype, this should have already been configured for you. The easiest way is an Java Annotation on the UI subclass.
#Theme ( "mytheme" ) // Tell Vaadin to apply your custom theme, usually a subclass of the Valo or Reindeer theme.
#Title ( "PowerWrangler" ) // Statically specify the title to appear in web browser window/tab.
#SuppressWarnings ( "serial" ) // If not serializing such as "sticky sessions" and such, disable compiler warnings about serialization.
#Push ( PushMode.AUTOMATIC ) // If using Push technology.
public class MyVaadinUI extends UI
{
…
Favicon Usage/Behavior Not Standard
Remember that favicon behavior is not standardized. Favicons developed haphazardly, mostly out of a sense of fun. The exact behavior depends on the particular browser and particular server. Other than the particular folder location, none of this is special to Vaadin.
Image File Formats
Originally the ICO file format was used exclusively. Since then most browsers have evolved to accept any of several formats including JPEG, TIFF, and PNG.
Image Size/Resolution
Originally favicons were intended to be very small bitmap icons. Some browsers have made various uses of the favicon in situations where you may want to provide a higher-resolution image. But remember that smaller files load faster without keeping your users waiting.
Favicon File Name
Some browsers or servers may handle other file names or name extensions, but I've found it easiest to name my file exactly favicon.ico -- even if using a different format! I usually use a PNG file but name it with the .ico extension. While I cannot guarantee this practice works one every server and browser, I’ve not encountered any problem.
Existing Favicon File
Recent versions of Vaadin have included a Vaadin-related icon in a favicon.ico file in a configured project. So you must replace that file with your own. In Vaadin 7.5.3 the file contains four sizes, the largest looking like this:
Older versions did not add a file, so you drop in your own.
IDE Screen Shots
Here are a pair of screen shots. One is the project (logical) view in NetBeans 8, while the other is a files (physical) view.
In case of custom icon name (Vaadin 7):
public class MyServlet extends VaadinServlet implements SessionInitListener {
#Override
protected void servletInitialized() throws ServletException {
super.servletInitialized();
getService().addSessionInitListener(this);
}
#Override
public void sessionInit(SessionInitEvent event) throws ServiceException {
event.getSession().addBootstrapListener(new BootstrapListener() {
#Override
public void modifyBootstrapPage(BootstrapPageResponse response) {
response.getDocument().head()
.getElementsByAttributeValue("rel", "shortcut icon")
.attr("href", "./VAADIN/themes/mynewtheme/custom.ico");
response.getDocument().head()
.getElementsByAttributeValue("rel", "icon")
.attr("href", "./VAADIN/themes/mynewtheme/custom.ico");
}
#Override
public void modifyBootstrapFragment(BootstrapFragmentResponse response) {
}
});
}
}
EDIT
It is better to use the BootstrapListener as a static nested class: link
Vaadin 23.x (plain spring/war application, no springboot!):
Derive an implementation of com.vaadin.flow.component.page.AppShellConfigurator:
#Theme(value = "mytheme")
#PWA(name = "My application", shortName = "MyApp", iconPath = "icons/favicon.ico" )
public class AppShellConfiguratiorImpl implements AppShellConfigurator {
#Override
public void configurePage(AppShellSettings settings) {
settings.addFavIcon("icon", "icons/favicon.ico", "16x16");
}
}
And put your favicon.ico into src\main\webapp\icons (in order that it is encluded in <war-root>/icons/favicon.ico)
A servlet container (3.0 plus, e.g. Tomcat 8.5) will pick up this class automagically and load it.

error while trying vaadin jpacontainer example

I'm getting
java.lang.NoClassDefFoundError: com/vaadin/data/util/converter/Converter$ConversionException
error. I have made Person class as entity, and my application class is like this:
public class SimplejpaApplication extends Application {
#Override
public void init() {
// TODO Auto-generated method stub
VerticalLayout layout = new VerticalLayout();
JPAContainer<Person> persons =
JPAContainerFactory.make(Person.class, "book-examples");
persons.addEntity(new Person("Marie-Louise Meilleur", 117));
Table personTable = new Table("The Persistent People",persons);
layout.addComponent(personTable);
setMainWindow(new Window("simple",layout));
}
I'm using vaadin-jpacontainer-agpl-3.0-3.0.0-alpha2.jar
Can someone tell why this error happening? thank you.
Converter class is from Vaadin 7 but you are using Vaadin 6. You need to use vaadin-jpacontainer-agpl-3.0-2.1.0 for Vaadin 6.
Or you can upgrade your project to Vaadin 7 and use vaadin-jpacontainer-agpl-3.0-3.0.0-alpha2.jar.
Both jar files can be downloaded from Vaadin add-on page https://vaadin.com/directory#addon/vaadin-jpacontainer.

Resources