Thank you for visiting! If you liked the site, please add a bookmark, else add a critical comment! Would you like to visit Greece? Traditional Greek flag This real estate site is only available in Greek! The holy mountain

Tuesday, 20 March 2012

Obtaining the selected values of a selectManyChoice component

Searching for selectManyChoice  in the J2EE or fusion  11g developer guides does not return more than a series of drag and drop instructions. Again, the programmer is left at one's own devises, to improvise in order to find the solution. This is no exception to the rule that when in need or emergency, the only thing one is certain to find in a technical guide document is missing information! Even the difference in the  number of pages between the two guides is huge; showing a heavy bias to using ADF based on business components, only. 
This post is a jsf and ejb 3 full source code example, including necessary import statements; showing how to snag the user selections, when a selectManyChoice component  is used.  It could be considered as a complement to the article named:

How to access selected rows in an af:selectManyChoice component, by Frank Nimphius


which focuses only on ADF business components. Two versions of the code will follow, a ADF (licensed) and an open source one. 

First, the ADF version:

<?xml version='1.0' encoding='UTF-8'?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1"
          xmlns:f="http://java.sun.com/jsf/core"
          xmlns:h="http://java.sun.com/jsf/html"
          xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
  <jsp:directive.page contentType="text/html;charset=UTF-8"/>
  <f:view>
    <af:document id="d1" title="Create new order"
                 binding="#{backingBeanScope.backing_createOrder.d1}">
      <af:messages id="m1"
                   binding="#{backingBeanScope.backing_createOrder.m1}"/>
      <af:form id="f1" binding="#{backingBeanScope.backing_createOrder.f1}">
        <af:pageTemplate viewId="/WEB-INF/templates/templateABDef.jspx"
                         id="pt1">
          <f:facet name="content">
            <af:panelStretchLayout id="psl1"
                                   binding="#{backingBeanScope.backing_createOrder.psl1}">
              <f:facet name="center">
                <af:panelFormLayout id="pfl1"
                                    binding="#{backingBeanScope.backing_createOrder.pfl1}">
                  <af:selectManyChoice label="Select one or more items"
                                       binding="#{backingBeanScope.backing_createOrder.smc1}"
                                       id="smc1">
                    <f:selectItems value="#{backingBeanScope.backing_createOrder.allItems}"
                                   binding="#{backingBeanScope.backing_createOrder.si1}"
                                   id="si1"/>
                  </af:selectManyChoice>
                  <af:selectOneChoice label="Billing Info"
                                      binding="#{backingBeanScope.backing_createOrder.soc1}"
                                      id="soc1">
                    <f:selectItems value="#{backingBeanScope.backing_createOrder.allBillingInfos}"
                                   binding="#{backingBeanScope.backing_createOrder.si2}"
                                   id="si2"/>
                  </af:selectOneChoice>
                  <af:inputText value="#{securityContext.userName}"
                                label="#{bindings.bidderId.hints.label}"
                                required="#{bindings.bidderId.hints.mandatory}"
                                columns="#{bindings.bidderId.hints.displayWidth}"
                                maximumLength="#{bindings.bidderId.hints.precision}"
                                shortDesc="#{bindings.bidderId.hints.tooltip}"
                                id="it3"
                                binding="#{backingBeanScope.backing_createOrder.it3}"
                                rendered="true">
                    <f:validator binding="#{bindings.bidderId.validator}"/>
                  </af:inputText>
                  <af:selectOneChoice label="Shipping info"
                                      binding="#{backingBeanScope.backing_createOrder.soc2}"
                                      id="soc2">
                    <f:selectItems value="#{backingBeanScope.backing_createOrder.allShippingInfos}"
                                   binding="#{backingBeanScope.backing_createOrder.si3}"
                                   id="si3"/>
                  </af:selectOneChoice>
                  <af:commandButton text="create order"
                                    binding="#{backingBeanScope.backing_createOrder.cb1}"
                                    id="cb1"
                                    action="#{backingBeanScope.backing_createOrder.createNewOrder}"/>
                </af:panelFormLayout>
              </f:facet>
            </af:panelStretchLayout>
          </f:facet>
        </af:pageTemplate>
      </af:form>
    </af:document>
  </f:view>
  <!--oracle-jdev-comment:auto-binding-backing-bean-name:backing_createOrder-->
</jsp:root>

