English 中文(简体)
Jsf重定向到新窗口
原标题:Jsf redirect to new window

我正在使用mojarra primefaces tomcat6.x制作一个JSF2.0项目。

我做了一个选择列表,当我选择列表中的项目时,我想重定向到选定的url。它可以是一个内部URL。

这是可行的,但我想知道是否有可能在新窗口中重定向。

我有以下代码JSF:

        <h:form>
            <h:selectOneMenu onchange="this.form.submit();" valueChangeListener="#{wagent.selectBusinessTravelLink}">
                <f:selectItem itemLabel="#{msg[ form.select.defaultValue ]}" itemValue="" noSelectionOption="true"/>
                <f:selectItems value="#{wagent.businessTravelLinks}" var="bLinkItem" itemLabel="#{bLinkItem.label}" itemValue="#{bLinkItem.id}" />
            </h:selectOneMenu>
        </h:form>

Java语言:

   public void selectBusinessTravelLink(ValueChangeEvent event) {
// some stuff
FacesContext.getCurrentInstance().getExternalContext().redirect(targetUrl);
}
最佳回答

使用JavaScript swindow.open()函数,而不是form.submit()

假设select项的值是完全有价值的URL,下面是一个示例:

<h:selectOneMenu onchange="window.open(this.options[this.selectedIndex].value)">
问题回答

使用onclick=“this.form.target=_blank”(或在onchange中使用),即。,

<h:form id="form">
    <h:selectOneMenu onchange="this.form.target= _blank ; this.form.submit();" valueChangeListener="#{wagent.selectBusinessTravelLink}">
         <f:selectItem itemLabel="#{msg[ form.select.defaultValue ]}" itemValue="" noSelectionOption="true"/>
         <f:selectItems value="#{wagent.businessTravelLinks}" var="bLinkItem" itemLabel="#{bLinkItem.label}" itemValue="#{bLinkItem.id}" />
     </h:selectOneMenu>
 </h:form>

当然,不要忘记修复<;h: form id=“form”>





相关问题
How to use redirect_to to a non-Rails URL with query params?

We just had an existing use of redirect_to break due to a Rails upgrade, and it led to a question. I ve been experimenting, and I don t seem to find a way to use redirect_to to send the user to a non-...

Apache authentication: Redirect on failure, reliably?

I ve set my ErrorDocument 401 to point to my website s account creation page, but not all browsers seem to honor this redirect (Safari). Also, other browsers (Firefox, Chrome) never quit asking for ...

Response.Redirect HTTP status code

Why is it that ASP/ASP.NET Response.Redirect uses a HTTP-302 status code ("Moved Temporarily") even though in most cases a HTTP-301 status code ("Moved Permanently") would be more appropriate?

Exceptions: redirect or render?

I m trying to standardize the way I handle exceptions in my web application (homemade framework) but I m not certain of the "correct" way to handle various situations. I m wondering if there is a ...

Cakephp is not redirecting properly when pages are cached

I am having some issues with a site that was working correctly until i implemented full page caching in CakePHP. I have followed the guidance in the Manual and have my $session->flash in a no-cache ...