1 2 Previous Next 27 Replies Latest reply on Apr 30, 2007 11:42 AM by sreejag Go to original post
      • 15. Re: Ajax4jsf and dataTable question

        it depends of how you organize your data model. When the data comes from the page and validation is Ok, the corresponded setters will be invoked.

        • 16. Re: Ajax4jsf and dataTable question

          Thanks for reply,

          It will be great if you could explain briefly with a small piece of code
          Please...

          thanks and regards
          Kristien

          • 17. Re: Ajax4jsf and dataTable question

            Hi SergeySmirnov,

            Please can you post the source code for the example, example10.jsf and
            Salesreport.java. I have few problems testing the example10.jsf.

            thanks and regards
            Kristein

            • 18. Re: Ajax4jsf and dataTable question

              I am going to commit this example to svn tomorrow.

              Those are the beans:

              package org.rf.datatable;
              
              import java.util.ArrayList;
              import java.util.List;
              
              public class SalesReport {
               List items = null;
              
               public List getItems() {
               if (items == null)
               initData();
               return items;
               }
              
               public void setItems(List items) {
               this.items = items;
               }
              
               private void initData() {
               items = new ArrayList();
               items.add(new SalesItem(1, 20.00));
               items.add(new SalesItem(2, 10.00));
               items.add(new SalesItem(3, 20.00));
               items.add(new SalesItem(4, 20.00));
               }
              }
              



              package org.rf.datatable;
              
              public class SalesItem {
               private int productCode;
               private double proposedPrice;
               private double ProposedGrossMargin;
               private double salesCost;
               public SalesItem(int productCode, double salesCost) {
               super();
               this.productCode = productCode;
               this.salesCost = salesCost;
               }
               public int getProductCode() {
               return productCode;
               }
               public void setProductCode(int productCode) {
               this.productCode = productCode;
               }
               public double getProposedGrossMargin() {
               if (proposedPrice == 0)
               return 0;
               else {
               return (proposedPrice-salesCost)/proposedPrice ;
               }
               }
               public void setProposedGrossMargin(double proposedGrossMargin) {
               ProposedGrossMargin = proposedGrossMargin;
               }
               public double getProposedPrice() {
               return proposedPrice;
               }
               public void setProposedPrice(double proposedPrice) {
               this.proposedPrice = proposedPrice;
               }
               public double getSalesCost() {
               return salesCost;
               }
               public void setSalesCost(double salesCost) {
               this.salesCost = salesCost;
               }
              }
              


              • 19. Re: Ajax4jsf and dataTable question

                Hi SergeySmirnov,

                Your example is working fine.But when I am trying to implement the same logic in my application using the dao's,I am getting the exception.

                Here's the exception:

                java.lang.IllegalArgumentException: java.lang.ClassCastException@2fb3 java.lang.IllegalArgumentException: java.lang.ClassCastException@2fc6 java.lang.IllegalArgumentException: type mismatch java.lang.IllegalArgumentException: type mismatch java.lang.IllegalArgumentException: type mismatch java.lang.IllegalArgumentException: type mismatch java.lang.IllegalArgumentException: java.lang.ClassCastException@2fcd java.lang.IllegalArgumentException: java.lang.ClassCastException@2fce java.lang.IllegalArgumentException: type mismatch java.lang.IllegalArgumentException: java.lang.ClassCastException@2fcc java.lang.IllegalArgumentException: java.lang.ClassCastException@2fca java.lang.IllegalArgumentException: java.lang.ClassCastException@2fb8 java.lang.IllegalArgumentException: type mismatch java.lang.IllegalArgumentException: java.lang.ClassCastException@2fd2 java.lang.IllegalArgumentException: type mismatch


                Could you please tell where I am going wrong!

                • 20. Re: Ajax4jsf and dataTable question

                  Can say nothing yet base on the info you provided

                  • 21. Re: Ajax4jsf and dataTable question

                    ok,here are the code pieces.

                    jsp page


                    <!-- Spreadsheet panel -->
                    <h:panelGrid columns="1" rendered="#{!PriceModelHeaderBean.tableEmpty}" styleClass="layoutTable">
                    <rich:dataTable value="#{PriceModelHeaderBean.listDataModel}" var="item"
                     first="#{PriceModelHeaderBean.currentRowIndex}"
                     rows="#{PriceModelHeaderBean.rowsPerPage}"
                     styleClass="partDataTable" rowClasses="rowLight, rowDark" headerClass="dataHeader"
                     border="0" cellspacing="0">
                    <f:facet name="header">
                     <h:panelGrid columns="2" columnClasses="lAlign, rAlign" styleClass="pagerTable">
                     <h:panelGrid columns="5">
                     <h:commandButton action="#{PriceModelHeaderBean.pageFirst}"
                     disabled="#{PriceModelHeaderBean.pageFirstDisabled}"
                     styleClass="xSmallButton"
                     value="|<<"/>
                     <h:commandButton action="#{PriceModelHeaderBean.pagePrev}"
                     disabled="#{PriceModelHeaderBean.pagePrevDisabled}"
                     styleClass="xSmallButton"
                     value="<<"/>
                     <h:commandButton action="#{PriceModelHeaderBean.pageNext}"
                     disabled="#{PriceModelHeaderBean.pageNextDisabled}"
                     styleClass="xSmallButton"
                     value=">>"/>
                     <h:commandButton action="#{PriceModelHeaderBean.pageLast}"
                     disabled="#{PriceModelHeaderBean.pageLastDisabled}"
                     styleClass="xSmallButton"
                     value=">>|"/>
                     <h:outputText value="#{PriceModelHeaderBean.caption}" escape="false"/>
                     </h:panelGrid>
                     <!-- Start Table headers / Right side paging size -->
                     <h:panelGrid columns="2">
                     <h:outputLabel value="Rows/page:"/>
                    
                     <h:selectOneMenu value="#{PriceModelHeaderBean.rowsPerPageValue}"
                     valueChangeListener="#{PriceModelHeaderBean.applyRowsPerPageValue}"
                     onchange="this.form.submit();">
                     <f:selectItems value="#{RowSelectionMap}"/>
                     </h:selectOneMenu>
                     </h:panelGrid>
                     </h:panelGrid>
                     </f:facet>
                    
                    <!-- Table Column defs, which include column header and sort indicator, then method for data fill -->
                    
                    
                     <h:column>
                     <f:facet name="header">
                     <h:commandLink action="#{PriceModelHeaderBean.sort}"
                     actionListener="#{PriceModelHeaderBean.bindSortColumn}"
                     value="Prod Code" immediate="false">
                     <f:attribute name="sortColumn" value="dto.productCode"/>
                     </h:commandLink>
                     </f:facet>
                     <h:outputText value="#{item.dto.productCode}"/>
                     </h:column>
                    
                     <h:column>
                     <f:facet name="header">
                     <h:commandLink action="#{PriceModelHeaderBean.sort}"
                     actionListener="#{PriceModelHeaderBean.bindSortColumn}"
                     value="Proposed Price" immediate="false">
                     <f:attribute name="sortColumn" value="dto.proposedPrice"/>
                     </h:commandLink>
                     </f:facet>
                     <h:inputText id="price" value="#{item.dto.proposedPrice}"> <!-- TODO: Gotta make this editable -->
                     <a4j:support event="onchange" reRender="margin" />
                     <h:message for="price" />
                     </h:inputText>
                     </h:column>
                    
                     <h:column>
                     <f:facet name="header">
                     <h:commandLink action="#{PriceModelHeaderBean.sort}"
                     actionListener="#{PriceModelHeaderBean.bindSortColumn}"
                     value="Proposed GM%" immediate="false">
                     <f:attribute name="sortColumn" value="dto.proposedGrossMargin"/>
                     </h:commandLink>
                     </f:facet>
                     <h:inputText id="margin" value="#{item.dto.proposedGrossMargin}">
                     <f:convertNumber pattern="$###0.000"/>
                     <h:message for="margin" />
                     </h:inputText>
                     </h:column>
                    
                    
                    
                     <h:column>
                     <f:facet name="header">
                     <h:commandLink action="#{PriceModelHeaderBean.sort}"
                     actionListener="#{PriceModelHeaderBean.bindSortColumn}"
                     value="Sales Cost" immediate="false">
                     <f:attribute name="sortColumn" value="dto.salesCost"/>
                     </h:commandLink>
                     </f:facet>
                     <h:outputText value="#{item.dto.salesCost}"/>
                     </h:column>
                    
                     </rich:dataTable>
                     <a4j:outputPanel id="err" ajaxRendered="true">
                     <h:messages />
                    </a4j:outputPanel>
                    </h:panelGrid>


                    ----------------------------------------------------------------------------------
                    Here is PriceModelHeaderBean

                    /**
                     * Return the proposed price for this Spreadsheet as a <tt>BigDecimal</tt>.
                     * @return - <tt>BigDecimal</tt> - proposed price.
                     */
                     public BigDecimal getProposedPrice()
                     {
                     return getProposedPriceAt(PricingModel.ZERO);
                     }
                    
                     /**
                     * Set the proposed price for this Spreadsheet. This will update all <tt>PricingModel</tt>s
                     * with the new price
                     * @param newPrice - a <tt>BigDecimal</tt>, the proposed price.
                     */
                     public void setProposedPrice(BigDecimal newPrice)
                     {
                     this.updating(proposedPrice, newPrice);
                     this.proposedPrice = newPrice;
                     for (Iterator i = pricingModels.values().iterator(); i.hasNext();)
                     {
                     PricingModel pm = (PricingModel)i.next();
                     pm.setProposedPrice(newPrice);
                     }
                     }
                    
                     /**
                     * Return the gross margin for the proposed price of the Spreadsheet
                     * as a <tt>BigDecimal</tt>.
                     * @return - a <tt>BigDecimal</tt> - the gross margin at the proposed price.
                     */
                     public BigDecimal getProposedGrossMargin()
                     {
                     return getProposedGrossMarginAt(PricingModel.ZERO);
                     }
                    
                     /**
                     * Set the proposed price for this Spreadsheet by setting it's gross margin.
                     * This will update all <tt>PricingModel</tt>s with the new price/gm
                     * @param proposedGM - a <tt>BigDecimal</tt>, the proposed gross margin.
                     */
                     public void setProposedGrossMargin(BigDecimal proposedGM)
                     {
                     for (Iterator i = pricingModels.values().iterator(); i.hasNext();)
                     {
                     PricingModel pm = (PricingModel)i.next();
                     pm.setProposedGrossMargin(proposedGM);
                     }
                     // Now update the actual price from the pricingModel...
                     this.updating(proposedPrice, this.getProposedPrice());
                     this.proposedPrice = this.getProposedPrice();
                     }
                    
                     public void setSalesCost(BigDecimal salesCost)
                     {
                     this.salesCost = salesCost.setScale(2, RoundingMode.HALF_UP);
                     }
                    
                     public BigDecimal getSalesCost()
                     {
                     return salesCost;
                     }

                    ---------------------------------------------------------------------------
                    PriceingModelBean


                    public void setProposedGrossMargin(BigDecimal proposedGM)
                     {
                     BigDecimal newProposedPrice = cost.divide(ONE.subtract(proposedGM.movePointLeft(2)), 2, RoundingMode.HALF_UP);
                     this.setProposedPrice(newProposedPrice);
                     }
                    
                     public BigDecimal getProposedGrossMargin()
                     {
                     if (cost == null || proposedPrice == null) return HUNDRED.negate();
                     if (proposedPrice.compareTo(ZERO) == 0) return ZERO;
                     BigDecimal gm;
                     if (isListModel())
                     {
                     gm = proposedPrice.subtract(cost).divide(proposedPrice, 6, RoundingMode.HALF_UP);
                     }
                     else
                     {
                     gm = getProposedDiscountPrice().subtract(cost).divide(getProposedDiscountPrice(), 6, RoundingMode.HALF_UP);
                     }
                     return gm.movePointRight(2).setScale(2, RoundingMode.HALF_UP);
                     }
                     public void setProposedPrice(BigDecimal proposedPrice)
                     {
                     if (proposedPrice == null) return;
                     this.proposedPrice = proposedPrice.setScale(2,RoundingMode.HALF_UP);
                     }
                    
                     public BigDecimal getProposedPrice()
                     {
                     return proposedPrice;
                     }


                    could you please tell me where I am going wrong!

                    • 22. Re: Ajax4jsf and dataTable question

                      Do you have information where and when the ClassCast exception occurs?

                      • 23. Re: Ajax4jsf and dataTable question

                        Thanks for replying,

                        I am getting this exception when I am changing the ProposedPrice text field value, on loosing the focus of the text field, nothing is changed in the ProposedGrossMargin field.

                        • 24. Re: Ajax4jsf and dataTable question

                          Do you have an exception stack trace ?

                          • 25. Re: Ajax4jsf and dataTable question

                            here is the exception stack trace


                            07/04/10 16:34:17 BEFORE RESTORE_VIEW 1
                            07/04/10 16:34:17 AFTER RESTORE_VIEW 1
                            07/04/10 16:34:17 BEFORE APPLY_REQUEST_VALUES 2
                            07/04/10 16:34:17 AFTER APPLY_REQUEST_VALUES 2
                            07/04/10 16:34:17 BEFORE PROCESS_VALIDATIONS 3
                            ERROR ProcessValidationsPhase 2007-04-10 16:34:18,312 java.lang.NumberFormatException: null
                            javax.faces.el.EvaluationException: java.lang.NumberFormatException: null
                             at com.sun.faces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:130)
                             at javax.faces.component.UIInput.broadcast(UIInput.java:492)
                             at org.ajax4jsf.ajax.repeat.UIDataAdaptor.broadcast(UIDataAdaptor.java:1056)
                             at org.ajax4jsf.framework.ajax.AjaxViewRoot.processEvents(AjaxViewRoot.java:180)
                             at org.ajax4jsf.framework.ajax.AjaxViewRoot.broadcastEvents(AjaxViewRoot.java:156)
                             at org.ajax4jsf.framework.ajax.JsfOneOneInvoker.invokeOnRegionOrRoot(JsfOneOneInvoker.java:62)
                             at org.ajax4jsf.framework.ajax.AjaxContext.invokeOnRegionOrRoot(AjaxContext.java:176)
                             at org.ajax4jsf.framework.ajax.AjaxViewRoot.processValidators(AjaxViewRoot.java:315)
                             at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:78)
                             at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
                             at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:90)
                             at javax.faces.webapp.FacesServlet.service(FacesServlet.java:197)
                             at com.evermind.server.http.ResourceFilterChain.doFilter(ResourceFilterChain.java:64)
                             at org.ajax4jsf.framework.ajax.xmlfilter.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:96)
                             at org.ajax4jsf.framework.ajax.xmlfilter.BaseFilter.doFilter(BaseFilter.java:220)
                             at com.evermind.server.http.EvermindFilterChain.doFilter(EvermindFilterChain.java:15)
                             at org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:144)
                             at com.evermind.server.http.EvermindFilterChain.doFilter(EvermindFilterChain.java:17)
                             at org.nanocontainer.nanowar.ServletRequestContainerFilter.doFilter(ServletRequestContainerFilter.java:44)
                             at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:627)
                             at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:376)
                             at com.evermind.server.http.HttpRequestHandler.doProcessRequest(HttpRequestHandler.java:870)
                             at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:451)
                             at com.evermind.server.http.HttpRequestHandler.serveOneRequest(HttpRequestHandler.java:218)
                             at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:119)
                             at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:112)
                             at oracle.oc4j.network.ServerSocketReadHandler$SafeRunnable.run(ServerSocketReadHandler.java:260)
                             at oracle.oc4j.network.ServerSocketAcceptHandler.procClientSocket(ServerSocketAcceptHandler.java:230)
                             at oracle.oc4j.network.ServerSocketAcceptHandler.access$800(ServerSocketAcceptHandler.java:33)
                             at oracle.oc4j.network.ServerSocketAcceptHandler$AcceptHandlerHorse.run(ServerSocketAcceptHandler.java:831)
                             at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:303)
                             at java.lang.Thread.run(Thread.java:595)
                            Caused by: java.lang.NumberFormatException: null
                             at java.lang.Integer.parseInt(Integer.java:415)
                             at java.lang.Integer.parseInt(Integer.java:497)
                             at com.katun.jsf.pagebean.DataTableBean.applyRowsPerPageValue(DataTableBean.java:158)
                             at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                             at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                             at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                             at java.lang.reflect.Method.invoke(Method.java:585)
                             at com.sun.faces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:126)
                             ... 31 more


                            • 26. Re: Ajax4jsf and dataTable question

                              So, you have a problem with converter to BigDecimal.
                              There are two places where you have inputText - Price and GrossMargin. The Price has no converter at all. GrossMargin has a converter, but it is a convertNumber. So, one of them is invalid (probably, both). Read more about JSF converter to find a right solution.

                              • 27. Re: Ajax4jsf and dataTable question
                                sreejag

                                HI there,
                                when you are using

                                <h:inputText id="price" value="#{item.dto.proposedPrice}"> <!-- TODO: Gotta make this editable -->
                                 <a4j:support event="onchange" reRender="margin" />
                                 <h:message for="price" />
                                 </h:inputText>


                                which method in the backing bean are you calling???



                                1 2 Previous Next