I dont know why, but i implemented your library, everything disappear in all my views. only i can see the splits but not the app layout to another library
Lo mismo me pasa alguna solucion???
Did you find any other solution? Any other Add-ons that you can recommend? I have a pdf file and I need to open it in a new browser tab, but with this Add-On I couldn’t…all versions of this Add-On for my project, it didn’t work, I use vaadin 14.6.3… I tried versions 3.1.0 - 3.0.1 - 3.0.0 here and nothing made the pdf open
We switched to a class named ‘EmbeddedPdfDocument’ by Dennis Reichenberg. If you search on Stack Overflow, you should find his comment that has the code in it.
would this article be?
https://vaadin.com/forum/thread/17577990/pdf-viewer-for-vaadin-13
Yes.
Paul, I can’t make it work in my application:
See what I did:
1st I copied the class this class to my project:
package br.com.fjsistemas.embedded;
import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.HasSize;
import com.vaadin.flow.component.Tag;
import com.vaadin.flow.server.StreamResource;
@Tag("object")
public class EmbeddedPdfDocument extends Component implements HasSize {
private static final long serialVersionUID = 1L;
public EmbeddedPdfDocument(StreamResource resource) {
this();
getElement().setAttribute("data", resource);
}
public EmbeddedPdfDocument(String url) {
this();
getElement().setAttribute("data", url);
}
protected EmbeddedPdfDocument() {
getElement().setAttribute("type", "application/pdf");
setSizeFull();
}
}
2nd
the article presents 3 options to work with the pdf, in my case, the third option is the most suitable, so I copied the class referring to the 3rd option
package br.com.fjsistemas.embedded;
import java.io.ByteArrayInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import org.springframework.stereotype.Component;
import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.server.StreamResource;
@Component
public class TestView extends Div {
private static final long serialVersionUID = 1L;
public TestView() {
add(new EmbeddedPdfDocument(new StreamResource("book-of-vaadin.pdf", () -> {
try {
return getPdfInputStream();
} catch (FileNotFoundException e) {
return new ByteArrayInputStream(new byte[] {});
}
})));
setHeight("100%");
}
private InputStream getPdfInputStream() throws FileNotFoundException {
return new FileInputStream("C:\\Users\\fjd2320\\eclipse-workspace\\Vaadin-Application-Sales-master\\src\\main\\resources\\RelatorioVendas.pdf");
}
}
3rd
In my ReportView class, I have a button that when clicked I want it to generate the pdf and then display it on the screen, so I instantiated the TestView class annotated as @Component, not @Route(“test”)
@autowired
private TestView view;
button:
exportarRelatorio.addThemeVariants(ButtonVariant.LUMO_PRIMARY);
exportarRelatorio.getStyle().set("margin-top", "37px");
exportarRelatorio.setWidth("180px");
exportarRelatorio.addClickListener(event -> {
//generates the report.pdf
try {
pdf.conversor();
} catch (JRException | SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//display in browser
try {
view.getPdfInputStream();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
});
Stack:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'testView' defined in file [C:\Users\fjd2320\eclipse-workspace\Vaadin-Application-Sales-master\target\classes\br\com\fjsistemas\embedded\TestView.class]
: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [br.com.fjsistemas.embedded.TestView]
: Constructor threw exception; nested exception is java.lang.NullPointerException
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1316) ~[spring-beans-5.3.6.jar:5.3.6]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1214) ~[spring-beans-5.3.6.jar:5.3.6]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:564) ~[spring-beans-5.3.6.jar:5.3.6]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:524) ~[spring-beans-5.3.6.jar:5.3.6]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.6.jar:5.3.6]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.6.jar:5.3.6]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.6.jar:5.3.6]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.6.jar:5.3.6]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:944) ~[spring-beans-5.3.6.jar:5.3.6]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918) ~[spring-context-5.3.6.jar:5.3.6]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) ~[spring-context-5.3.6.jar:5.3.6]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:144) ~[spring-boot-2.4.5.jar:2.4.5]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:782) ~[spring-boot-2.4.5.jar:2.4.5]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:774) ~[spring-boot-2.4.5.jar:2.4.5]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:439) ~[spring-boot-2.4.5.jar:2.4.5]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:339) ~[spring-boot-2.4.5.jar:2.4.5]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1340) ~[spring-boot-2.4.5.jar:2.4.5]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1329) ~[spring-boot-2.4.5.jar:2.4.5]
at br.com.fjsistemas.Application.main(Application.java:14) ~[classes/:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:567) ~[na:na]
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) ~[spring-boot-devtools-2.4.5.jar:2.4.5]
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [br.com.fjsistemas.embedded.TestView]
: Constructor threw exception; nested exception is java.lang.NullPointerException
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:225) ~[spring-beans-5.3.6.jar:5.3.6]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:87) ~[spring-beans-5.3.6.jar:5.3.6]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1308) ~[spring-beans-5.3.6.jar:5.3.6]
... 23 common frames omitted
Caused by: java.lang.NullPointerException: null
at com.vaadin.flow.server.communication.StreamRequestHandler.generateURI(StreamRequestHandler.java:152) ~[flow-server-2.6.3.jar:2.6.3]
at com.vaadin.flow.server.StreamResourceRegistry.getURI(StreamResourceRegistry.java:144) ~[flow-server-2.6.3.jar:2.6.3]
at com.vaadin.flow.server.StreamResourceRegistry.getURI(StreamResourceRegistry.java:127) ~[flow-server-2.6.3.jar:2.6.3]
at com.vaadin.flow.internal.nodefeature.ElementAttributeMap.doSetResource(ElementAttributeMap.java:159) ~[flow-server-2.6.3.jar:2.6.3]
at com.vaadin.flow.internal.nodefeature.ElementAttributeMap.setResource(ElementAttributeMap.java:143) ~[flow-server-2.6.3.jar:2.6.3]
at com.vaadin.flow.dom.impl.BasicElementStateProvider.setAttribute(BasicElementStateProvider.java:348) ~[flow-server-2.6.3.jar:2.6.3]
at com.vaadin.flow.dom.Element.setAttribute(Element.java:355) ~[flow-server-2.6.3.jar:2.6.3]
at br.com.fjsistemas.embedded.EmbeddedPdfDocument.<init>(EmbeddedPdfDocument.java:15) ~[classes/:na]
at br.com.fjsistemas.embedded.TestView.<init>(TestView.java:19) ~[classes/:na]
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:na]
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500) ~[na:na]
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481) ~[na:na]
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:212) ~[spring-beans-5.3.6.jar:5.3.6]
... 25 common frames omitted
We are currently on flow 2.5.4 (you are on 2.6.3).
In the 2.5.4 version, StreamRequestHandler.java @152 is attempting to retrieve the current UI (builder.append(UI.getCurrent().getUIId()).append(PATH_SEPARATOR);).
Is this the same in 2.6.3?
honestly i can’t answer your question