/******************* JavaBean code, JSP code is at the bottom *******************/ package article.jsp; import java.util.*; import javax.rmi.*; // PortableRemoteObject import javax.naming.*; // InitialContext, NamingException import article.servlet.RIStore; public class StoreBean implements java.io.Serializable { private RIStore theStore; private ArrayList theItems; private ArrayList theChoices; private String selection; public StoreBean() { theChoices = new ArrayList(); try { InitialContext ic = new InitialContext(); Object obj = ic.lookup( "StoreServer" ); theStore = (RIStore) PortableRemoteObject.narrow( obj, RIStore.class ); theItems = theStore.getItems(); } catch (NamingException ex ) { ex.printStackTrace(); } catch (java.rmi.RemoteException ex ) { ex.printStackTrace(); } } public void setSelection( String str ) { selection = str; if ( ! selection.equals("0")) { theChoices.add( new Integer( Integer.parseInt(selection) - 1 ) ); } } public boolean isDone() { if (selection == null) return false; return selection.equals( "0" ); } public String getResponse() { StringBuffer response = null; try { response = new StringBuffer( theStore.placeOrder( theChoices ) ); } catch (java.rmi.RemoteException ex ) { ex.printStackTrace(); } // massage the returned String to work with HTML conventions formatOrderConfirmation( response ); return response.toString(); } public String getItemList() { StringBuffer sb = new StringBuffer(); Iterator it = theItems.iterator(); for (int i=1; it.hasNext(); i++) sb.append( "
Selections are:
Top <% session.invalidate(); return; } %>