The bean:

package actionbazaar.view.backing;


import actionbazaar.buslogic.PlaceBillingInfo;
import actionbazaar.buslogic.PlaceItem;
import actionbazaar.buslogic.PlaceOrder;
import actionbazaar.buslogic.PlaceShippingInfo;

import actionbazaar.persistence.BillingInfo;
import actionbazaar.persistence.Item;
import actionbazaar.persistence.ShippingInfo;

import actionbazaar.view.CustomBackingBean;

import java.util.ArrayList;
import java.util.List;

import javax.el.ELContext;
import javax.el.ExpressionFactory;
import javax.el.ValueExpression;

import javax.faces.application.Application;
import javax.faces.component.UISelectItems;
import javax.faces.context.FacesContext;
import javax.faces.model.SelectItem;

import javax.naming.InitialContext;
import javax.naming.NamingException;

import oracle.adf.share.ADFContext;
import oracle.adf.view.rich.component.rich.RichDocument;
import oracle.adf.view.rich.component.rich.RichForm;
import oracle.adf.view.rich.component.rich.input.RichInputText;
import oracle.adf.view.rich.component.rich.input.RichSelectManyChoice;
import oracle.adf.view.rich.component.rich.input.RichSelectOneChoice;
import oracle.adf.view.rich.component.rich.layout.RichPanelFormLayout;
import oracle.adf.view.rich.component.rich.layout.RichPanelStretchLayout;
import oracle.adf.view.rich.component.rich.nav.RichCommandButton;
import oracle.adf.view.rich.component.rich.output.RichMessages;


public class CreateOrder extends CustomBackingBean {
    private RichInputText it3;
    private RichPanelFormLayout pfl1;
    private RichPanelStretchLayout psl1;
    private RichForm f1;
    private RichMessages m1;
    private RichDocument d1;
   
    private String bidderId ;
    private ArrayList<SelectItem> allItems;
    private ArrayList<SelectItem> orderItems;
    private ArrayList<SelectItem> shippingInfos;
    private ArrayList<SelectItem> billingInfos;

    private RichCommandButton cb1;
    private RichSelectOneChoice soc1;
    private UISelectItems si2;
    private RichSelectOneChoice soc2;
    private UISelectItems si3;
    private RichSelectManyChoice smc1;
    private UISelectItems si1;

    public CreateOrder() {
      bidderId = ADFContext.getCurrent().getSecurityContext().getUserName();
     // getAllBillingInfos();
      //getAllShippingInfos();
    }

  public ArrayList<SelectItem> getAllItems() {
   try {
       InitialContext context = new InitialContext();
       PlaceItem beanRemote = (PlaceItem) context.lookup( "ejb3inaction-Model-PlaceItem#actionbazaar.buslogic.PlaceItem");
       List<Item> allItems = beanRemote.getItemFindAll();
       orderItems = new ArrayList<SelectItem>(allItems.size());
       for (Item item : allItems) {
             Long itemId = item.getItemId();
             String itemName= item.getItemName();
             SelectItem selectItem = new SelectItem(itemId, itemName);
             orderItems.add(selectItem);
       }
         logger.debug("orderItems.size() " + orderItems.size());
         this.setOrderItems(orderItems);
       } catch (NamingException e) {
           System.err.println(e.getMessage());
   }
     return orderItems;
   }
 
  public ArrayList<SelectItem> getAllBillingInfos() {
   try {
         InitialContext context = new InitialContext();
         PlaceBillingInfo beanRemote1 = (PlaceBillingInfo)context.lookup("ejb3inaction-Model-PlaceBillingInfo#actionbazaar.buslogic.PlaceBillingInfo");
                      
         List<BillingInfo> alllBillingInfos = beanRemote1.getBillingInfoFindByUserId(bidderId);
         billingInfos = new ArrayList<SelectItem>(alllBillingInfos.size());
         for (BillingInfo bi : alllBillingInfos) {
             Long billingId = bi.getBillingId();
             String billingName= bi.getAccountNo() + " " + bi.getCardType() + " " + bi.getExpiryDate() +" " + bi.getSecretCode();
             SelectItem selectItem1 = new SelectItem(billingId, billingName);
             billingInfos.add(selectItem1);
       }
         logger.debug("billingInfos.size() " + billingInfos.size());
       this.setBillingInfos(billingInfos);
       } catch (NamingException e) {
           System.err.println(e.getMessage());
   }
   return billingInfos;
   }

