4 Replies Latest reply on Aug 6, 2009 7:22 PM by jmacneedshelp

    Mutilple DataModel - DataModelSelection with dataTable & subTable

    jmacneedshelp

      I have a dataTable of Orders which has subTable of Orderitems. I want to have a link at the order level that will tell me which order was selected but I also want a link at the Orderitem level that will tell me which Orderitem was selected. I have the Order level link working properly, however I cannot figure out how to tell seam to Inject the Orderitem level link, the orderitem var is always null. What am I missing?


      Thank you for your time! I greatly appreciate any help that I can get.


      DropShipOrderAction component


      @Stateful
      @Name("DropShipOrders")
      public class DropShipOrdersAction implements DropShipOrders {
      
          @Logger private Log log;
          
          @In FacesMessages facesMessages;
         
          @In private EntityManager entityManager;
      
          @DataModel(value="order")
          List<Orders> dropShipOrdersList;
          
          @DataModelSelection(value="order")
          Orders order;
          
          @DataModel(value="orderitem")
          List<Orderitem> orderitems;
          
          @DataModelSelection(value="orderitem")
          @Out(required = false)
          Orderitem orderitem;
          
          @Factory(scope=ScopeType.CONVERSATION)
          public List<Orders> getDropShipOrdersList() {
              dropShipOrdersList = entityManager.createQuery("select o from Orders o where o.orderId In(13247,13115)").getResultList();
              return dropShipOrdersList;
          }
          
          public List<Orderitem> getOrderitems() {
              orderitems = order.getOrderitems();
              return orderitems;
          }
              
              public void transmitOrder(){
                      log.info("DropShipOrders.transmitOrder Called");
                      if( order != null) {
                              log.info("DropShipOrders.transmitOrder Order "+order.getOrderId()+" IS NOT Null");
                              order.setStatus("Processing");
                              entityManager.persist(order);
                      }
                      if( orderitem != null) {
                              log.info("DropShipOrders.transmitOrder Orderitem "+orderitem.getOrderItemId()+" IS NOT Null");
                      }
                      
              }
              
              public void transmitLineItem(){
                      log.info("DropShipOrders.transmitOrderItem Called");
                      if( order != null) {
                              log.info("DropShipOrders.transmitOrderItem Order "+order.getOrderId()+" IS NOT Null");
                              order.setStatus("Processing");
                              entityManager.persist(order);
                              //dropShipOrdersList.remove(order);
                      }
                      if( orderitem != null) {
                              log.info("DropShipOrders.transmitOrderItem Item: "+orderitem.getOrderItemId());
                      }
              }
              
               @Destroy @Remove                                                                      
               public void destroy() {}
              
      }
      



      DropShipOrders.xhtml (just the data table section


      <rich:dataTable
                                      id="ordersList" var="_orders" value="#{DropShipOrders.dropShipOrdersList}"
                                      rendered="#{not empty ordersList.resultList}">
                      
                          <!-- <f:facet name="header"> -->
                              <rich:columnGroup style="border:1px solid #FFFFBB;background: #A99999;color: white;">
                                  <rich:column style="font-size:12px;font-weight:bold;text-align:left" colspan="1">
                                  <f:facet name="header">
                                                  <h:outputText value="spacer" />
                                              </f:facet>
                                              Order ID</rich:column>
                                  <rich:column style="font-size:12px;font-weight:bold;text-align:left" colspan="1">
                                  <f:facet name="header">
                                                  <h:outputText value="spacer" />
                                              </f:facet>
                                              Customer</rich:column>
                                  <rich:column style="font-size:12px;font-weight:bold;text-align:left" colspan="1">
                                  <f:facet name="header">
                                                  <h:outputText value="spacer" />
                                              </f:facet>
                                              Company</rich:column>
                                  <rich:column style="font-size:12px;font-weight:bold;text-align:left" colspan="1">
                                  <f:facet name="header">
                                                  <h:outputText value="spacer" />
                                              </f:facet>
                                              Status</rich:column>
                                              <rich:column style="font-size:12px;font-weight:bold;text-align:left" colspan="1">
                                  <f:facet name="header">
                                                  <h:outputText value="spacer" />
                                              </f:facet>
                                              Action</rich:column>
                              </rich:columnGroup>
                              
                          <!-- </f:facet> -->
                          <rich:columnGroup style="vertical-align: top;height:25px">
                                  <rich:column  colspan="1">
                                      <h:outputText value="#{_orders.orderId}" />
                                  </rich:column>
                                  <rich:column   colspan="1">
                                      <h:outputText value="#{_orders.customer.firstName} #{_orders.customer.lastName}" />
                                  </rich:column>
                                  <rich:column  colspan="1">
                                      <h:outputText value="#{_orders.customer.organization}" />
                                  </rich:column>
                                  <rich:column  colspan="1">
                                      <h:outputText value="#{_orders.status}" />
                                  </rich:column>
                                  <rich:column colspan="1">
                                              <h:form>
                                              <h:commandLink value="test" action="#{DropShipOrders.transmitOrder}"/>
                                          </h:form>
                                      </rich:column>
                             </rich:columnGroup>     
                          
                          <rich:subTable var="_orderitem" value="#{DropShipOrders.orderitem}">
                              <rich:column>
                                      <f:facet name="header">Vendor</f:facet>
                                                      <h:form  styleClass="edit">        
                                                      <!--  <h:inputHidden id="orderItem" value="#{_orderitem}"/> -->
                                                      <h:outputText id="venorName" value="#{_orderitem.vendor.company}"></h:outputText>
                                                              <h:selectOneMenu value="#{_orderitem.vendor}">
                                                                              <s:selectItems value="#{_orderitem.product.vendors}" noSelectionLabel="Select..." var="vendor" label="#{vendor.company}" />
                                                                              <s:convertEntity/>
                                                                              <a:support event="onchange" reRender="ovenorName" focus="venorName" process="_orderitem" ajaxSingle="true"/>
                                                                              </h:selectOneMenu>                
                                                              </h:form>
                                                          <f:facet style="height : 25px;" name="ass">test<rich:spacer style=" width : 26px; height : 25px;"></rich:spacer></f:facet>
                              </rich:column> 
                              <rich:column>
                                      <f:facet name="header">Qty</f:facet>
                                  <h:outputText value="#{_orderitem.quantity}"></h:outputText>
                                  <f:facet style="height : 25px;" name="ass"><rich:spacer style=" width : 26px; height : 25px;"></rich:spacer></f:facet>
                              </rich:column>
                              <rich:column>
                                      <f:facet name="header">Product</f:facet>
                                  <h:outputText value="#{_orderitem.product.name}"></h:outputText>
                                  <f:facet style="height : 25px;" name="ass"><rich:spacer style=" width : 26px; height : 25px;"></rich:spacer></f:facet>
                              </rich:column>
                              <rich:column >
                                      <f:facet name="header">Model</f:facet>
                                  <h:outputText value="#{_orderitem.code}"></h:outputText>
                                  <f:facet style="height : 25px;" name="ass">this is a test<rich:spacer style=" width : 26px; height : 25px;"></rich:spacer></f:facet>
                              </rich:column>
                              <rich:column >
                                      <f:facet name="header">Action</f:facet>
                                  <h:form>
                                      <h:inputHidden  value="" binding="#{_order}" />
                                              <h:commandLink value="test" action="#{DropShipOrders.transmitLineItem}"/>
                                          </h:form>
                                  <f:facet style="height : 25px;" name="ass">this si a test<rich:spacer style=" width : 26px; height : 25px;"></rich:spacer></f:facet>
                              </rich:column>
                          </rich:subTable>
                          
                          <rich:columnGroup style="height:50px;border:none;">
                              <rich:column colspan="5"></rich:column>
                          </rich:columnGroup>
                      </rich:dataTable>
                              </div>
                      </rich:panel>
      

        • 1. Re: Mutilple DataModel - DataModelSelection with dataTable & subTable
          jmacneedshelp

          Ooops,I forgot to mention, I've also tried this for the subTable, which displays the items, and the link executes the dropShipOrders transmitLineItem method, but the orderItem is null.


          <rich:subTable var="_orderitem" value="#{_order.orderItems}">
          

          • 2. Re: Mutilple DataModel - DataModelSelection with dataTable & subTable
            asookazian

            I'm not going to read all your code (sorry, but it's a lot, usually the more the better, but this is too much for me).


            here is the deal with this code:


            @DataModel(value="order")
                List<Orders> dropShipOrdersList;
                
                @DataModelSelection(value="order")
                Orders order;
                
                @DataModel(value="orderitem")
                List<Orderitem> orderitems;
                
                @DataModelSelection(value="orderitem")
                @Out(required = false)
                Orderitem orderitem;
            



            The @DataModel, @DataModelSelection, and @DataModelSelectionIndex annotations are used in conjunction with a clickable dataTable.  So that means you have a rich:dataTable, for example, with the backing data being a ListDataModel and with at least one column of commandLinks or commandButtons.  When the user clicks on a row's commandLink or commandButton, in your case Seam injects the Orders instance or Orderitem instance into your backing bean.


            If that is not happening, you need to check to see if the data for the dataTable is really the outjected @DataModel List<foo> or not.


            Also, I haven't tried using @DataModel with a subTable.  Perhaps that is the problem.  Try replacing the subTable with a regular dataTable just to see if that's the root cause...

            • 3. Re: Mutilple DataModel - DataModelSelection with dataTable & subTable
              jmacneedshelp

              Hi Arbi
              Thank you for your help.


              Although I've seen examples of nested dataTable's I cannot get the nested table to display any data without using subTable. I just tried it both ways and it doesn't seem to work, perhaps that's part of the my problem, I don't know. Below are the relevent chunks of my code, do you see anything that's obviously wrong(variable names or annotation misuse)


              Thank you, very much, for your help.


                  @In private EntityManager entityManager;
              
                  @DataModel(value="order")
                  List<Orders> dropShipOrdersList;
                  
                  @DataModelSelection(value="order")
                  Orders order;
                  
                  @DataModel(value="orderitem")
                  List<Orderitem> orderitems;
                  
                  @DataModelSelection(value="orderitem")
                  @Out(required = false)
                  Orderitem orderitem;
                  
                  @Factory(scope=ScopeType.CONVERSATION)
                  public List<Orders> getDropShipOrdersList() {
                       dropShipOrdersList = entityManager.createQuery("select o from Orders o where o.orderId In(13247,13115)").getResultList();
                       return dropShipOrdersList;
                  }
                  @Factory(scope=ScopeType.CONVERSATION)
                  public List<Orderitem> getOrderitems() {
                       orderitems = order.getOrderitems();
                       return orderitems;
                  }
              



              parent dataTable(Orders)


              <rich:dataTable
                  id="ordersList" var="_orders" value="#{dropShipOrdersList}"
                  rendered="#{not empty ordersList.resultList}">
              


              command link for parent table(This works perfect)


              <h:form>
                  <h:commandLink value="test" action="#{DropShipOrders.transmitOrder}"/>
              </h:form>
              



              subTable (Orderitems)


              <rich:subTable var="_orderitem" value="#{DropShipOrders.orderitems}"> 
              



              command link for subTable(executes method but does not inject orderitem)


              <h:form>
                  <h:commandLink value="test" action="#{DropShipOrders.transmitLineItem}"/>
              </h:form>
              

              • 4. Re: Mutilple DataModel - DataModelSelection with dataTable & subTable
                jmacneedshelp

                OK, I got it working, but not exactly the way I was expecting it to work. Here's how I got it to work.


                Instead of using bijection with the DataModel I saw in another post where someone was calling a method in a component like this:


                component.methodName(arg)
                



                So I thought I'd try that, and it worked. I'm not sure if this is the right way to do this, but if anyone has a better idea of how to get this to work, please let me know.


                DropShipOrdersAction


                @DataModel(value="order")
                    List<Orders> dropShipOrdersList;
                    
                    @DataModelSelection(value="order")
                    Orders order;
                    
                    @Factory(scope=ScopeType.CONVERSATION)
                    public List<Orders> getDropShipOrdersList() {
                         dropShipOrdersList = entityManager.createQuery("select o from Orders o where o.orderId In(13247,13115)").getResultList();
                         return dropShipOrdersList;
                    }
                     
                     public void transmitOrder(){
                          log.info("DropShipOrders.transmitOrder Called");
                          if( order != null) {
                               log.info("DropShipOrders.transmitOrder Order "+order.getOrderId()+" IS NOT Null");
                               order.setStatus("Processing");
                               entityManager.persist(order);
                          }
                     }
                     
                     public void transmitLineItem(Orders o, Orderitem oi){
                          log.info("DropShipOrders.transmitOrderItem Called");
                          if( o != null) {
                               log.info("DropShipOrders.transmitOrderItem Order "+o.getOrderId()+" IS NOT Null");
                          }
                          if( oi != null) {
                               log.info("DropShipOrders.transmitOrderItem Item: "+oi.getOrderItemId());
                          }
                     }
                



                DropShipOrders.xhtml


                <h:form>
                    <h:commandLink value="test" action="#{DropShipOrders.transmitLineItem(_orders,_orderitem)}"/>
                </h:form>