You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by kiuma <ki...@usa.net> on 2002/09/20 14:39:40 UTC

Re: LookupDispatchAction

I hope this can help u,
bye,
kiuma


/*
 * CustomerCustomerAction.java
 *
 * Created on 9 settembre 2002, 14.16
 */

package com.wingstech.webappointments;

import org.apache.struts.actions.*;
import org.apache.struts.action.*;
import org.apache.struts.util.MessageResources;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.wingstech.webappointments.utils.*;
import com.wingstech.webappointments.interfaces.*;
import javax.naming.*;
import java.util.*;
import org.w3c.dom.*;
/**
 *
 * @author  kiuma
 *
 *
 *
 *
 */

//LookupDispatch

public class ListedCustomerAction extends LookupDispatchAction {
//public class ListedCustomerAction extends Action {   
   
   
    protected Map getKeyMethodMap()
    {
            Map map = new HashMap();
            map.put("button.find", "find");
            map.put("button.delete.selected", "delete");
            map.put("button.append", "append");
            return map;
    }

    public ActionForward delete( ActionMapping mapping,
                                  ActionForm form,
                                  HttpServletRequest req,
                                  HttpServletResponse res ) throws 
Exception
    {      
        Collection customersToDelete = 
((ListedCustomerForm)form).getListCustomerChecked();
        try {
            Context lContext = new InitialContext();
            CustomerSessionHome lHome = (CustomerSessionHome) 
lContext.lookup(
                "java:comp/env/ejb/webappointments/CustomerSession"
            );
            CustomerSession cSession = lHome.create();           
            cSession.deleteCustomerByIDs( customersToDelete );
           
            HttpSession hSession = req.getSession(true);
            Collection collSave = 
((Collection)hSession.getAttribute(IStrutsConstants.SESSION_CUSTOMER_LIST));
            Iterator iter = collSave.iterator();
           
            int i;
            int currArrayPos = 0;          
            while (iter.hasNext())
            {
                CustomerData cData = ((CustomerData)iter.next());
                if ( customersToDelete.contains( cData.getId() + "" ) 
)               
                {                   
                    iter.remove();
                }                              
            }
            
hSession.setAttribute(IStrutsConstants.SESSION_CUSTOMER_LIST, collSave);
           
            return mapping.findForward( IStrutsConstants.SUCCESS );
        } catch (Exception e) {
            return mapping.findForward( IStrutsConstants.SUCCESS );
        }
              
    }
   
    public ActionForward find( ActionMapping mapping,
                                  ActionForm form,
                                  HttpServletRequest req,
                                  HttpServletResponse res ) throws 
Exception
    {

        String keyfinder = ((ListedCustomerForm)form).getCustomerToFind();
       
       
        if ( !keyfinder.equals("") )
        {
            CustomerData uData;
            Collection cCustomers;
            Iterator iter;           
            try {
                Context lContext = new InitialContext();
                CustomerSessionHome lHome = (CustomerSessionHome) 
lContext.lookup(
                    "java:comp/env/ejb/webappointments/CustomerSession"
                );
                CustomerSession cSession = lHome.create();
                cCustomers = cSession.getAllWithName( keyfinder );
                HttpSession hSession = req.getSession(true);
                
hSession.removeAttribute(IStrutsConstants.SESSION_CUSTOMER_LIST);
                if (cCustomers.size() > 0)
                    
hSession.setAttribute(IStrutsConstants.SESSION_CUSTOMER_LIST, cCustomers);
            } catch (Exception e) {
                System.out.println( e.getMessage() );
                return mapping.findForward( IStrutsConstants.FAILURE );
            }
        }
       
        return mapping.findForward( IStrutsConstants.SUCCESS );
    }
   
    public ActionForward append( ActionMapping mapping,
                                  ActionForm form,
                                  HttpServletRequest req,
                                  HttpServletResponse res ) throws 
Exception
    {       
        return mapping.findForward( IStrutsConstants.CUSTOMER_APPEND );    
    }
   
}



Darren Hill wrote:

>Hey everyone .. happy Friday.
>
>Does anyone have a working example the uses LookupDispatchAction.  I think I
>understand ... just wanna see some working example code.
>
>D.
>
>--
>To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
>For additional commands, e-mail: <ma...@jakarta.apache.org>
>
>.
>



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>