   public ArrayList<SelectItem> getAllShippingInfos() {
   try {
       InitialContext context = new InitialContext();
       PlaceShippingInfo beanRemote2 = (PlaceShippingInfo)context.lookup("ejb3inaction-Model-PlaceShippingInfo#actionbazaar.buslogic.PlaceShippingInfo");
       List<ShippingInfo> allShippingInfos = beanRemote2.getShippingInfoFindAll();
       shippingInfos = new ArrayList<SelectItem>(allShippingInfos.size());
       for (ShippingInfo si : allShippingInfos) {
             Long ShippingInfoId = si.getShippingId();
             String ShippingInfoName= si.getStreet() + " " + si.getCity() + " " + si.getState();
             SelectItem selectItem2 = new SelectItem(ShippingInfoId, ShippingInfoName);
             shippingInfos.add(selectItem2);
       }
         logger.debug("shippingInfos.size() " + shippingInfos.size());
         this.setShippingInfos(shippingInfos);
       } catch (NamingException e) {
           System.err.println(e.getMessage());
   }
   return shippingInfos;
   }
 
  public Object createNewOrder() {
        try {
                              
                  FacesContext ctx = FacesContext.getCurrentInstance();
                  ELContext ectx =ctx.getELContext();
                  Application app = ctx.getApplication();
                  ExpressionFactory factory = app.getExpressionFactory();
                /*  An alternate way which works too*/
                /*
                 java.util.ArrayList billingIdUIComponents = (java.util.ArrayList)si2.getValue();
                 SelectItem billingIdItem=(SelectItem)billingIdUIComponents.get(0);
                 Long billingId = new Long( billingIdItem.getValue().toString() );
                 */
                  ValueExpression ve =   factory.createValueExpression(ectx,   "#{backingBeanScope.backing_createOrder.soc1.value}",Object.class );
                  Long billingId = new Long(ve.getValue(ectx).toString());
                  ValueExpression ve1= factory.createValueExpression(ectx,   "#{backingBeanScope.backing_createOrder.soc2.value}",Object.class );
                  Long shippingId = new Long( ve1.getValue(ectx).toString());
                 ValueExpression ve2= factory.createValueExpression(ectx,   "#{backingBeanScope.backing_createOrder.smc1.value}",Object.class );
                 /*selectManyChoice working alternate*/
               /*   ArrayList<Object> selectedItemsId =  (ArrayList<Object>)ve2.getValue(ectx);
                 ArrayList<Long> itemsId = new ArrayList<Long>(selectedItemsId.size());
                 for (int i = 0; i < selectedItemsId.size(); i++) {
                      Long val = new Long(selectedItemsId.get(i).toString());
                      logger.debug( "itemId " + val);
                      itemsId.add(val);
                  }
               */
                   
                 ArrayList itemIdUIComponents = (java.util.ArrayList)si1.getValue();
                 ArrayList<Long> itemsId = new ArrayList<Long>(itemIdUIComponents.size());
                 for (int i = 0; i < itemIdUIComponents.size(); i++) {
                      SelectItem selectedItemsId =(SelectItem)itemIdUIComponents.get(i);
                      Long itemId = new Long( selectedItemsId.getValue().toString() );
                      itemsId.add(itemId);
                }
               
         
       
                 if (logger.isDebugEnabled())
                         logger.debug(  "bidderId " + bidderId +"  billingId " + billingId +  " shippingId " + shippingId);
                 InitialContext context = new InitialContext();
                 PlaceOrder facadeSessionEJB = (PlaceOrder)context.lookup("ejb3inaction-Model-PlaceOrder#actionbazaar.buslogic.PlaceOrder");
                 facadeSessionEJB.addOrder(bidderId, itemsId, shippingId, billingId );
                 if (logger.isDebugEnabled())
                         logger.debug(  "itemsId " + itemsId.get(0) +"  billingId " +  " shippingId " );
               } catch (NamingException e) {
                    System.err.println(e.getMessage());
               }
         return null;
    }


    public void setIt3(RichInputText it3) {
        this.it3 = it3;
    }

    public RichInputText getIt3() {
        return it3;
    }


    public void setPfl1(RichPanelFormLayout pfl1) {
        this.pfl1 = pfl1;
    }

