相关疑难解决方法(0)

JSF + JSON:在servlet中输出"plain"文本?

我正在尝试将Mootools(Request.JSON)与JSF一起使用 - 主要是因为我前段时间在CakePHP中编写了一个类似的应用程序,并希望重用大部分JS部分.

有没有办法使用像无标记facelet这样的请求返回纯文本("application/json")?

我想出的唯一解决方案是使用HttpServlet并将其注册到web.xml中的服务URL.这种方法可以正常返回一个没有任何标记的文件,但我更倾向于使用我注入Spring的ManagedProperties,而不是仅限于WebApplicationContextUtils.

我错过了什么或是推荐的方式吗?

javascript jsf json facelets

3
推荐指数
1
解决办法
2956
查看次数

通过JSF将PDF发送到浏览器

我试图将JasperReports生成的PDF文件发送到用户的浏览器,我找不到我的托管bean方法有什么问题,这里是一个片段:

System.out.println("Making pdf...");

        FacesContext fc = FacesContext.getCurrentInstance();
        ExternalContext ec = fc.getExternalContext();
        String tplPath = ec.getRealPath("testTemplate.jrxml");
        JasperReport jasperReport = JasperCompileManager.compileReport(tplPath);
        JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, new HashMap<String,Object>(), ds );

        String pdfName = "/testReport.pdf";
        String pdfPath = ec.getRealPath(pdfName);
        JasperExportManager.exportReportToPdfFile(jasperPrint, pdfPath);

        System.out.println("PDF ready!");

        ec.responseReset(); 
        ec.setResponseContentType(ec.getMimeType(pdfPath)); 
        //ec.setResponseContentLength(contentLength); 
        ec.setResponseHeader("Content-Disposition", "attachment; filename=\"" + pdfName + "\""); 

        InputStream input = new FileInputStream(pdfPath);
        OutputStream output = ec.getResponseOutputStream();
        IOUtils.copy(input, output);

        System.out.println("Sending to browser...");

        fc.responseComplete();  
Run Code Online (Sandbox Code Playgroud)

通过简单的用户点击调用它:

<p:menuitem value="TestPDF" action="#{menuController.getTestPdf()}" />
Run Code Online (Sandbox Code Playgroud)

我觉得这很容易找到.为什么我看不到它?:)

jsf download jasper-reports primefaces jsf-2

3
推荐指数
1
解决办法
5797
查看次数

无法从JSF页面下载zip文件

我试图将多个PDF文件作为一个zip文件下载,然后更新JSF页面上的详细信息 - 有效地显示我正在处理这些文件.我已经使用场景后面的两个请求实现了这一点 - 1)更新数据库详细信息并刷新屏幕2)下载zip文件.

这在单工作站Windows环境中工作正常,但是当我在Linux环境中部署它时,在负载均衡器后面,我在尝试下载zip时得到一个空白页.我已经编写了SOP统计信息来打印通过JSF BB发送到ServletOutputStream的文件的大小,我发现正在打印正确的文件大小.但不知何故,我一直在丢失zip以及更新的JSF.这种情况也会在Windows中随机出现,这让我很担心:(.请提供宝贵的建议并帮助我摆脱这个问题.

您可能会考虑的一些要点:我使用的是Richfaces 3.3.3 Final,IE 8浏览器,响应传输编码类型是分块的.

==== BB方法如下:

String checkoutDoc = service.checkout(docId,true,contract, error);
FacesContext ctx = FacesContext.getCurrentInstance();
HttpServletResponse response = (HttpServletResponse) ctx.getExternalContext().getResponse();
File tempPdf = new File(checkoutDoc);URI tempURI = tempPdf.toURI();
URL pdfURL = tempURI.toURL();ServletOutputStream outstream =response.getOutputStream();
try 
{
 URLConnection urlConn = pdfURL.openConnection();
 response.setContentType("application/zip");
 response.setHeader("Transfer-Encoding", "chunked");
 response.addHeader("Content-disposition", "attachment;filename="+docId.toString()+".zip" );
 BufferedInputStream bufInStrm = new BufferedInputStream (urlConn.getInputStream());
 int readBytes = 0;
 int bufferSize = 8192;
 byte[] buffer = new byte[bufferSize];
 while ((readBytes = bufInStrm.read(buffer)) != -1){
if (readBytes …
Run Code Online (Sandbox Code Playgroud)

zip jsf load-balancing download

2
推荐指数
1
解决办法
4882
查看次数

java.lang.IllegalStateException:调用JasperReport时已为此响应调用了getOutputStream()

我在JSF 2中尝试iReport/JasperReport但是当我生成PDF时我得到了这个错误.我搜索并发现了一些类似的问题和解决方案,但没有任何效果.很抱歉再次发布相同的问题.但我尝试了所有可能的解决方案,但没有一个对我有用.请帮忙

java.lang.IllegalStateException: getOutputStream() has already been called for this response
at org.apache.catalina.connector.Response.getWriter(Response.java:637)
at org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:214)
at com.sun.faces.context.ExternalContextImpl.getResponseOutputWriter(ExternalContextImpl.java:723)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.createResponseWriter(FaceletViewHandlingStrategy.java:1009)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:382)
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:124)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:999)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:565)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:309)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
Run Code Online (Sandbox Code Playgroud)

以下是功能

public void init() throws IOException, JRException {
    JRBeanCollectionDataSource beanCollectionDataSource = new JRBeanCollectionDataSource(listReportObjects);
    ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext(); …
Run Code Online (Sandbox Code Playgroud)

jasper-reports servletexception ireport jasper-plugin jsf-2

2
推荐指数
2
解决办法
2万
查看次数

单击确认对话框后,无法下载zip文件。

我无法下载该zip文件。在confirmDialog中单击“确定”按钮后,我无法下载zip文件。如果我没有使用confirmDialog,则可以下载文件。谁能帮我这个忙,

在这里,我添加了代码以供参考。

<h:form>
    <p:panelGrid rendered="true">
        <p:commandButton style="HEIGHT: 24px; WIDTH: 300px" id="AjaxFalse"
            value="AjaxFalse"
            action="#{testDownload.getZipFile}"
            title="AjaxFalse" rendered="true">
            <p:confirm message="Are you sure?"
                header="Confirmation"
                icon="ui-icon-alert" />
        </p:commandButton>

    </p:panelGrid>

    <p:confirmDialog global="true" showEffect="fade" hideEffect="fade" width="500">
                <h:panelGroup layout="block" style="text-align: center">
                    <p:commandButton value="Ok"  type="submit" styleClass="ui-confirmdialog-yes" style="width:70px;"/>
                    <p:commandButton value="Cancel" type="button" styleClass="ui-confirmdialog-no" style="width:70px;"/>
                </h:panelGroup>
    </p:confirmDialog>
</h:form>
Run Code Online (Sandbox Code Playgroud)

我的菜豆是

public class TestDownload
{
//some code here
//Downloading the zip file in jsf2.x
public String getZipFile()
    {       
    try{
    //enter code here
            FacesContext fc = FacesContext.getCurrentInstance();
            ExternalContext ec = fc.getExternalContext();
            ec.setResponseHeader("Content-Disposition", "attachment;filename=\"" + Test …
Run Code Online (Sandbox Code Playgroud)

jsf primefaces

0
推荐指数
1
解决办法
616
查看次数