f:ajax监听器不重定向页面,而p:ajax工作正常

时间:2015-11-27 13:56:45

标签: ajax jsf redirect primefaces

我在表单中有两个下拉菜单,在第一个菜单上更改第二个菜单刷新的值(AJAX)然后我可以使用一个按钮来提交表单,该按钮在视图范围内的bean中执行某些操作在完成重定向到成功页面时,我遇到了一个我无法弄清楚的问题

也就是说,当我使用<f:ajax>标签时:

  1. 当我在不更改菜单的情况下提交表单时,会执行操作并正常重定向。
  2. 当我更改菜单并单击“提交”按钮时,将执行操作,但页面永远不会重定向
  3. 当使用<p:ajax>标签时,它按预期工作,我现在已经搜索了一段时间,我想问题是关于请求ajax但是我无法确定具体原因,这是页面上的一个片段。

    XHTML

        <div class="col-xs-12 col-sm-12 col-md-4 col-lg-4">
            <div class="form-group arabic">
                <h:selectOneMenu id="governorates" required="true"
                                            requiredMessage="#{msgBean.getRequired()}"
                                            styleClass="btn btn-white dropdown-toggle" style="width:100%"
                                            value="#{propertyBean.property.propertyDetails.governate}"
                                            converter="#{governateConverter}">
                    <f:selectItem itemValue="#{null}" itemLabel="اختر المحافظة"
                                                noSelectionOption="true" />
                    <f:selectItems value="#{dataBean.availableGovernates}"
                                                var="governateObj" itemValue="#{governateObj}"
                                                itemLabel="#{governateObj.name}"/>
                    <p:ajax listener="#{propertyBean.setValidCities}"
                                                update="governorate_message cities" />
                </h:selectOneMenu>
                <h:message id="governorate_message" for="governorates"
                                            infoClass="help-block" errorClass="help-block error" />
            </div>
        </div>
        <div class="col-xs-12 col-sm-12 col-md-4 col-lg-4">
    
            <div class="form-group arabic">
                <h:selectOneMenu id="cities" required="true"
                                            requiredMessage="#{msgBean.getRequired()}"
                                            styleClass="btn btn-white dropdown-toggle" style="width:100%"
                                            value="#{propertyBean.property.propertyDetails.city}"
                                            converter="#{cityConverter}">
                    <f:selectItem itemValue="#{null}" itemLabel="اختر المدينة"
                                                noSelectionOption="true" />
                    <f:selectItems value="#{propertyBean.validCities}"
                                                var="cityObj" itemValue="#{cityObj}"
                                                itemLabel="#{cityObj.name}"/>
                    <p:ajax update="cities" />
    
                </h:selectOneMenu>
                <h:message id="city_message" for="cities" infoClass="help-block"
                                            errorClass="help-block error" />
            </div>
        </div>
    <h:commandButton id="update" value="تعديل"
                                onclick="if( validate('submitForm')==true){ updateProperty();} else{ return false;}"
                                action="#{propertyBean.update}"
                                class="btn btn-green btn-lg arabic"
                                rendered="#{propertyBean.isNew == false}">
                                <f:param name="propertyId" value="#{propertyBean.property.id}">
                                </f:param>
                            </h:commandButton>
    

    Java类

    public String update() {
            System.out.println("updating");
                return navBean.redirectToSuccess();
            }
    

    使用<f:ajax>代码

    <div class="col-xs-12 col-sm-12 col-md-4 col-lg-4">
        <div class="form-group arabic">
            <h:selectOneMenu id="governorates" required="true"
                requiredMessage="#{msgBean.getRequired()}"
                styleClass="btn btn-white dropdown-toggle" style="width:100%"
                value="#{propertyBean.property.propertyDetails.governate}"
                converter="#{governateConverter}">
                <f:selectItem itemValue="#{null}" itemLabel="اختر المحافظة"
                    noSelectionOption="true" />
                <f:selectItems value="#{dataBean.availableGovernates}"
                    var="governateObj" itemValue="#{governateObj}"
                    itemLabel="#{governateObj.name}"/>
                <f:ajax event="blur"  listener="#{propertyBean.setValidCities}" render="governorate_message cities" />
            </h:selectOneMenu>
            <h:message id="governorate_message" for="governorates"
                infoClass="help-block" errorClass="help-block error" />
        </div>
    </div>
    

    使用f:ajax

    时,浏览器网络会显示以下内容

    请求:

    POST /Newgar_revamp/pages/add.xhtml HTTP/1.1
    Host: localhost:8080
    Connection: keep-alive
    Content-Length: 2207
    Pragma: no-cache
    Cache-Control: no-cache
    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
    Origin: http://localhost:8080
    Upgrade-Insecure-Requests: 1
    User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.86 Safari/537.36
    Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryFE3725BjJXsA1xKf
    Referer: http://localhost:8080/Newgar_revamp/pages/add.xhtml?propertyId=3
    Accept-Encoding: gzip, deflate
    Accept-Language: en-GB,en-US;q=0.8,en;q=0.6,ar;q=0.4
    Cookie: JSESSIONID=B81FF21F23988CC8C98D84DA14B36F54
    

    响应:

    HTTP/1.1 302 Found
    Server: Apache-Coyote/1.1
    Location: http://localhost:8080/Newgar_revamp/pages/status/success.xhtml
    Content-Length: 0
    Date: Fri, 20 Nov 2015 21:24:32 GMT
    

    但浏览器永远不会重定向到成功页面

0 个答案:

没有答案