    public RichPanelFormLayout getPfl1() {
        return pfl1;
    }

    public void setPsl1(RichPanelStretchLayout psl1) {
        this.psl1 = psl1;
    }

    public RichPanelStretchLayout getPsl1() {
        return psl1;
    }

    public void setF1(RichForm f1) {
        this.f1 = f1;
    }

    public RichForm getF1() {
        return f1;
    }

    public void setM1(RichMessages m1) {
        this.m1 = m1;
    }

    public RichMessages getM1() {
        return m1;
    }

    public void setD1(RichDocument d1) {
        this.d1 = d1;
    }

    public RichDocument getD1() {
        return d1;
    }

    public void setAllItems(ArrayList<SelectItem> allItems) {
        this.allItems = allItems;
    }

    public void setOrderItems(ArrayList<SelectItem> orderItems) {
        this.orderItems = orderItems;
    }


    public void setCb1(RichCommandButton cb1) {
        this.cb1 = cb1;
    }

    public RichCommandButton getCb1() {
        return cb1;
    }

    public void setShippingInfos(ArrayList<SelectItem> shippingInfos) {
        this.shippingInfos = shippingInfos;
    }

    public void setBillingInfos(ArrayList<SelectItem> billingInfos) {
        this.billingInfos = billingInfos;
    }

    public void setSoc1(RichSelectOneChoice soc1) {
        this.soc1 = soc1;
    }

    public RichSelectOneChoice getSoc1() {
        return soc1;
    }

    public void setSi2(UISelectItems si2) {
        this.si2 = si2;
    }

    public UISelectItems getSi2() {
        return si2;
    }

    public void setSoc2(RichSelectOneChoice soc2) {
        this.soc2 = soc2;
    }

    public RichSelectOneChoice getSoc2() {
        return soc2;
    }

    public void setSi3(UISelectItems si3) {
        this.si3 = si3;
    }

    public UISelectItems getSi3() {
        return si3;
    }

    public void setSmc1(RichSelectManyChoice smc1) {
        this.smc1 = smc1;
    }

    public RichSelectManyChoice getSmc1() {
        return smc1;
    }

    public void setSi1(UISelectItems si1) {
        this.si1 = si1;
    }

    public UISelectItems getSi1() {
        return si1;
    }
}


Second, the J2EE open source version, starting with the page:

<?xml version='1.0' encoding='UTF-8'?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1"
          xmlns:f="http://java.sun.com/jsf/core"
          xmlns:h="http://java.sun.com/jsf/html">
    <jsp:output omit-xml-declaration="true" doctype-root-element="HTML"
                doctype-system="http://www.w3.org/TR/html4/loose.dtd"
                doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN"/>
    <jsp:directive.page contentType="text/html;charset=UTF-8"/>
    <f:view>
        <html>
            <head>
                <meta http-equiv="Content-Type"
                      content="text/html; charset=UTF-8"/>
                <h:messages/>
            </head>
            <body>
                <div align="center">
                    <h:form>
                        <h:panelGrid columns="2"
                                     binding="#{backing_createOrder.panelGrid11}"
                                     id="panelGrid11"
                                     style="vertical-align:middle;">
                            <h:outputLabel value="Select items"
                                           binding="#{backing_createOrder.outputLabel31}"
                                           id="outputLabel31"/>
                            <h:selectManyListbox binding="#{backing_createOrder.selectManyListbox11}"
                                                 id="selectManyListbox11"
                                                 required="true">
                                <f:selectItems value="#{backing_createOrder.allItems}"
                                               binding="#{backing_createOrder.selectItems41}"
                                               id="selectItems41"/>
                            </h:selectManyListbox>
                            <h:outputLabel value="Bidder"
                                           binding="#{backing_createOrder.outputLabel11}"
                                           id="outputLabel11"/>
                            <h:inputText binding="#{backing_createOrder.inputText11}"
                                         id="inputText11"
                                         value="#{backing_createOrder.bidderId}"/>
                            <h:outputLabel value="Billing details"
                                           binding="#{backing_createOrder.outputLabel21}"
                                           id="outputLabel21"/>
                            <h:selectOneListbox label="BillingInfo"
                                                binding="#{backing_createOrder.selectOneListbox11}"
                                                id="selectOneListbox11"
                                                required="true">
                                <f:selectItems value="#{backing_createOrder.allBillingInfos}"
                                               binding="#{backing_createOrder.selectItems21}"
                                               id="selectItems21"/>
                            </h:selectOneListbox>
                            <h:outputLabel value="Shipping details"
                                           binding="#{backing_createOrder.outputLabel41}"
                                           id="outputLabel41"/>
                            <h:selectOneListbox label="ShippingInfo"
                                                binding="#{backing_createOrder.selectOneListbox21}"
                                                id="selectOneListbox21"
                                                required="true">
                                <f:selectItems value="#{backing_createOrder.allShippingInfos}"
                                               binding="#{backing_createOrder.selectItems31}"
                                               id="selectItems31"/>
                            </h:selectOneListbox>
                            <f:facet name="footer">
                                <h:panelGroup binding="#{backing_createOrder.panelGroup1}"
                                              id="panelGroup1">
                                    <input type="reset" name="Reset"
                                           value="Reset"/>
                                    <h:commandButton value="create Order"
                                                     binding="#{backing_createOrder.commandButton11}"
                                                     id="commandButton11"
                                                     action="#{backing_createOrder.createNewOrder}"/>
                                </h:panelGroup>
                            </f:facet>
                            <f:facet name="header">
                                <h:outputFormat value="Create new order"
                                                binding="#{backing_createOrder.outputFormat11}"
                                                id="outputFormat11"/>
                            </f:facet>
                        </h:panelGrid>
                    </h:form>
                </div>
            </body>
        </html>
    </f:view>
    <!--oracle-jdev-comment:auto-binding-backing-bean-name:backing_createOrder-->
