Jsf 如何使用h:commandLink在新窗口而不是选项卡中打开页面?

Jsf 如何使用h:commandLink在新窗口而不是选项卡中打开页面?,jsf,Jsf,使用PrimeFaces4.0和JSF2.2 我想将访问者发送到新窗口(而不是选项卡)中的页面。登录页面是一个名为grade.xhtmljsf页面 我试过: <h:commandLink value="OK" onclick="window.open('grade.html', 'newwindow','width=300, height=300'); return false;"/> 这是404。显然,这一切都发生在客户端,因此grade.html不会从grade.xhtml

使用PrimeFaces4.0和JSF2.2

我想将访问者发送到新窗口(而不是选项卡)中的页面。登录页面是一个名为
grade.xhtml
jsf页面

我试过:

<h:commandLink value="OK" onclick="window.open('grade.html', 'newwindow','width=300, height=300'); return false;"/>

这是404。显然,这一切都发生在客户端,因此grade.html不会从
grade.xhtml
生成。我该怎么办

注意:如果我将
onclick=“window.open('grade.xhtml','newwindow','width=300,height=300');返回false;“
则页面确实打开,但显示的是jsf(xhtml代码)而不是html版本。

尝试以下操作:

<h:commandLink value="OK" action="grade.xhtml" target="_blank"/>


看看这里的一个例子:

我使用javaScript来实现这一点。。试试看:

<script type="text/javascript" language="javascript">
    function funcForWindowPopup()
    {
        var popup = null;
        popup = window.open("grade.xhtml", "popup", "toolbar=no,menubar=no,scrollbars=yes,location=no,left=350,top=50,width=650, height=600");
        popup.openerFormId = "formID";
        popup.focus();
    }

</script>

函数funcForWindowPopup()
{
var=null;
popup=window.open(“grade.xhtml”,“popup”,“toolbar=no,menubar=no,scrollbars=yes,location=no,left=350,top=50,width=650,height=600”);
popup.openerFormId=“formID”;
popup.focus();
}

您可以根据需要更改参数;)

从JSF控制器在新窗口中打开URL

HttpServletResponse res = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse();
            HttpServletRequest req = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
            String uri = req.getRequestURI();
            res.getWriter().println("<script>window.open('" + myUrl + "','_blank', 'location=yes,height=600,width=800,scrollbars=yes,status=yes'); window.parent.location.href= '"+uri+"';</script>");
            FacesContext.getCurrentInstance().responseComplete();   
HttpServletResponse res=(HttpServletResponse)FacesContext.getCurrentInstance().getExternalContext().getResponse();
HttpServletRequest req=(HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
字符串uri=req.getRequestURI();

res.getWriter().println(“window.open(“+myUrl+”,“u blank”,“location=yes,height=600,width=800,scrollbars=yes,status=yes”);window.parent.location.href=“+uri+”;”; FacesContext.getCurrentInstance().responseComplete();
为URL使用绝对路径?仍然是带/grade.htmlCheck设置的404@蒂亚戈的回答是正确的。纯html
也会打开新窗口。两人都被重新测试了。谢谢!不过,这会重定向到grade.xhtml的jsf版本(包含所有jsf标记的版本),而不是html版本。我检查了简单的“”是否正常工作。我看不出这里出了什么问题…@seinecle你说得不对。此答案中的代码打开新窗口。检查您的设置。window.parent.location.href='“+uri+”,这将刷新父页面以将其恢复。