I experience problem when placing downloading of a file to a data table. Problem seems to be related to pagination, downloading of a file works with
Code: Select all
paginator=false
Consider this code for jsf:
Code: Select all
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.prime.com.tr/ui"
template="/WEB-INF/templates/default.xhtml"
xmlns:c="http://java.sun.com/jsp/jstl/core">
<ui:define name="content">
<f:view contentType="text/html">
<h:form prependId="false">
<p:panel header="Files " >
<p:dataTable var="logRow" value="#{testDownloadController.inputLog}" paginator="true"
selectionMode="single"
onRowSelectUpdate="display"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="10"
paginatorPosition="bottom"
>
<p:column sortBy="#{logRow.filename}" filterBy="#{logRow.filename}">
<f:facet name="header">
<h:outputText value="Filename" />
</f:facet>
<h:outputText value="#{logRow.filename}" rendered="#{logRow.inputFileStreamedContent == null}" />
<h:commandLink value="#{logRow.filename}" rendered="#{logRow.inputFileStreamedContent != null}">
<p:fileDownload value="#{logRow.inputFileStreamedContent}"></p:fileDownload>
</h:commandLink>
</p:column>
</p:dataTable>
</p:panel>
</h:form>
</f:view>
</ui:define>
</ui:composition>
Code: Select all
package mytestpackage;
import testBean.InputFileLog;
import java.io.Serializable;
import java.util.List;
import javax.enterprise.context.SessionScoped;
import javax.inject.Named;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Named
@SessionScoped
public class TestDownloadController implements Serializable {
@PersistenceContext
EntityManager em;
private Logger logger = LoggerFactory.getLogger(TestDownloadController.class);
private InputFileLog selectedLog;
public InputFileLog getSelectedLog() {
return selectedLog;
}
public void setSelectedLog(InputFileLog selectedLog) {
this.selectedLog = selectedLog;
}
public List<InputFileLog> getInputLog() {
Query q = em.createNamedQuery("InputFileLog.findAll");
return q.getResultList();
}
}
Code: Select all
package .....;
import FileContentTypes;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
....
import org.primefaces.model.DefaultStreamedContent;
import org.primefaces.model.StreamedContent;
@Entity
@Table(name = "INPUT_FILE_LOG")
@NamedQueries({
@NamedQuery(name = "InputFileLog.findAll", query = "SELECT i FROM InputFileLog i")
})
public class InputFileLog implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Basic(optional = false)
@Column(name = "fileuri")
private String fileuri;
@Column(name="CONTENT_TYPE")
private FileContentTypes contentType;
@Lob
private byte[] contents;
public InputFileLog() {
}
public InputFileLog(String fileuri) {
this.fileuri = fileuri;
}
public String getFileuri() {
return fileuri;
}
public void setFileuri(String fileuri) {
this.fileuri = fileuri;
}
public String getFilename() {
return filename;
}
public void setFilename(String filename) {
this.filename = filename;
}
public FileContentTypes getContentType() {
return contentType;
}
public void setContentType(FileContentTypes contentType) {
this.contentType = contentType;
}
public byte[] getContents() {
return contents;
}
public void setContents(byte[] contents) {
this.contents = contents;
}
public StreamedContent getInputFileStreamedContent() {
if (this.contents == null){
this.contents = new byte[0];
}
InputStream inputStream = new ByteArrayInputStream(this.contents);
return new DefaultStreamedContent(inputStream, this.contentType.toString(), this.filename);
}
@Override
public int hashCode() {
int hash = 0;
hash += (fileuri != null ? fileuri.hashCode() : 0);
return hash;
}
@Override
public String toString() {
return "InputFileLog[fileuri=" + fileuri + "]";
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final InputFileLog other = (InputFileLog) obj;
if ((this.fileuri == null) ? (other.fileuri != null) : !this.fileuri.equals(other.fileuri)) {
return false;
}
return true;
}
}
With paginator="true", when I click on a link a get this exception
Code: Select all
java.lang.NullPointerException
at org.primefaces.component.datatable.DataHelper.decodeFilters(DataHelper.java:182)
at org.primefaces.component.datatable.DataTableRenderer.decode(DataTableRenderer.java:47)
at javax.faces.component.UIComponentBase.decode(UIComponentBase.java:790)
at javax.faces.component.UIData.processDecodes(UIData.java:980)
at org.primefaces.component.datatable.DataTable.processDecodes(DataTable.java:595)
at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1042)
at javax.faces.component.UIForm.processDecodes(UIForm.java:216)
at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1042)
at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1042)
at javax.faces.component.UIViewRoot.processDecodes(UIViewRoot.java:941)
at com.sun.faces.lifecycle.ApplyRequestValuesPhase.execute(ApplyRequestValuesPhase.java:78)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:312)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1523)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:343)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:215)
at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:79)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:215)
at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:61)
at org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108)
at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137)
at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:81)
at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66)
at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:359)
at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:275)
at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)
at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)
at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:344)
at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:272)
at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:81)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:215)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:277)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:188)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:641)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:97)
at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:85)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:185)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:325)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:226)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:165)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:791)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:693)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:954)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:170)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:135)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:102)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:88)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:76)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:53)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:57)
at com.sun.grizzly.ContextTask.run(ContextTask.java:69)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:330)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:309)
at java.lang.Thread.run(Thread.java:662)
Any ideas? Just ask if you need more info
EDITED: found out, that fileDownload does not have to be placed inside dataTable, it's enough if there is some table that has paginator=true and download fails.
something like this
Code: Select all
<h:panelGroup>
<h:panelGrid border="0" cellspacing="10" columns="1">
<h:panelGroup>
<h:outputText value="File with Error : "/>
<h:commandLink value="#{inputFilelog.filename}" >
<p:fileDownload value="#{inputFileLog.errorsFileStreamedContent}" />
</h:commandLink>
</h:panelGroup>
</h:panelGrid>
<h:panelGrid id="display" columns="2" cellpadding="4" >
<p:dataTable var="data" value="#{someList}" paginator="true" rows="#{uisettings.file_error_rows}"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="#{uisettings.datatable_rows_per_page_template}"
paginatorPosition="bottom" rendered="true"
>
<p:column sortBy="#{data.A}" filterBy="#{data.A}">
<f:facet name="header">
<h:outputText value="data A" />
</f:facet>
<h:outputText value="#{data.A}" />
</p:column>
</p:dataTable>
</h:panelGrid>
</h:panelGroup>