</jsp:root>

Finally, the bean:

package actionbazaar.backing;


import actionbazaar.buslogic.PlaceBillingInfo;
import actionbazaar.buslogic.PlaceItem;
import actionbazaar.buslogic.PlaceOrder;
import actionbazaar.buslogic.PlaceShippingInfo;

import actionbazaar.persistence.BillingInfo;
import actionbazaar.persistence.Item;
import actionbazaar.persistence.Order;
import actionbazaar.persistence.ShippingInfo;

import java.util.ArrayList;
import java.util.List;

import javax.el.ELContext;
import javax.el.ExpressionFactory;
import javax.el.ValueExpression;

import javax.faces.application.Application;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.component.UISelectItems;
import javax.faces.component.html.HtmlCommandButton;
import javax.faces.component.html.HtmlInputText;
import javax.faces.component.html.HtmlOutputFormat;
import javax.faces.component.html.HtmlOutputLabel;
import javax.faces.component.html.HtmlPanelGrid;
import javax.faces.component.html.HtmlPanelGroup;
import javax.faces.component.html.HtmlSelectManyListbox;
import javax.faces.component.html.HtmlSelectOneListbox;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.faces.model.SelectItem;

import javax.naming.InitialContext;
import javax.naming.NamingException;

import javax.servlet.http.HttpServletRequest;


@ManagedBean(name="backing_createOrder")
@RequestScoped
public class CreateOrder extends CustomBackingBean{
   
    private ArrayList<SelectItem> allItems;
    private ArrayList<SelectItem> orderItems;
    private ArrayList<SelectItem> shippingInfos;
    private ArrayList<SelectItem> billingInfos;
    private String bidderId  ;
    private FacesContext ctx;
    private ExternalContext ectx;
    private HtmlPanelGrid panelGrid1;
    private HtmlOutputLabel outputLabel1;
    private HtmlInputText inputText1;
    private HtmlSelectOneListbox selectOneListbox1;
    private UISelectItems selectItems2;
    private HtmlCommandButton commandButton1;
    private HtmlSelectOneListbox selectOneListbox2;
    private UISelectItems selectItems3;
    private HtmlOutputLabel outputLabel2;
    private HtmlOutputLabel outputLabel3;
    private HtmlOutputLabel outputLabel4;
    private HtmlSelectManyListbox selectManyListbox1;
    private UISelectItems selectItems4;
    private HtmlOutputFormat outputFormat1;
    private HtmlPanelGrid panelGrid11;
    private HtmlOutputLabel outputLabel31;
    private HtmlSelectManyListbox selectManyListbox11;
    private UISelectItems selectItems41;
    private HtmlOutputLabel outputLabel11;
    private HtmlInputText inputText11;
    private HtmlOutputLabel outputLabel21;
    private HtmlSelectOneListbox selectOneListbox11;
    private UISelectItems selectItems21;
    private HtmlOutputLabel outputLabel41;
    private HtmlSelectOneListbox selectOneListbox21;
    private UISelectItems selectItems31;
    private HtmlCommandButton commandButton11;
    private HtmlOutputFormat outputFormat11;
    private HtmlPanelGroup panelGroup1;

