1 2 Previous Next 27 Replies Latest reply on Apr 30, 2007 11:42 AM by sreejag

    Ajax4jsf and dataTable question

      I am new to JSF and facing few problems in solving this.
      My question is I have a dataTable with columns ProdCode,ProposedPrice and ProposedGrossMargin.In which ProposedPrice and ProposedGrossMargin are editable columns.
      If I change value of ProposedPrice of a particular row then it should dynamically update ProposedGrossmargin column of that row and at the same time it should also be saved in the database.
      Please could any body help me how to do this using ajax4jsf.
      please save me, any help is highly appreciated.

      Thanks and regards
      Kristein

        • 1. Re: Ajax4jsf and dataTable question
          ilya_shaikovsky
          • 2. Re: Ajax4jsf and dataTable question

            Thanks ilya_shaikovsky,

            I'll try to solve my problem using the examples mentioned above

            • 3. Re: Ajax4jsf and dataTable question

              Hi,
              I've a question
              do I need to use Facelet's <ui:repeat> tag for using the <a4j:repeat> component?

              I have a dataTable with columns ProdCode,ProposedPrice and ProposedGrossMargin.In which ProposedPrice and ProposedGrossMargin are editable columns.
              If I change value of ProposedPrice of a particular row then it should dynamically update ProposedGrossmargin column of that row.

              Now, how to use the <a4j:repeat> tag around the <h:inputText> tag.I am in very much confused state.I am new to ajax4jsf, I don't have any knowledge about this before.
              Please.. help me how to do this with a piece of code.
              Any help is highly appreciated

              • 4. Re: Ajax4jsf and dataTable question

                please anybody help me to solve this problem.

                thanks and regards
                kristien

                • 5. Re: Ajax4jsf and dataTable question

                  Your use case is more about using a4j:support than a4j:repeat.
                  I am not sure I exactly understand the example. As far as I understand, both ProposedPrice and ProposedGrossMargin are input fields. So, if ProposedGrossMargin is calculated based on ProposedPrice how it is possible the user can edit ProposedGrossMargin also manually after it is calculated?

                  • 6. Re: Ajax4jsf and dataTable question

                    Thanks for your reply SergeySmirnov,

                    You are right,ProposedPrice and ProposedGrossMargin are input fields and
                    ProposedGrossMargin is calculated based on ProposedPrice for the particular row of that column.My requirement is once the user enters the price in ProposedPrice field the ProposedGrossMargin shoud be calculated immeadiately for that row.
                    ProposedGrossMargin= (ProposedPrice-SalesCost)/ProposedPrice
                    where Sales Cost is also one of the column.

                    I am new to ajax4jsf and having problem in understanding this.
                    Please help me how to do this using ajax4jsf with a piece of code.

                    thanks and regardsd
                    Kristien

                    • 7. Re: Ajax4jsf and dataTable question

                      I am still confused with one detail.

                      So, if
                      ProposedGrossMargin= (ProposedPrice-SalesCost)/ProposedPrice

                      why ProposedGrossMargin is still a writable field. Does user are able to correct ProposedGrossMargin because she does not trust to formula ?

                      • 8. Re: Ajax4jsf and dataTable question

                        once again thanks for your kind reply SergeySmirnov,

                        I got the requirement like that.
                        Ok, I will make the ProposedGrossmargin field as outputText field.
                        please.. can you help me how to do this.

                        • 9. Re: Ajax4jsf and dataTable question

                          I will try to do it today.

                          • 10. Re: Ajax4jsf and dataTable question

                            Thank you very very much friend.

                            • 11. Re: Ajax4jsf and datatable question

                              This is an example that uses rich:dataTable

                              http://livedemo.exadel.com/richfaces-art-dataTable/pages/example10.jsf

                              <h:form id="form">
                               <rich:dataTable value="#{salesReport.items}" var="item">
                               <f:facet name="header">
                               <rich:columnGroup>
                               <h:column>
                               <h:outputText value="Product Code" />
                               </h:column>
                               <h:column>
                               <h:outputText value="Proposed Price" />
                               </h:column>
                               <h:column>
                               <h:outputText value="Sales Cost" />
                               </h:column>
                               <h:column>
                               <h:outputText value="Proposed Gross Margin" />
                               </h:column>
                               </rich:columnGroup>
                               </f:facet>
                               <h:column>
                               <h:outputText value="#{item.productCode}" />
                               </h:column>
                               <h:column>
                               <h:inputText value="#{item.proposedPrice}" size="7">
                               <a4j:support event="onchange" reRender="margin" />
                               </h:inputText>
                               </h:column>
                               <h:column>
                               <h:outputText value="#{item.salesCost}" />
                               </h:column>
                               <h:column>
                               <h:outputText id="margin" value="#{item.proposedGrossMargin}">
                               <f:convertNumber pattern="$###0.000" />
                               </h:outputText>
                               </h:column>
                               </rich:dataTable>
                              
                              <a4j:outputPanel id="err" ajaxRendered="true">
                               <h:messages />
                              </a4j:outputPanel>
                              </h:form>


                              • 12. Re: Ajax4jsf and dataTable question

                                Many thanks for your reply SergeySmirnov,
                                This is what exactly I needed.But now I've few question to ask you.

                                1)Can I do this without using rich:dataTable.If I should use rich:dataTable then simply Copy the "richfaces-3.0.x.jar" file into the "WEB-INF/lib" folder of my application and add

                                <%@ taglib uri="http://richfaces.ajax4jsf.org/rich" prefix="rich"%> on each jsp page.

                                2)When I change ProposedPrice field value, the ProposedPrice value have to be saved in the DTO at the same time so that it should also shown on some other page.How to update the DTO onchange for the particular row of that column.

                                3)Where can I get the source code for the example you mentioned above.

                                I am asking you somuch,sorry I don't have any other source.
                                Please help me in solving this

                                once again thanks for your kind help.

                                thanks and regards
                                kristein

                                • 13. Re: Ajax4jsf and dataTable question

                                  There is no different between rich:dataTable and a4j:repeat, but just a formating. You need to take care about it by yourself.

                                  <a4j:repeat value="#{salesReport.items}" var="item">
                                   <h:inputText value="#{item.proposedPrice}" size="7">
                                   <a4j:support event="onchange" reRender="margin" />
                                   </h:inputText>
                                  
                                   <h:outputText id="margin" value="#{item.proposedGrossMargin}">
                                   <f:convertNumber pattern="$###0.000" />
                                   </h:outputText>
                                   <f:verbatim><br /></f:verbatim>
                                  </a4j:repeat>


                                  • 14. Re: Ajax4jsf and dataTable question

                                    Thanks for reply,

                                    When I change ProposedPrice field value, the ProposedPrice value have to be saved in the DTO at the same time so that it should also shown on some other page.How to update the DTO, onchange for the particular row of that column.


                                    thanks and regards
                                    kristein

                                    1 2 Previous Next