12 Replies Latest reply on Feb 20, 2009 11:46 AM by nbelaevski

    Problem with retrieving updated information from back bean

    andrew_st

      Hello,

      I would appreciate a lot your support in solving the following "newbie" problem.

      I use rich:calendar to set some date and send it to some service in backbean on clicking some commandButton. The service gets currency exchange course and supposedly should send it to jsp without jsp reloading. Alas, all I succeded to reach so far is that by selecting a new date and clicking the button I receive currency rates for the previously selected date. Though in console I'm getting the currency rates for the last selected date

      My latest code is as follows:

      <a4j:form>
      ...
      <rich:calendar value="#{calculator.selectedDate}">
      <a4j:support event="onchanged"/>
      </rich:calendar>
      ...
      <a4j:commandButton id="getCourseButton" value="Fetch Currency Rates" immediate="true" actionListener="#{calculator.fetchCourse}" reRender="euroRate, usdRate"/>
      ...
      <h:outputText id="euroRate" value="#{calculator.euroRate}">
      <h:outputText id="usdRate" value="#{calculator.usdRate}">


      It must be very basic but I'm stucked.

      Thank you a lot in advance.

        • 1. Re: Problem with retrieving updated information from back be
          nbelaevski

          Hello,

          Your code seems to be ok. Are you using RF 3.3.0?

          • 2. Re: Problem with retrieving updated information from back be
            andrew_st

            Yes, I do
            I use 3.3.0

            • 3. Re: Problem with retrieving updated information from back be
              nbelaevski

              Please post full page and bean code.

              • 4. Re: Problem with retrieving updated information from back be
                andrew_st

                Hello again,

                jsp:


                <%--<f:loadBundle basename="LocalizationResources" var="bundle"/>--%>
                <f:view>
                <a4j:form>
                <rich:calendar value="#{calculator.selectedDate}">
                <a4j:support event="onchanged"/>
                </rich:calendar>

                Кур� валют
                <h:selectOneRadio id="radioList" value="0" layout="pageDirection" valueChangeListener="#{calculator.selectRateSource}">



                <f:selectItem itemValue="0" itemLabel="У�тановить кур�ы валют по ЦБ на дату" />


                <a4j:commandButton id="getCourseButton" value="Получить кур� валют" immediate="true" actionListener="#{calculator.fetchCourse}" reRender="euroRate, usdRate"/>

                <%--

                <h:commandButton id="getCourseButton" value="Получить кур� валют" immediate="true">
                <a4j:support actionListener="#{calculator.fetchCourse}" event="onclick" reRender="euroRate, usdRate" disableDefault="true"/>
                </h:commandButton>

                --%>


                <f:selectItem itemValue="1" itemLabel="У�тановить кур�ы валют вручную" />
                </h:selectOneRadio>

                <h:panelGroup id="rates" rendered="true"> <!-- Возможно, и не нужно -->


                <h:outputLabel value="Кур� евро" for="euroRate" />
                <h:outputText id="euroRate" value="#{calculator.euroRate}"></h:outputText>
                <h:message for="euroRate" />


                <h:outputLabel value="Кур� доллара" for="usdRate" />

                <h:outputText id="usdRate" value="#{calculator.usdRate}"></h:outputText>
                <h:message for="usdRate" />


                </h:panelGroup>

                <h:commandButton id="setCoursesButton" actionListener="#{calculator.setCourses}" value="У�тановить кур� валют" />



                Параметры

                <h:dataTable value="#{calculator.parameterList}" var="parameters" border="1">
                <h:column>
                <f:facet name="header">
                <h:outputText value="�аименование"/>
                </f:facet>
                <%-- h:inputText потребуют также valueChangeListener="" --%>
                <h:inputText value="#{parameters.name}" />
                </h:column>
                <h:column>
                <f:facet name="header">
                <h:outputText value="�азвание"/>
                </f:facet>
                <h:inputText value="#{parameters.abbrev}" />
                </h:column>
                <h:column>
                <f:facet name="header">
                <h:outputText value="Значение"/>
                </f:facet>
                <h:inputText value="#{parameters.value}">
                <f:convertNumber type="currency"/>
                </h:inputText>
                </h:column>
                <h:column>
                <f:facet name="header">
                <h:outputText value="Примечание"/>
                </f:facet>
                <h:inputText value="#{parameters.comment}" />
                </h:column>
                </h:dataTable>

                <h:commandButton actionListener="#{calculator.addParameter}" id="addParamButton" value="Добавить параметр" />
                <h:commandButton actionListener="#{calculator.deleteParameter}" id="deleteParamButton" value="Удалить параметр" />



                </a4j:form>
                </f:view>

                • 5. Re: Problem with retrieving updated information from back be
                  andrew_st

                  I'm sorry for the mess.
                  I will post corrected version tomorrow.
                  Please check again for this post tomorrow

                  • 6. Re: Problem with retrieving updated information from back be
                    nbelaevski

                     

                    "andrew_st" wrote:
                    Hello again,

                    jsp:
                     <body>
                     <%--<f:loadBundle basename="LocalizationResources" var="bundle"/>--%>
                     <f:view>
                     <a4j:form>
                     <rich:calendar value="#{calculator.selectedDate}">
                     <a4j:support event="onchanged"/>
                     </rich:calendar>
                     <fieldset>
                     <legend>�šÑƒÑ€Ñ� �²�°�»ÑŽÑ‚</legend>
                     <h:selectOneRadio id="radioList" value="0" layout="pageDirection" valueChangeListener="#{calculator.selectRateSource}">
                     <table>
                     <tr>
                     <td>
                     <f:selectItem itemValue="0" itemLabel="�£Ñ�т�°�½�¾�²�¸Ñ‚ÑŒ �ºÑƒÑ€Ñ�ы �²�°�»ÑŽÑ‚ �¿�¾ �¦�‘ �½�° �´�°Ñ‚у" />
                     </td>
                     <td>
                     <a4j:commandButton id="getCourseButton" value="�Ÿ�¾�»ÑƒÑ‡�¸Ñ‚ÑŒ �ºÑƒÑ€Ñ� �²�°�»ÑŽÑ‚" immediate="true" actionListener="#{calculator.fetchCourse}" reRender="euroRate, usdRate"/>
                     </td>
                     <%--
                     <td>
                     <h:commandButton id="getCourseButton" value="�Ÿ�¾�»ÑƒÑ‡�¸Ñ‚ÑŒ �ºÑƒÑ€Ñ� �²�°�»ÑŽÑ‚" immediate="true">
                     <a4j:support actionListener="#{calculator.fetchCourse}" event="onclick" reRender="euroRate, usdRate" disableDefault="true"/>
                     </h:commandButton>
                     </td>
                     --%>
                     </tr>
                     </table>
                     <f:selectItem itemValue="1" itemLabel="�£Ñ�т�°�½�¾�²�¸Ñ‚ÑŒ �ºÑƒÑ€Ñ�ы �²�°�»ÑŽÑ‚ �²Ñ€ÑƒÑ‡�½ÑƒÑŽ" />
                     </h:selectOneRadio>
                    
                     <h:panelGroup id="rates" rendered="true"> <!-- �’�¾�·�¼�¾�¶�½�¾, �¸ �½�µ �½Ñƒ�¶�½�¾ -->
                     <table>
                     <tr>
                     <td><h:outputLabel value="�šÑƒÑ€Ñ� �µ�²Ñ€�¾" for="euroRate" /></td>
                     <td><h:outputText id="euroRate" value="#{calculator.euroRate}"></h:outputText></td>
                     <td><h:message for="euroRate" /></td>
                     </tr>
                     <tr>
                     <td><h:outputLabel value="�šÑƒÑ€Ñ� �´�¾�»�»�°Ñ€�°" for="usdRate" />
                     </td>
                     <td><h:outputText id="usdRate" value="#{calculator.usdRate}"></h:outputText></td>
                     <td><h:message for="usdRate" /></td>
                     </tr>
                     </table>
                     </h:panelGroup>
                     <div id="buttonSetCourses">
                     <h:commandButton id="setCoursesButton" actionListener="#{calculator.setCourses}" value="�£Ñ�т�°�½�¾�²�¸Ñ‚ÑŒ �ºÑƒÑ€Ñ� �²�°�»ÑŽÑ‚" />
                     </div>
                     </fieldset>
                     <fieldset>
                     <legend>�Ÿ�°Ñ€�°�¼�µÑ‚ры</legend>
                     <div id="parameters">
                     <h:dataTable value="#{calculator.parameterList}" var="parameters" border="1">
                     <h:column>
                     <f:facet name="header">
                     <h:outputText value="���°�¸�¼�µ�½�¾�²�°�½�¸�µ"/>
                     </f:facet>
                     <%-- h:inputText �¿�¾Ñ‚Ñ€�µ�±ÑƒÑŽÑ‚ т�°�º�¶�µ valueChangeListener="" --%>
                     <h:inputText value="#{parameters.name}" />
                     </h:column>
                     <h:column>
                     <f:facet name="header">
                     <h:outputText value="���°�·�²�°�½�¸�µ"/>
                     </f:facet>
                     <h:inputText value="#{parameters.abbrev}" />
                     </h:column>
                     <h:column>
                     <f:facet name="header">
                     <h:outputText value="�—�½�°Ñ‡�µ�½�¸�µ"/>
                     </f:facet>
                     <h:inputText value="#{parameters.value}">
                     <f:convertNumber type="currency"/>
                     </h:inputText>
                     </h:column>
                     <h:column>
                     <f:facet name="header">
                     <h:outputText value="�ŸÑ€�¸�¼�µÑ‡�°�½�¸�µ"/>
                     </f:facet>
                     <h:inputText value="#{parameters.comment}" />
                     </h:column>
                     </h:dataTable>
                     <div>
                     <h:commandButton actionListener="#{calculator.addParameter}" id="addParamButton" value="�”�¾�±�°�²�¸Ñ‚ÑŒ �¿�°Ñ€�°�¼�µÑ‚Ñ€" />
                     <h:commandButton actionListener="#{calculator.deleteParameter}" id="deleteParamButton" value="�£�´�°�»�¸Ñ‚ÑŒ �¿�°Ñ€�°�¼�µÑ‚Ñ€" />
                     </div>
                     </div>
                     </fieldset>
                     </a4j:form>
                     </f:view>
                     </body>


                    Why wait until tomorrow? :)

                    • 7. Re: Problem with retrieving updated information from back be
                      andrew_st

                      Oh, I see now that the main things are clear despite the unconverted cyrillics.

                      Here is the action listener attached to <h:commandButton id="getCourseButton"... />:

                      public void fetchCourse(ActionEvent event) {

                      Thread t = new Thread() {

                      public void run() {
                      CBRFCurrencyCourse cbrfCourse = new CBRFCurrencyCourse();
                      DateCurrencyCourse course = null;
                      //Date dateLocal = new Date(System.currentTimeMillis());
                      System.out.println("The user selected date: " + getSelectedDate());
                      try {
                      course = cbrfCourse.getDateCurrencyCourse(getSelectedDate());
                      setEuroRate(Double.toString(course.getCurrency().get(Currency.EUR)));
                      setUsdRate(Double.toString(course.getCurrency().get(Currency.USD)));
                      System.out.println("Euro rate: " + getEuroRate());
                      System.out.println("USD rate: " + getUsdRate());
                      } catch (TravelCostException ex) {
                      String message = bundle.getString(ex.getResource());
                      } finally {
                      //progress bar dissappears
                      }
                      }
                      };
                      t.start();
                      }



                      Dear Mr. Belaevski,
                      I would appreciate a lot your help.

                      • 8. Re: Problem with retrieving updated information from back be
                        andrew_st

                        Let me remind you the snippet for the commandButton which activates currency rate fetching and supposedly should have to update outputText fields:

                        <a4j:commandButton id="getCourseButton" value="Fetch currency rates" immediate="true" actionListener="#{calculator.fetchCourse}" reRender="euroRate, usdRate"/>

                        • 9. Re: Problem with retrieving updated information from back be
                          andrew_st

                          May be I have to ajaxify somehow outputText fields in addition to reRender attribute in commandButton firing the action ?

                          • 10. Re: Problem with retrieving updated information from back be
                            andrew_st

                            I have tried to use <a4j:outputPanel where I have put outputText. It did not work as needed either :(

                            • 11. Re: Problem with retrieving updated information from back be
                              andrew_st

                              I tried to put outputText inside a4j:outputPanel.
                              it did not work either :(

                              • 12. Re: Problem with retrieving updated information from back be
                                nbelaevski

                                This:

                                <h:form>
                                 <rich:calendar value="#{forum5Bean.testDate}">
                                 <a4j:support event="onchanged"/>
                                 </rich:calendar>
                                
                                 <a4j:commandButton value="Get" immediate="true" actionListener="#{forum5Bean.printDate}"/>
                                 </h:form>
                                

                                public void printDate(ActionEvent actionEvent) {
                                 System.out.println(testDate);
                                 }

                                works ok for me on 3.3.0.GA. I saw one problem in your code: a4j:support nested inside h:commandButton and this support is not immediate="true". Could this be the reason?