    public CreateOrder() {
            getAllItems();
            getAllShippingInfos();
            ctx = FacesContext.getCurrentInstance();
            ectx =ctx.getExternalContext();
            getAllBillingInfos();
    }
    public ArrayList<SelectItem> getAllItems() {
    try {
        InitialContext context = new InitialContext();
        PlaceItem beanRemote = (PlaceItem) context.lookup( "ejb3inaction-Model-PlaceItem#actionbazaar.buslogic.PlaceItem");
        List<Item> allItems = beanRemote.getItemFindAll();
        orderItems = new ArrayList<SelectItem>(allItems.size());
        for (Item item : allItems) {
              Long itemId = item.getItemId();
              String itemName= item.getItemName();
              SelectItem selectItem = new SelectItem(itemId, itemName);
              orderItems.add(selectItem);
        }
          logger.debug("orderItems.size() " + orderItems.size());
          this.setOrderItems(orderItems);
        } catch (NamingException e) {
            System.err.println(e.getMessage());
    }
    return orderItems;
    }
    public ArrayList<SelectItem> getAllBillingInfos() {
    try {
          InitialContext context = new InitialContext();
          PlaceBillingInfo beanRemote1 = (PlaceBillingInfo)context.lookup("ejb3inaction-Model-PlaceBillingInfo#actionbazaar.buslogic.PlaceBillingInfo");
                       
          List<BillingInfo> alllBillingInfos = beanRemote1.getBillingInfoFindByUserId( bidderId); //
          billingInfos = new ArrayList<SelectItem>(alllBillingInfos.size());
          for (BillingInfo bi : alllBillingInfos) {
              Long billingId = bi.getBillingId();
              String billingName= bi.getAccountNo() + " " + bi.getCardType() + " " + bi.getExpiryDate() +" " + bi.getSecretCode();
              SelectItem selectItem1 = new SelectItem(billingId, billingName);
              billingInfos.add(selectItem1);
        }
          logger.debug("billingInfos.size() " + billingInfos.size());
        this.setBillingInfos(billingInfos);
        } catch (NamingException e) {
            System.err.println(e.getMessage());
    }
    return billingInfos;
    }

    public ArrayList<SelectItem> getAllShippingInfos() {
    try {
        InitialContext context = new InitialContext();
        PlaceShippingInfo beanRemote2 = (PlaceShippingInfo)context.lookup("ejb3inaction-Model-PlaceShippingInfo#actionbazaar.buslogic.PlaceShippingInfo");
        List<ShippingInfo> allShippingInfos = beanRemote2.getShippingInfoFindAll();
        shippingInfos = new ArrayList<SelectItem>(allShippingInfos.size());
        for (ShippingInfo si : allShippingInfos) {
              Long ShippingInfoId = si.getShippingId();
              String ShippingInfoName= si.getStreet() + " " + si.getCity() + " " + si.getState();
              SelectItem selectItem2 = new SelectItem(ShippingInfoId, ShippingInfoName);
              shippingInfos.add(selectItem2);
        }
          logger.debug("shippingInfos.size() " + shippingInfos.size());
          this.setShippingInfos(shippingInfos);
        } catch (NamingException e) {
            System.err.println(e.getMessage());
    }
    return shippingInfos;
    }
  
