2 Replies Latest reply on Aug 7, 2009 9:49 AM by jmacneedshelp

    Getting inputText value

    jmacneedshelp

      So, I think I have a simple question but I cannot seem to figure out the answer. I have a component DropShipOrders into which I want to inject an inputText value. I have tried EVERYTHING including create a @Transient field in Orderitem to bind the inputText field to. The field is set from the value but it will not reset based on a new value I enter into the box. What am I doing wrong?


      DropShipOrdersAction component


      @Stateful
      @Name("DropShipOrders")
      public class DropShipOrdersAction implements DropShipOrders {
      
          @Logger private Log log;
          
          @In FacesMessages facesMessages;
         
          @In private EntityManager entityManager;
          
          @In(create=true)
          private Renderer renderer;
          
          //@In(required=false)
          private Orders searchOrder = new Orders();
          
          private String splitQuantity = new String("15");
          
          public void setSplitQuantity(String splitQuantity){
               this.splitQuantity = splitQuantity;
          }
          
          public String getSplitQuantity() {
               return splitQuantity;
          }
          
      
          //@Factory(scope=ScopeType.CONVERSATION)
          public List<Orders> getDropShipOrdersList() {
               log.info("DropShipOrders.getDropShipOrders ");
               if( searchOrder != null ) {
                    log.info("OrderID: "+searchOrder.getOrderNumber());
               }
                    
               if( searchOrder != null && searchOrder.getOrderNumber() != null ) {
                    return entityManager.createQuery("select o from Orders o where o.orderNumber='"+searchOrder.getOrderNumber()+"'").getResultList();
               } else {
                    return entityManager.createQuery("select o from Orders o where o.status In('Whs')").getResultList();
               }
          }
          
          public Orders getSearchOrder() {
               return searchOrder;
          }
          
          public void setSearchOrder(Orders searchOrder) {
               log.info("Setting searchOrder");
               this.searchOrder = searchOrder;
          }
          
          public void findOrder() {
               log.info("DropShipOrders.findOrder Called.");
               if( searchOrder != null )
                    log.info("OrderID: "+searchOrder.getOrderNumber());
               //return entityManager.createQuery("select o from Orders o where o.orderId In("++)").getResultList();
          }
          
          public void splitLineItem(Orderitem oi) {
                log.info("DropShipOrders.splitLineItem Called");
                log.info("SplitQuantity: "+splitQuantity);
                try {
                     int qty = oi.getQuantity();
                     log.info("DropShipOrders.splitLineItem to QTY:"+qty);
                     oi.setSplitQuantity(0);
                     Orders o = oi.getOrders();
                     List items = o.getOrderitems();
                     Orderitem newSplitItem = (Orderitem)BeanUtils.cloneBean(oi);
                     newSplitItem.setOrderItemId(null);
                     newSplitItem.setQuantity(qty);
                     newSplitItem.setOrderitemattributes(null);
                     oi.setQuantity((oi.getQuantity()-qty));
                     items.add(newSplitItem);
                     entityManager.persist(newSplitItem);
                } catch(Exception ex) {
                     facesMessages.add("Unable to copy line item. Error was: "+ex.getMessage());
                }
           }
          
           public void transmitOrder(Orders order){
                log.info("DropShipOrders.transmitOrder Called");
                if( order != null) {
                     log.info("DropShipOrders.transmitOrder Order "+order.getOrderId()+" IS NOT Null");
                     order.setStatus("Processing");
                     entityManager.persist(order);
                }
                try {
                     renderer.render("/simple.xhtml");
                    facesMessages.add("Email sent successfully");
                } 
                catch (Exception e) {
                     facesMessages.add("Email sending failed: " + e.getMessage());
                }
                facesMessages.add("Order "+order.getOrderNumber()+" transmitted to vendor");
           }
           
           public void transmitLineItem(Orders o, Orderitem oi){
                log.info("DropShipOrders.transmitOrderItem Called");
                
           }
           
            @Destroy @Remove                                                                      
            public void destroy() {}
           
      }
      


      form from xhtml page


      <h:form>
          <h:inputText size="3" var="splitQuantity" value="#{DropShipOrders.splitQuantity}" />
          <h:commandButton id="split" value="Split" action="#{DropShipOrders.splitLineItem(_orderitem)}" />
      </h:form>
      



        • 1. Re: Getting inputText value
          lvdberg

          Hi John,


          I can imagine that you have some more code in your page and that your getting


          _orderItem 



          from some datatable.


          I see ve seen some strange things in your code . First I don't think an inputText has the var-attribute.which normally is part of some iterating element (such as selectOne or many items. Maybe something goes wrong there.


          The other one is the way you create splitQuantity. You shouldn't use new for String initiation. A new is not neccesary and (depending on your users) can lead to a lot of unneccesary objects.


          private String splitQuantity = new String("15");
          private String splitQuantity = "15";
          
          
          


          The latter will be optimized by the compiler and creates a single shared static text.


          If creation and destroy of you bean is not in-sync (check that with methods with @Create and @Destroy with some logging), every time the bean is created it make a toatally new object somewhere in memory, which is lost in the second call (I assume you're not using a conversation because I am not seeing @begin/@end). And you always get the string 15 as a result.


          Leo












          • 2. Re: Getting inputText value
            jmacneedshelp

            Leo,
            That was it! Once I set the scope to Conversation, the splitQty value was set correctly. THANK YOU!