struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Darren Hill <dh...@724.com>
Subject [kiuma ] LookupDispatchAction ...
Date Fri, 20 Sep 2002 13:37:17 GMT
By the way ... 

If that is your actual code .. I have a few suggestions.

1)  Create a plug-in that, on initilization, stores the JNDI context into
either the Applciation or Session object.
	- rather the create it every time.

2)  Make use of the EJBHomeFactory pattern when gaining access to the EJB
Home interfaces.
	- reduces calls and produces less redundant code.

3)  Make use of a Session facade to hide all EJB activity.
	- Centralizes a service layer that can be interchanged ( in case you
want to use your app with some other the EJB )


Any help you need with that ... I here for ya.

D.

Do you have an example struts-config.xml and jsp for that code below for me?



-----Original Message-----
From: kiuma [mailto:kiuma@usa.net]
Sent: September 20, 2002 8:40 AM
To: Struts Users Mailing List
Subject: 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:
<mailto:struts-user-unsubscribe@jakarta.apache.org>
>For additional commands, e-mail:
<mailto:struts-user-help@jakarta.apache.org>
>
>.
>



--
To unsubscribe, e-mail:
<mailto:struts-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail:
<mailto:struts-user-help@jakarta.apache.org>

--
To unsubscribe, e-mail:   <mailto:struts-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:struts-user-help@jakarta.apache.org>


Mime
View raw message