Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jsf 在commandLink操作中打开其他链接_Jsf - Fatal编程技术网

Jsf 在commandLink操作中打开其他链接

Jsf 在commandLink操作中打开其他链接,jsf,Jsf,我有以下命令链接: <h:commandLink action="#{orderForm.printOrderCards}" value="Print Document"> </h:commandLink> ActionHandler如下所示: public String printOrderCards() { try { HttpServletResponse response = (HttpServletResponse) Fac

我有以下命令链接:

<h:commandLink action="#{orderForm.printOrderCards}"
    value="Print Document">
</h:commandLink>

ActionHandler如下所示:

public String printOrderCards() {
    try {
        HttpServletResponse response = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext()
                .getResponse();

        PrintWriter out = response.getWriter();
        out.println("<html><body>");
        out.println("<script type=\"text/javascript\">");
        String url = "http://nb200srv2016:8080/obt-documents/Artikel/2050/1007144_Rev.BA.pdf?allowCache=true&openDirectly=true";
        out.println("window.open(\"" + url + "\");");

        out.println("</script>");
        out.println("</body></html>");
        out.flush();
        out.close();
    } catch (final IOException e) {
        e.printStackTrace();
    }
    return "go_printOrderCards";
}
公共字符串printOrderCards(){
试一试{
HttpServletResponse=(HttpServletResponse)FacesContext.getCurrentInstance().getExternalContext()
.getResponse();
PrintWriter out=response.getWriter();
out.println(“”);
out.println(“”);
字符串url=”http://nb200srv2016:8080/obt-documents/Artikel/2050/1007144_Rev.BA.pdf?allowCache=true和OpenDirective=true”;
out.println(“window.open(\“”+url+“\”);”;
out.println(“”);
out.println(“”);
out.flush();
out.close();
}捕获(最终IOE例外){
e、 printStackTrace();
}
返回“go_printOrderCards”;
}
我想在新窗口中打开一个URL。操作完成后,应打开一个jsp页面(
go\u PrintOrderCards
)。 将打开新窗口中的URL。但是
go\u PrintOrderCards
的新jsp页面将不会显示

有人能帮我解决这个问题吗?

你能做的是:

1) 将
printOrderCards
方法的返回类型更改为void,如下所示:

public void printOrderCards() {
2) 删除
printOrderCards
方法中的所有代码行,并将这些代码行添加到该方法中:

String url = "http://nb200srv2016:8080/obt-documents/Artikel/2050/1007144_Rev.BA.pdf?allowCache=true&openDirectly=true";
RequestContext requestContext = RequestContext.getCurrentInstance();  
requestContext.execute("window.open('"+url+"')");

javascript的调用正在工作。但是CommandLink不会在naviagte之后转到打印订单卡。因为您自己已经发送了html响应。您不能(http限制,而不是JSF)在一个响应中发送两个不同的响应。这是否回答了您的问题?