struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Richard.Fe...@VerizonWireless.com
Subject RE: Pass Javabeans
Date Fri, 16 Nov 2007 22:05:03 GMT
I would look into the following Patterns:

BusinessDelegate , SessionFacade


For Database connectivity with EJBs you should also look at
servicelocator.



Typically what I do is:

Have an action:
	To retrieve data from a database -- I pass all necessary
interface parameters to a BusinessDeleget.  The business delegate does
all of the work to prevent tier leakage.

	A BusinessDelegate will pass back a ValueObject (JavaBean) to a
JSP Page.

	I'll save that bean in a request or session attribute for use
within the JSP page.

Hope this gives you some insight.  

Here is a code snippet:

    public ActionForward findOrderDetail(ActionMapping _mapping,
ActionForm  _form, HttpServletRequest _request, HttpServletResponse
_response )
    {
	  UserInfo _userInfo = getUserInfo();//private method to get
user info
        String _userId = "null user";
        ActionErrors _errs = new ActionErrors(); 
        FindOrderDetailActionFormBean _params =
(FindOrderDetailActionFormBean) _form;        
        try
        {
            getConsolePrinting(this.getResources(_request));
           _errs = checkActionErrors(_mapping, _form, _request);  
           if(_errs.size()==0)
           {
               
                Logger.debug( "[MyOrdersDispatchAction.java][public
ActionForward findOrderDetail(ActionMapping _mapping, ActionForm  _form,
HttpServletRequest _request, HttpServletResponse _response)][started
with 0 Errors Found.]");
               IOrderManagerPDA _mgr =
OrderManagerBD.getOrderManagerPDA();
                Logger.debug ( "[MyOrdersDispatchAction.java][ public
ActionForward findOrderDetail(ActionMapping _mapping, ActionForm  _form,
HttpServletRequest _request, HttpServletResponse
_response)][IOrderManager Created And Retrieved. Params Recovered from
FindOrderDetailActionFormBean. User Id is {"+_userId+"} Location is
{"+_params.getLocation()+"}  Order Number is {
"+_params.getOrderNumber()+" } ]");

			//THIS IS A VALUE OBJECT BEAN THAT YOU SHOULD
CREATE IN
			//YOUR BUSINESS DELEGATE AND USE IN YOUR JSP
PAGES
               IOrderVOPDA orderVO = _mgr.getOrder(_userId ,
_userInfo.getregionId(),  _params.getLocation(),
_userInfo.getisHybridLocation() , _userInfo.getbillingSystem(),
_userInfo.getbillingSystemText() ,
Integer.parseInt(_params.getOrderNumber()) );
               if( orderVO != null )
               {
                   _request.setAttribute("orderVO" , orderVO );
                    Logger.debug( "[MyOrdersDispatchAction.java][private
ActionForward findOrderDetail(ActionMapping _mapping, ActionForm  _form,
HttpServletRequest _request, HttpServletResponse _response)][
Initializing Location to Location is {"+_params.getLocation()+"} .
Returning {"+_SUCCESS+"}.  User Id is {"+_userId+"}  Order Number is {
"+_params.getOrderNumber()+" } ]" );
Logger.debug("[MyOrdersDispatchAction.java][private ActionForward
findOrderDetail(ActionMapping _mapping, ActionForm  _form,
HttpServletRequest _request, HttpServletResponse _response)][ Session
Value of orderVO has been initialized.  Returning {"+_SUCCESS+"}.  User
Id is {"+_userId+"} Location is {"+_params.getLocation()+"}  Order
Number is { "+_params.getOrderNumber()+" } ]" );
                   _request.getSession().setAttribute("sessionLocation"
, _params.getLocation() );                    
                   return _mapping.findForward(_SUCCESS);
               }
               else
               {
                    throw new FindOrderDetailException("Order Not Found.
NOT FAILURE.");
               }
           }
           else
           {
               throw new FindOrderDetailException("Errors found in
request.");   
           }
        }catch(FindOrderDetailException fod)
        {
            //Return action errors to the user
	  }
    }



-----Original Message-----
From: Minghui Yu [mailto:minghuiyu@gmail.com] 
Sent: Friday, November 16, 2007 4:40 PM
To: Struts Users Mailing List
Subject: Pass Javabeans

Hi folks,

I know it is a stupid question. But how shall I pass JavaBeans from an
Action object to a JSP page? Use setAttribute('xxx',xxx)?

I have a list of JavaBeans that I want to pass to JSP pages to display
one by one.

Shall be a very simple question to anyone who is not a brand new
beginner to struts (version 1) like me :)

Thanks a lot.

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



The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure.  If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof.  Thank you.



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


Mime
View raw message