Java 如何在primefaces中强制重新加载页面?

Java 如何在primefaces中强制重新加载页面?,java,javascript,primefaces,Java,Javascript,Primefaces,下载文件后,我想强制重新加载页面中的页面 我试过了,但没用 <p:commandButton ajax="false" actionListener="#{fileDownloadController.forceDownload}"> <p:fileDownload value="#{fileDownloadController.downloadXMLFile(myBean.mostRecentFile)}" /> </p:commandBu

下载文件后,我想强制重新加载页面中的页面

我试过了,但没用

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


您可以尝试以下方法:

// 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); }
}


是的,谢谢,这正是我想要的,但是,我不能再下载了这是什么意思,“不能再下载了”?出现错误了吗?嗯,刷新是在下载之前完成的,因为我必须在返回新的DefaultStreamedContent(流,“text/xml”,文件名)之前加上“ExternalContext ec”;嗯,我想我明白了。您不能在一个请求中进行重定向和下载;这是需要提出的两项独立请求。我唯一能想到的是,在下载完成后设置某种标志,然后在客户端进行ajax轮询,检查是否要设置该标志,此时从客户端触发重定向。
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);
    }
}
// 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());