    public Object createNewOrder() {
        try {
                                     
                   bidderId = (String)inputText11.getValue();           
                                                    
                   java.util.ArrayList billingIdUIComponents = (java.util.ArrayList)selectItems21.getValue();
                   SelectItem billingIdItem=(SelectItem)billingIdUIComponents.get(0);
                   Long billingId = new Long( billingIdItem.getValue().toString() );
                   /*
                   java.util.ArrayList shippingIdUIComponents = (java.util.ArrayList)selectItems31.getValue();
                   SelectItem shippingIdItem=(SelectItem)shippingIdUIComponents.get(0);
                   Long shippingId = new Long( shippingIdItem.getValue().toString());
                 */
                   ELContext elctx =ctx.getELContext();
                  Application app = ctx.getApplication();
                   ExpressionFactory factory = app.getExpressionFactory();
                   ValueExpression ve =   factory.createValueExpression(elctx,   "#{backing_createOrder.selectOneListbox21.value}",Object.class );
                   Long shippingId = new Long( ve.getValue(elctx).toString());
                
                  HttpServletRequest request =    (HttpServletRequest)ctx.getExternalContext().getRequest();
                  String[] selectedItemsId = request.getParameterValues("j_id_id2:selectManyListbox11");
                  
                 ArrayList<Long> itemsId = new ArrayList<Long>(selectedItemsId.length);
                 
                  for (int i = 0; i < selectedItemsId.length; i++) {
                      Long val = new Long(selectedItemsId[i].toString());
                       logger.debug( "itemId " + val);
                       itemsId.add(val);
                   }
                 if (logger.isDebugEnabled())
                         logger.debug(  "bidderId " + getBidderId() +"  billingId " + billingId +  " shippingId " + shippingId);
                 InitialContext context = new InitialContext();
                 PlaceOrder facadeSessionEJB = (PlaceOrder)context.lookup("ejb3inaction-Model-PlaceOrder#actionbazaar.buslogic.PlaceOrder");
                 facadeSessionEJB.addOrder(getBidderId(), itemsId, shippingId, billingId );
                             
               } catch (NamingException e) {
                    System.err.println(e.getMessage());
                    return null;
               }
         return "queryOrders";
    }


    public void setAllItems(ArrayList<SelectItem> allItems) {
        this.allItems = allItems;
    }

    public void setOrderItems(ArrayList<SelectItem> orderItems) {
        this.orderItems = orderItems;
    }

    public void setShippingInfos(ArrayList<SelectItem> shippingInfos) {
        this.shippingInfos = shippingInfos;
    }

    public void setBillingInfos(ArrayList<SelectItem> billingInfos) {
        this.billingInfos = billingInfos;
    }

    public void setBidderId(String bidderId) {
        this.bidderId = bidderId;
    }

    public String getBidderId() {
        return ectx.getRemoteUser();
    }


    public void setPanelGrid1(HtmlPanelGrid panelGrid1) {
        this.panelGrid1 = panelGrid1;
    }

    public HtmlPanelGrid getPanelGrid1() {
        return panelGrid1;
    }


    public void setOutputLabel1(HtmlOutputLabel outputLabel1) {
        this.outputLabel1 = outputLabel1;
    }

    public HtmlOutputLabel getOutputLabel1() {
        return outputLabel1;
    }

    public void setInputText1(HtmlInputText inputText1) {
        this.inputText1 = inputText1;
    }

    public HtmlInputText getInputText1() {
        return inputText1;
    }

    public void setSelectOneListbox1(HtmlSelectOneListbox selectOneListbox1) {
        this.selectOneListbox1 = selectOneListbox1;
    }

    public HtmlSelectOneListbox getSelectOneListbox1() {
        return selectOneListbox1;
    }

    public void setSelectItems2(UISelectItems selectItems2) {
        this.selectItems2 = selectItems2;
    }

    public UISelectItems getSelectItems2() {
        return selectItems2;
    }

    public void setCommandButton1(HtmlCommandButton commandButton1) {
        this.commandButton1 = commandButton1;
    }

    public HtmlCommandButton getCommandButton1() {
        return commandButton1;
    }


    public void setSelectOneListbox2(HtmlSelectOneListbox selectOneListbox2) {
        this.selectOneListbox2 = selectOneListbox2;
    }

    public HtmlSelectOneListbox getSelectOneListbox2() {
        return selectOneListbox2;
    }

    public void setSelectItems3(UISelectItems selectItems3) {
        this.selectItems3 = selectItems3;
    }

    public UISelectItems getSelectItems3() {
        return selectItems3;
    }

    public void setOutputLabel2(HtmlOutputLabel outputLabel2) {
        this.outputLabel2 = outputLabel2;
    }

    public HtmlOutputLabel getOutputLabel2() {
        return outputLabel2;
    }

    public void setOutputLabel3(HtmlOutputLabel outputLabel3) {
        this.outputLabel3 = outputLabel3;
    }

    public HtmlOutputLabel getOutputLabel3() {
        return outputLabel3;
    }

