Jsf PrimeFaces commandButton需要验证两个日历组件,然后将包含两个日历值的外部URL重定向到新页面

Jsf PrimeFaces commandButton需要验证两个日历组件,然后将包含两个日历值的外部URL重定向到新页面,jsf,redirect,primefaces,Jsf,Redirect,Primefaces,我不熟悉JSF和primefaces,我正在尝试做以下工作:我必须创建一个包含两个日期的URL,然后在新页面中打开它。我使用primefaces,所以我创建了两个p:calendar组件和一个p:commandButton 我的问题是,我设法验证了日历,然后打开了URL,但在同一个窗口中。如果我将ajax=“false”设置为commandbutton,将target=“\u blank”设置为表单,则会在新页面中打开URL,但如果日历值无效,则还会在新页面中打开原始页面,并显示验证消息。对于重

我不熟悉JSF和primefaces,我正在尝试做以下工作:我必须创建一个包含两个日期的URL,然后在新页面中打开它。我使用primefaces,所以我创建了两个p:calendar组件和一个p:commandButton

我的问题是,我设法验证了日历,然后打开了URL,但在同一个窗口中。如果我将ajax=“false”设置为commandbutton,将target=“\u blank”设置为表单,则会在新页面中打开URL,但如果日历值无效,则还会在新页面中打开原始页面,并显示验证消息。对于重定向,我在bean中使用FacesContext.getCurrentInstance().getExternalContext().redirect(URL)

我还尝试使用h:outputLink重定向,并将其值设置为bean.url和target=“\u blank”。它重定向到一个新页面,但在本例中,我没有设法验证日历

我该怎么做?

谢谢

使用
窗口有条件地呈现
。打开()
,具体取决于验证:

<h:form>
    <p:calendar validator="yourValidator" />
    <p:calendar validator="yourValidator" />
    <p:commandButton action="#{bean.submit}" update="@form" />
    <h:outputScript rendered="#{facesContext.postback and not facesContext.validationFailed}">
        window.open('someURL');
    </h:outputScript>
</h:form>

使用
窗口有条件地呈现
。打开()
,具体取决于验证:

<h:form>
    <p:calendar validator="yourValidator" />
    <p:calendar validator="yourValidator" />
    <p:commandButton action="#{bean.submit}" update="@form" />
    <h:outputScript rendered="#{facesContext.postback and not facesContext.validationFailed}">
        window.open('someURL');
    </h:outputScript>
</h:form>

感谢您的回复,但是window.open会将url作为内部页面()打开,但我只需要打开url本身。我不确定是否理解您的意思。然后打开URL本身?例如,如果我运行以下命令:RequestContext.getCurrentInstance().execute(“window.open('www.google.com');”);,那么它就不会打开谷歌网站。你应该用这个方案指定一个绝对URL,否则它当然是相对于当前URL的。谢谢,我不知道为什么我没有想到。谢谢你的回复,但是window.open会将URL作为一个内部页面()打开,但我只需要打开URL本身。我不确定我是否理解你。然后打开URL本身?例如,如果我运行以下命令:RequestContext.getCurrentInstance().execute(“window.open('www.google.com');”);,那么它就不会打开谷歌网站。你应该用这个方案指定一个绝对URL,否则它当然是相对于当前URL的。谢谢,我不知道为什么我没有想到这一点。