My understanding for making Struts action thread safe you shouldn't have 
instance variable in any action class. Correct ?
( it should be OK if you have read only variable ). But to make app for 
flexible, so in future you can change value of variable and pass it around
helper functions, I made variable local. as shown in  the following code.

Two questions .
1.  I am getting Null pointer exception in setUpForInsertOrUpdate even 
after calling initialize ! How come ?
 

2.   This service objects are used by many dispatch actions methods for my 
app, it contains data from DAO object.
       What is the best practice so I don't keep declaring instance 
variable in all DispatchAction methods like ( update/delete) and so on.


Code is like this.


public class SectorAction extends DispatchAction {
 

 public void  initialize(HttpServletRequest request,SectorService 
sectService,SectorOwnerService sectOwnerService) throws Exception
    {
 
        sectService = (SectorService) 
request.getSession().getAttribute("SectorService");
                sectOwnerService = (SectorOwnerService) 
request.getSession().getAttribute("SectorOwnerService");
 
    }
 

    public ActionForward setUpForInsertOrUpdate(ActionMapping mapping, 
ActionForm form, HttpServletRequest request, HttpServletResponse  
response) throws Exception {
        SectorService sectService = null;
                SectorOwnerService sectOwnerService = null;
 
 
                initialize(request,sectService,sectOwnerService);
 
                SectorForm sectForm = (SectorForm)form;

                WebSector sector = 
sectService.getSector(sectForm.getSectorId());
                BeanUtils.copyProperties(sectForm, sector);

        return mapping.findForward(Constants.SUCCESS);
     }
      public ActionForward delete(ActionMapping mapping, ActionForm form, 
HttpServletRequest request, HttpServletResponse response) throws  
Exception {
        SectorService sectService = new SectorDaoService();
                SectorOwnerService sectOwnerService = new 
SectorOwnerDaoService();
 
        initialize(request,sectService,sectOwnerService);  

 
        SectorForm sectForm = (SectorForm)form;
 
        sectService.deleteSector(sectForm.getSectorId());
        populateSectors(request,sectService,sectOwnerService);
        return mapping.findForward(Constants.SUCCESS);
    }

}

in my action forward I can see initialize has valid sectService and 
sectOwnerService objects but once initialze comes back to 
setUpForInsertOrUpdate method this service objects are null and I am 
getting NullPointerException.


I thought even if calls in java are passed by value, it should 
some how after I call initialize and get my two service objects, i


Digant 
This communication is for informational purposes only. It is not intended
as an offer or solicitation for the purchase or sale of any financial
instrument or as an official confirmation of any transaction. All market prices,
data and other information are not warranted as to completeness or accuracy and
are subject to change without notice. Any comments or statements made herein 
do not necessarily reflect those of JPMorgan Chase & Co., its subsidiaries 
and affiliates

Reply via email to