    public void setOutputLabel4(HtmlOutputLabel outputLabel4) {
        this.outputLabel4 = outputLabel4;
    }

    public HtmlOutputLabel getOutputLabel4() {
        return outputLabel4;
    }


    public ArrayList<SelectItem> getBillingInfos() {
        return billingInfos;
    }

    public void setSelectManyListbox1(HtmlSelectManyListbox selectManyListbox1) {
        this.selectManyListbox1 = selectManyListbox1;
    }

    public HtmlSelectManyListbox getSelectManyListbox1() {
        return selectManyListbox1;
    }

    public void setSelectItems4(UISelectItems selectItems4) {
        this.selectItems4 = selectItems4;
    }

    public UISelectItems getSelectItems4() {
        return selectItems4;
    }

    public void setOutputFormat1(HtmlOutputFormat outputFormat1) {
        this.outputFormat1 = outputFormat1;
    }

    public HtmlOutputFormat getOutputFormat1() {
        return outputFormat1;
    }

    public void setPanelGrid11(HtmlPanelGrid panelGrid11) {
        this.panelGrid11 = panelGrid11;
    }

    public HtmlPanelGrid getPanelGrid11() {
        return panelGrid11;
    }

    public void setOutputLabel31(HtmlOutputLabel outputLabel31) {
        this.outputLabel31 = outputLabel31;
    }

    public HtmlOutputLabel getOutputLabel31() {
        return outputLabel31;
    }

    public void setSelectManyListbox11(HtmlSelectManyListbox selectManyListbox11) {
        this.selectManyListbox11 = selectManyListbox11;
    }

    public HtmlSelectManyListbox getSelectManyListbox11() {
        return selectManyListbox11;
    }

    public void setSelectItems41(UISelectItems selectItems41) {
        this.selectItems41 = selectItems41;
    }

    public UISelectItems getSelectItems41() {
        return selectItems41;
    }

    public void setOutputLabel11(HtmlOutputLabel outputLabel11) {
        this.outputLabel11 = outputLabel11;
    }

    public HtmlOutputLabel getOutputLabel11() {
        return outputLabel11;
    }

    public void setInputText11(HtmlInputText inputText11) {
        this.inputText11 = inputText11;
    }

    public HtmlInputText getInputText11() {
        return inputText11;
    }

    public void setOutputLabel21(HtmlOutputLabel outputLabel21) {
        this.outputLabel21 = outputLabel21;
    }

    public HtmlOutputLabel getOutputLabel21() {
        return outputLabel21;
    }

    public void setSelectOneListbox11(HtmlSelectOneListbox selectOneListbox11) {
        this.selectOneListbox11 = selectOneListbox11;
    }

    public HtmlSelectOneListbox getSelectOneListbox11() {
        return selectOneListbox11;
    }

    public void setSelectItems21(UISelectItems selectItems21) {
        this.selectItems21 = selectItems21;
    }

    public UISelectItems getSelectItems21() {
        return selectItems21;
    }

    public void setOutputLabel41(HtmlOutputLabel outputLabel41) {
        this.outputLabel41 = outputLabel41;
    }

    public HtmlOutputLabel getOutputLabel41() {
        return outputLabel41;
    }

    public void setSelectOneListbox21(HtmlSelectOneListbox selectOneListbox21) {
        this.selectOneListbox21 = selectOneListbox21;
    }

    public HtmlSelectOneListbox getSelectOneListbox21() {
        return selectOneListbox21;
    }

    public void setSelectItems31(UISelectItems selectItems31) {
        this.selectItems31 = selectItems31;
    }

    public UISelectItems getSelectItems31() {
        return selectItems31;
    }

    public void setCommandButton11(HtmlCommandButton commandButton11) {
        this.commandButton11 = commandButton11;
    }

    public HtmlCommandButton getCommandButton11() {
        return commandButton11;
    }

    public void setOutputFormat11(HtmlOutputFormat outputFormat11) {
        this.outputFormat11 = outputFormat11;
    }

    public HtmlOutputFormat getOutputFormat11() {
        return outputFormat11;
    }

    public void setPanelGroup1(HtmlPanelGroup panelGroup1) {
        this.panelGroup1 = panelGroup1;
    }

    public HtmlPanelGroup getPanelGroup1() {
        return panelGroup1;
    }
}

No comments:

Post a Comment