3 Replies Latest reply on Sep 4, 2009 3:59 AM by ilya_shaikovsky

    Ajax - Format query result

      Hey,

      I am having some issues with the AJAX functionality.

      I have 2 output fields, which I have to fill through DB queries. The user selects a date and each time the date is selected a query to the database is fired. I was able to update the "first" field but I have problems with updating the "second" field.

      Right now I am using a simple String as the output, but I can't seem to format it at all. I tried adding a br tag, but it doesn't work.

      Is there a way to format the Strings? What am I missing?

      <a4j:outputPanel id="out" ajaxRendered="true">
       <h:panelGrid styleClass="ajax">
       <h:outputText id="first" value="Output: #{my.ajaxvalue}" />
       </h:panelGrid>
      </a4j:outputPanel>
      
      <rich:calendar id="dateFrom" value="#{my.calValueBegin}"
      validator="#{my.validator}" enableManualInput="true" popup="true" required="true" valueChangeListener="#{my.change}">
       <a4j:support event="oninputchange" reRender="dateFrom, second" />
       <a4j:support event="onchanged" reRender="dateFrom, second" />
      </rich:calendar><rich:message for="dateFrom" />
      
      <rich:calendar id="dateTo" value="#{my.calValueEnd}" enableManualInput="true" popup="true"
      validator="#{my.validator}" required="true" valueChangeListener="#{my.change}">
       <a4j:support event="oninputchange" reRender="first, second" />
       <a4j:support event="onchanged" reRender="first, second" />
      </rich:calendar><rich:message for="dateTo" />
      
      <h:outputText id="second" value="#{my.queryValue}" />


      public void change(ValueChangeEvent event) {
      Date selected = (Date) event.getNewValue();
      // Fill #{my.ajaxvalue}" (String)
      // Fill #{my.queryValue} (String)
      ...
      }


        • 1. Re: Ajax - Format query result
          ilya_shaikovsky

          how br should help you in format? Do you mean some layout roblem or the format of date displayed in outputTExt? if the second problem is your check f:convert tags.

          • 2. Re: Ajax - Format query result

            Yes, I mean a general layout problem after calculation. I played around with it and solved the problem by adding a datalist element to the page.

            However I still do have a general question:
            I have added a new element to the same page and I observe it with the a4j:support tag. I switched the event to "onkeyup", so each time the user puts in a key, it validates the field. What I don't understand is, why does it update all the other ajax fields on my page every time I type something in? Is it because of the ajaxRendered="true"?

            • 3. Re: Ajax - Format query result
              ilya_shaikovsky

              yes. this special attirbute tells that outuput panel should be updated on any ajax request