8 Replies Latest reply on Dec 8, 2009 3:53 AM by benterich

    Ajax-Request: Control the URL

      Hi,

      I've run into another problem concerning our setup and ajax requests. Our setup involves

      - JSF 1.2 (Apache MyFaces 1.2.7)
      - Facelets 1.1.14
      - RichFaces 3.3.3
      - running on Glassfish.

      RichFaces runs fine, all script includes are generated perfectly. Now I've got this button whose purpose it is to update two input fields after a selection on a drop down box via ajax.

      <h:selectOneMenu style="width:150px;" name="queryInterval" id="jq_queryInterval" immediate="true" value="#{my.queryInterval}" valueChangeListener="#{myManagedBean.intervalChanged}">
       <f:selectItems value="#{myManagedBean.validQueryIntervals}" />
       <a4j:support event="onchange" reRender="jq_pmDateFrom, jq_pmDateTill" />
      </h:selectOneMenu>
      


      So far so good, after changing in the select box a request to our server is started. Because we have a webserver in front of the appserver, that does some rewriting and xsl transformations, we need to bypass the webserver for this special request, i.e.: the ajax request generated must have some kind of detectable prefix/suffix, so we can directly rout it to the app server.

      Is there a way to do that? To control, which request url is taken for an Ajax-Request with Ajax4JSF? Or is it always the current (see browser adress bar) URL?

      Again, any pointers are welcome.

      Thanks in advance, regards.
      Christian

        • 1. Re: Ajax-Request: Control the URL

          Any ideas?
          Really depending on that, until now, Ajax just doesn't work for us.

          To rephrase the problem:
          Is it possible to control the URL for the request that is issued by RichFaces (via Ajax4JSF)?

          Regards,
          Christian

          • 2. Re: Ajax-Request: Control the URL
            ilya_shaikovsky

            post for ajax request contains AJAXREQUEST variable.

            • 3. Re: Ajax-Request: Control the URL

              Thank you Ilya, we take this now to decide, if we have an ajax request. So far it works, ajax request is routed correctly on the server and a (in my opinion) correct response is delivered to the browser.

              Just the browser does not rerender as he should. In the a4j.log we get the ominous lines:
              error[10:22:13,872]: Error parsing XML
              error[10:22:13,872]: Parse Error: Document is empty

              and nothing is rerendered. I'll post the complete log output for the response, maybe someone can help me with this:

              debug[10:22:13,871]: Response with content-type: text/html;charset=UTF-8
              debug[10:22:13,871]: Full response content: <html lang="de"><head><title></title><meta name="Ajax-Update-Ids" content="docSearchForm:jq_pmDateFrom"><meta id="Ajax-Response" name="Ajax-Response" content="true"><meta name="Ajax-Update-Ids" content="docSearchForm:jq_pmDateFrom"><meta id="Ajax-Response" name="Ajax-Response" content="true"><link class="component" href="/org/richfaces/renderkit/html/css/basic_classes.xcss/DATB/eAELXT5DOhSIAQ!sA18_.jsf" rel="stylesheet" type="text/css"><link class="component" href="/org/richfaces/renderkit/html/css/extended_classes.xcss/DATB/eAELXT5DOhSIAQ!sA18_.jsf" media="rich-extended-skinning" rel="stylesheet" type="text/css"><script src="/org.ajax4jsf.javascript.AjaxScript.jsf" type="text/javascript"> </script><script src="/org/richfaces/renderkit/html/scripts/jquery/jquery.js.jsf" type="text/javascript"> </script><script src="/org/richfaces/renderkit/html/scripts/skinning.js.jsf" type="text/javascript"> </script></head><body><input id="docSearchForm:jq_pmDateFrom" name="docSearchForm:jq_pmDateFrom" type="text" value="05.10.2009"><span id="ajax-view-state"><input type="hidden" name="javax.faces.ViewState" id="javax.faces.ViewState" value="zCxxR1bustLziO9eOGlrLdz+VNNWG+jPPUcXRVccZFbdAP1pEMqRAwVqOPYICjVV7tMnLqhlUrypk7u1Yl6OEwZ9H71BkdcIe9KU18a2QkVHiTt2vckScCcILa9OkNyFrWSW1x90ak/UZGRJZ3+sG31We7bKnmTSwyWyq4TM4vknoYvEr/FYinH6L2MVZHQc"></span><span id="ajax-view-state"><input type="hidden" name="javax.faces.ViewState" id="javax.faces.ViewState" value="zCxxR1bustLziO9eOGlrLdz+VNNWG+jPPUcXRVccZFbdAP1pEMqRAwVqOPYICjVV7tMnLqhlUrypk7u1Yl6OEwZ9H71BkdcIe9KU18a2QkVHiTt2vckScCcILa9OkNyFrWSW1x90ak/UZGRJZ3+sG31We7bKnmTSwyWyq4TM4vknoYvEr/FYinH6L2MVZHQc"></span></body></html>
              debug[10:22:13,872]: Header Ajax-Expired not found, search in <meta>
              error[10:22:13,872]: Error parsing XML
              error[10:22:13,872]: Parse Error: Document is empty
              


              As far as I can see, the response is correct:
              - correct content type
              - complete html page
              - correct update ids
              - correct update content

              The only thing I'm seeing is, that the response is not valid XHTML (meta and link tags are unbalanced). Could that be the problem? How could I fix this?

              The A4J-Filter is configured to always parse (forceparser=true), but AJAX-requests should produce valid XML in any case, right? Normal requests are valid XHTML too.

              Thanks for any pointers, regards.
              Christian

              • 4. Re: Ajax-Request: Control the URL

                Unfortunately no progress for us - still stuck with this.
                Ajax-Responses are not parsed - rerender does not work.

                Can it be something with the configured parsers? I'll post the filter config asap.

                Any help would be very welcome.

                • 5. Re: Ajax-Request: Control the URL

                  Filter config in web.xml

                  <!--
                   JSF: AJAX 4 JSF Filter to enhance facelets with AJAX.
                   Must be first in filter chain.
                   -->
                   <filter>
                   <filter-name>ajax4jsfFilter</filter-name>
                   <display-name>Ajax4jsf Filter</display-name>
                   <description>Adds ajax functionality to the application</description>
                   <filter-class>org.ajax4jsf.Filter</filter-class>
                   <!-- Force XML parsing (or XSLT transformation will not work). -->
                   <init-param>
                   <param-name>forceparser</param-name>
                   <param-value>true</param-value>
                   </init-param>
                   <init-param>
                   <param-name>mime-type</param-name>
                   <param-value>text/html</param-value>
                   </init-param>
                   </filter>
                  


                  • 6. Re: Ajax-Request: Control the URL
                    nbelaevski

                    Hi,

                    Try another mime-type, e.g. "application/xhtml+xml"

                    • 7. Re: Ajax-Request: Control the URL

                      Thanks for your answer. Unfortunately this produces this response:

                      debug[14:20:49,788]: Full response content: <!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"><head><META http-equiv="Content-Type" content="text/html; charset=UTF-8"> </head></html>
                      debug[14:20:49,789]: Header Ajax-Expired not found, search in <meta>
                      error[14:20:49,789]: Error parsing XML
                      error[14:20:49,790]: Parse Error: Document is empty
                      


                      This does not look like a correct ajax response.

                      • 8. Re: Ajax-Request: Control the URL

                        Finally we got this right, it all depends on the content type. The webserver always produced text/html which is unrecognized by the javascript ajax layer of a4j. Tuning the webserver to pass ajax responses through wielded the correct result.

                        Thanks to everyone for support.