<div dir="ltr">
Sziasztok!
<br>
<br>Csináltam egy JSF komponenst, amiben file letöltések vannak. A lényeg:
<br>
<br><?xml version="1.0" encoding="UTF-8"?>
<br><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
<a class="gmail-moz-txt-link-rfc2396E" href="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"</a>>
<br><html
<br>        xmlns:h=<a class="gmail-moz-txt-link-rfc2396E" href="http://java.sun.com/jsf/html">"http://java.sun.com/jsf/html"</a>
<br>        xmlns:p=<a class="gmail-moz-txt-link-rfc2396E" href="http://primefaces.org/ui">"http://primefaces.org/ui"</a>
<br>        xmlns:f=<a class="gmail-moz-txt-link-rfc2396E" href="http://java.sun.com/jsf/core">"http://java.sun.com/jsf/core"</a>
<br>        xmlns:composite=<a class="gmail-moz-txt-link-rfc2396E" href="http://java.sun.com/jsf/composite">"http://java.sun.com/jsf/composite"</a>
<br>>
<br><composite:interface>
<br>    <composite:attribute name="enabled"    required="false" 
shortDescription="Komponens engedélyezése" default="#{true}"/>
<br>    <composite:attribute name="exportFnc" required="true" 
shortDescription="Exportáló metódus"
<br>method-signature="org.primefaces.model.DefaultStreamedContent export()"
<br>        targets="expTxt expCsv expOds expXls"
<br>    />
<br></composite:interface>
<br>
<br><composite:implementation>
<br>    <h:panelGroup layout="block" styleClass="exporter" 
rendered="#{cc.attrs.enabled}">
<br>        <h:form>
<br>            <p:commandLink id="expTxt" ajax="false">
<br>                <p:graphicImage value="/img/export/txt.svg" alt="TXT"/>
<br>                <f:param name="exportType" value="TXT"/>
<br>                <p:fileDownload value="#{cc.attrs.exportFnc}" />
<br>            </p:commandLink>
<br>            <p:commandLink id="expCsv" ajax="false">
<br>                <p:graphicImage value="/img/export/csv.svg" alt="CSV"/>
<br>                <f:param name="exportType" value="CSV"/>
<br>                <p:fileDownload value="#{cc.attrs.exportFnc}" />
<br>            </p:commandLink>
<br>            <p:commandLink id="expOds" ajax="false">
<br>                <p:graphicImage value="/img/export/ods.svg" alt="ODS"/>
<br>                <f:param name="exportType" value="ODS"/>
<br>                <p:fileDownload value="#{cc.attrs.exportFnc}" />
<br>            </p:commandLink>
<br>            <p:commandLink id="expXls" ajax="false">
<br>                <p:graphicImage value="/img/export/xls.svg" alt="XLS"/>
<br>                <f:param name="exportType" value="XLS"/>
<br>                <p:fileDownload value="#{cc.attrs.exportFnc}" />
<br>             </p:commandLink>
<br>        </h:form>
<br>    </h:panelGroup>
<br></composite:implementation>
<br></html>
<br>
<br>Használata:
<br>
<br><laja:exporter enabled="#{ValamiController.data.size() > 0}" 
exportFnc="#{ValamiController.export}"/>
<br>
<br>A controller-ben a rutin valami ilyesmi:
<br>
<br>public DefaultStreamedContent export() {
<br>        DefaultStreamedContent sc = new DefaultStreamedContent(
<br>             new ByteArrayInputStream(exportedFile), 
expData.getType().mime, getFileName(lista, expData.getType())
<br>        );
<br>       ....
<br>}
<br>
<br>
<br>Sajna futtatáskor hibát dob:
<br>
<br>java.lang.ClassCastException: 
com.sun.faces.facelets.el.ContextualCompositeMethodExpression cannot be 
cast to org.primefaces.model.StreamedContent
<br>    at 
org.primefaces.component.filedownload.FileDownloadActionListener.processAction(FileDownloadActionListener.java:59)
<br>
<br>Valakinek ötlete mit lehet neki ártani? Neten majdnem semmi infó, ami 
van is 8-9 éves
<br>
<br>Köszi! Laja
<br>


</div>