8 Replies Latest reply on Jun 22, 2007 7:48 AM by Daniel Kane

    DataModelSelection always returns first row from h:dataTable

    Daniel Kane Novice

      When I click "Remove" in any row of the table, removeSelectedPosition() is always being called for first row(entity). What is wrong ?


      XHTML :

      <h:dataTable value="#{cart.cartList}" var="item">
       <h:column>
       <f:facet name="header">Quantity</f:facet>
       <h:inputText value="#{item.quantity}" style="width: 30px;"/>
       </h:column>
       <h:column>
       <f:facet name="header">Item</f:facet>
       #{item.part.description}
       </h:column>
       <h:column>
       <s:link id="cancel" value="Remove" action="#{cart.removeSelectedPosition}"/>
       </h:column>
       </h:dataTable>



      cart component :

      @Stateful
      @Name("cart")
      @Scope(ScopeType.SESSION)
      @Restrict("#{identity.loggedIn}")
      
      public class ShoppingCartBean implements ShoppingCart, Serializable
      {
       private OrderCMP cartOrder = new OrderCMP();
      
       @DataModelSelection
       private OrderPositionCMP selectedPosition;
      
       public void addPart(PartCMP part, int quantity)
       {
       cartOrder.addPosition(part, quantity);
       }
      
       public void addPart(PartCMP part)
       {
       this.addPart(part,1);
       }
      
       public void removeSelectedPosition()
       {
       if (selectedPosition!=null) removePart(selectedPosition);
       }
      
       public void removePart(OrderPositionCMP orderPos)
       {
       cartOrder.removePosition(orderPos.getPart());
       }
      
       @DataModel
       public List<OrderPositionCMP> getCartList()
       {
       return(cartOrder.getOrderPositions());
       }
      
       public boolean getIsEmpty()
       {
       return(cartOrder.getOrderPositions().size()==0);
       }
      
       public int getTotalPositions()
       {
       return(cartOrder.getOrderPositions().size());
       }
      
       public void resetCart()
       {
       cartOrder = new OrderCMP();
       }
      
       public OrderCMP getOrder()
       {
       return(cartOrder);
       }
      
       @Destroy @Remove
       public void destroy()
       {
       }
      
      }
      



      Thank you

        • 1. Re: DataModelSelection always returns first row from h:dataT
          Ivan Tufegdzic Newbie

          Put in data value name of dataTable without handler's name.

          • 2. Re: DataModelSelection always returns first row from h:dataT
            Ivan Tufegdzic Newbie

            mistake
            name of dataModel.
            You may put name @DataModel("cartList").
            But it works and with methods name without get.

            • 3. Re: DataModelSelection always returns first row from h:dataT
              Daniel Kane Novice

              ivan.tufegdzic,
              thank you very much , it solved the problem.

              But now I am getting "row is unavailable" exception .
              Notable thing is that exception arises after second of third "remove" operation. First "remove" works well and removes exactly the clicked row.

              javax.faces.el.EvaluationException: /parts.xhtml @74,59 rendered="#{!cart.isEmpty}": Exception getting value of property isEmpty of base of type : org.javassist.tmp.java.lang.Object_$$_javassist_166
               at com.sun.facelets.el.LegacyValueBinding.getValue(LegacyValueBinding.java:60)
               at javax.faces.component.UIComponentBase.isRendered(UIComponentBase.java:1075)
               at com.sun.facelets.tag.jsf.ComponentSupport.encodeRecursive(ComponentSupport.java:241)
               at com.sun.facelets.tag.jsf.ComponentSupport.encodeRecursive(ComponentSupport.java:249)
               at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:573)
               at org.ajax4jsf.framework.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:108)
               at org.ajax4jsf.framework.ajax.AjaxViewHandler.renderView(AjaxViewHandler.java:229)
               at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:384)
               at javax.faces.webapp.FacesServlet.service(FacesServlet.java:138)
               at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
               at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
               at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:63)
               at org.jboss.seam.debug.hot.HotDeployFilter.doFilter(HotDeployFilter.java:60)
               at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:49)
               at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:79)
               at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:49)
               at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
               at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:49)
               at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:57)
               at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:49)
               at org.jboss.seam.web.SeamFilter.doFilter(SeamFilter.java:84)
               at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
               at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
               at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
               at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
               at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
               at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
               at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
               at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:175)
               at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
               at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
               at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
               at org.jboss.web.tomcat.tc5.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:156)
               at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
               at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
               at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
               at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
               at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
               at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
               at java.lang.Thread.run(Thread.java:799)
              Caused by: javax.faces.el.EvaluationException: Bean: org.javassist.tmp.java.lang.Object_$$_javassist_166, property: isEmpty
               at org.apache.myfaces.el.PropertyResolverImpl.getProperty(PropertyResolverImpl.java:442)
               at org.apache.myfaces.el.PropertyResolverImpl.getValue(PropertyResolverImpl.java:82)
               at com.sun.facelets.el.LegacyELContext$LegacyELResolver.getValue(LegacyELContext.java:141)
               at com.sun.el.parser.AstValue.getValue(AstValue.java:125)
               at com.sun.el.parser.AstNot.getValue(AstNot.java:46)
               at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:195)
               at com.sun.facelets.el.TagValueExpression.getValue(TagValueExpression.java:71)
               at com.sun.facelets.el.LegacyValueBinding.getValue(LegacyValueBinding.java:56)
               ... 39 more
              Caused by: java.lang.reflect.InvocationTargetException
               at sun.reflect.GeneratedMethodAccessor2078.invoke(Unknown Source)
               at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
               at java.lang.reflect.Method.invoke(Method.java:615)
               at org.apache.myfaces.el.PropertyResolverImpl.getProperty(PropertyResolverImpl.java:438)
               ... 46 more
              Caused by: javax.ejb.EJBException: java.lang.IllegalArgumentException: row is unavailable
               at org.jboss.ejb3.tx.Ejb3TxPolicy.handleExceptionInOurTx(Ejb3TxPolicy.java:69)
               at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:83)
               at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:191)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
               at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
               at org.jboss.ejb3.stateful.StatefulInstanceInterceptor.invoke(StatefulInstanceInterceptor.java:83)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
               at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:77)
               at org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:102)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
               at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:47)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
               at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
               at org.jboss.ejb3.stateful.StatefulContainer.localInvoke(StatefulContainer.java:203)
               at org.jboss.ejb3.stateful.StatefulLocalProxy.invoke(StatefulLocalProxy.java:98)
               at $Proxy1785.getIsEmpty(Unknown Source)
               at sun.reflect.GeneratedMethodAccessor2079.invoke(Unknown Source)
               at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
               at java.lang.reflect.Method.invoke(Method.java:615)
               at org.jboss.seam.util.Reflections.invoke(Reflections.java:20)
               at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:31)
               at org.jboss.seam.intercept.ClientSideInterceptor$1.proceed(ClientSideInterceptor.java:72)
               at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:57)
               at org.jboss.seam.interceptors.SecurityInterceptor.aroundInvoke(SecurityInterceptor.java:37)
               at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:69)
               at org.jboss.seam.interceptors.RemoveInterceptor.aroundInvoke(RemoveInterceptor.java:40)
               at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:69)
               at org.jboss.seam.interceptors.SynchronizationInterceptor.aroundInvoke(SynchronizationInterceptor.java:31)
               at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:69)
               at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:103)
               at org.jboss.seam.intercept.ClientSideInterceptor.invoke(ClientSideInterceptor.java:50)
               at org.javassist.tmp.java.lang.Object_$$_javassist_166.getIsEmpty(Object_$$_javassist_166.java)
               ... 50 more
              Caused by: java.lang.IllegalArgumentException: row is unavailable
               at javax.faces.model.ListDataModel.getRowData(ListDataModel.java:63)
               at org.jboss.seam.databinding.DataModelBinder.getSelection(DataModelBinder.java:69)
               at org.jboss.seam.databinding.DataModelBinder.getSelection(DataModelBinder.java:19)
               at org.jboss.seam.Component.injectDataModelSelection(Component.java:1274)
               at org.jboss.seam.Component.injectDataModelSelections(Component.java:1254)
               at org.jboss.seam.Component.inject(Component.java:1196)
               at org.jboss.seam.interceptors.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:46)
               at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:69)
               at org.jboss.seam.interceptors.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:27)
               at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:69)
               at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:103)
               at org.jboss.seam.intercept.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:53)
               at sun.reflect.GeneratedMethodAccessor2035.invoke(Unknown Source)
               at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
               at java.lang.reflect.Method.invoke(Method.java:615)
               at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:118)
               at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
               at org.jboss.ejb3.entity.ExtendedPersistenceContextPropagationInterceptor.invoke(ExtendedPersistenceContextPropagationInterceptor.java:57)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
               at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
               at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:46)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
               at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:79)
               ... 82 more




              • 4. Re: DataModelSelection always returns first row from h:dataT
                Ivan Tufegdzic Newbie

                Change method in cart in isEmpty without get and in page rendered="#{cart.empty}"
                But I think that you should delete that and put rendered="{not empty cartList}"

                • 5. Re: DataModelSelection always returns first row from h:dataT
                  Daniel Kane Novice

                   

                  "ivan.tufegdzic" wrote:
                  Change method in cart in isEmpty without get and in page rendered="#{cart.empty}"
                  But I think that you should delete that and put rendered="{not empty cartList}"


                  {not empty cartList} works with no exception , thanks again.

                  However, when I add some items and then remove them all, the table header is still being displayed. It is not being displayed before that, though, so "rendered" is working. But does not recognize empty list after some operations.

                  • 6. Re: DataModelSelection always returns first row from h:dataT
                    Fumihiko Sugiyama Newbie

                    Hi,

                    #{cartList} is not List but DataModel.
                    Try the following:

                    rendered="{cartList.rowCount == 0}"
                    rendered="{cartList.rowCount > 0}"
                    


                    If you see dvd store example in JBoss Seam package more carefully, you may be more happy :)


                    • 7. Re: DataModelSelection always returns first row from h:dataT
                      Fumihiko Sugiyama Newbie

                      my mistake for EL expression :)

                      rendered="#{cartList.rowCount == 0}"
                      rendered="#{cartList.rowCount > 0}"
                      


                      • 8. Re: DataModelSelection always returns first row from h:dataT
                        Daniel Kane Novice

                         

                        "azalea" wrote:
                        my mistake for EL expression :)

                        rendered="#{cartList.rowCount > 0}"
                        


                        Excellent,
                        thanks !