2014-03-12 37 views
0

我想在我的文件下载后强制重新加载页面。如何强制在primefaces中重新加载页面?

我试过,但没有奏效

<p:commandButton ajax="false" actionListener="#{fileDownloadController.forceDownload}"> 
    <p:fileDownload value="#{fileDownloadController.downloadXMLFile(myBean.mostRecentFile)}" /> 
    </p:commandButton> 
</p:commandButton> 

EDITED 该解决方案正确地重新加载,但它发生之前的文件可以下载

public StreamedContent downloadXMLFile(DMFile dmFile) { 
    ... 
    return new DefaultStreamedContent(stream, "text/xml", fileName); 

}

而且

public void forceReload(){ 
    ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext(); 
    try { 
     ec.redirect(((HttpServletRequest) ec.getRequest()).getRequestURI()); 
    } catch (IOException ex) { 
     Logger.getLogger(FileDownloadController.class.getName()).log(Level.SEVERE, null, ex); 
    } 
} 

回答

1

你可以尝试这样的事情:

// Redirect 
public static void redirect(String urlStr) 
{ 
    FacesContext ctx = FacesContext.getCurrentInstance(); 
    String url = ctx.getExternalContext().encodeActionURL(ctx.getApplication().getViewHandler().getActionURL(ctx, urlStr.replaceAll("\\?faces-redirect=true", ""))); 
    try { ctx.getExternalContext().redirect(url); } 
    catch (IOException ioe) { throw new FacesException(ioe); } 
} 

ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext(); 
ec.redirect(((HttpServletRequest) ec.getRequest()).getRequestURI()); 
+0

感谢,但我在哪里赶urlStr? – stackSaru

+1

我编辑我的回答,希望它会帮助你 –

+0

是的,谢谢,这正是我不过是求,我不能下载任何更多 – stackSaru

相关问题