Re: Help with a design issue that I'm stumped by....

Vic Cekvenich <[email protected]> Fri, 09 May 2003 06:25:44 -0400
Newsgroups gmane.comp.java.mvc.devel
Organization baseBeans Engineering
Message-ID <[email protected]>
 comment in CAPS, since I can't nest comments more than 2 deep"

Rick Reumann wrote:

>Thanks for the comments, some more below....
>
><rick:>
>  
>
>>>If I create my SearchBean as a type of BaseBean these
>>>problems go away, but it does seem a bit heavy to make a simple bean
>>>like this a type of BaseBean.
>>>
>>>      
>>>
>
><vic:> 
>  
>
>>Agree. But since classloader loads BaseBean anyway.... its not that
>>big a deal.
>>    
>>
>
>rick:
>You're probably right, but I'll have to check my Java books again (it's
>been a while:)... because I thought I remember reading something about
>when an object extends another object it doesn't just "use" the parent
>class' fields but it actually ends up having them as part of the class
>(assuming of course they aren't private or static). Meaning that I think
>every new instance of a bean that extends BaseBean will actually 'pull
>into memory' all the BaseBean stuff. Granted this might not be that big
>of a deal, especially because simplicity and clarity is what I'm after.
>

SINCE BASEBEAN WAS LOADED ONCE, THE "HEAVY" BASEBEAN IS CLASSLOADED.

>
><vic:>
>  
>
>>Also as far as thinking .... no need :-) You have a form, the bean
>>must match form.
>>So you have a search form, and a search formBean (baseBean). It
>>matches. Each screen has it's bean, sort of.
>>To get to search form, you go to search action, that just creates the 
>>search bean in session, and passes to search screen.
>>
>>search form, then submits to EmployeList action, and the process
>>repeats. I know that is what you said, just with Struts, very little
>>to think about. I just handed things a bit same so it KISS:
>>namePg.jsp has a nameBean,java form bean that matches it. In order to 
>>get to  namePg.jsp you need to call nameAct.java.
>>
>>    
>>
><rick:>
>  
>
>>>2) Assuming this SearchBean should be a BaseBean I used it like
>>>this...
>>>
>>>First I have an EmployeeAdminAction that is associated with the
>>>EmployeeSearchBean .... possibly like...
>>>
>>>
>>><action path  ="/employeeAdmin"  
>>>       type="foo.bar.EmployeeAdminAct"
>>>       name="employeeSearchBean"    
>>>       scope="request"   			 
>>>       validate="false">
>>>             <forward name="Continue"  path="/employeeList.jsp" />
>>></action>
>>> 
>>>
>>>      
>>>
><vic:> 
>  
>
>>I make everything session scope..... just a habit.
>>    
>>
>
>rick:
>I like the opposite- everything request scope, unless I have to use
>session scope (just a habit also:)
>
><rick>
>  
>
>>>then my EmployeeAdminAction (extends BaseAction) and in there I have:
>>>
>>>
>>>public String onDisplayExec {
>>>
>>>	//try/catch removed for brevity
>>>	
>>>	EmployeeSearchBean employeeSearchBean = 
>>>		(EmployeeSearchBeanarchBean) ae.getBean();	
>>>
>>> 
>>>
>>>      
>>>
><vic:>
>  
>
>>Good!
>>
>>    
>>
><rick:>
>  
>
>>>	
>>>	//create an EmployeeBean (List backed)
>>>
>>>	EmployeeBean employeeeBean = new EmployeeBean();
>>>
>>>      
>>>
>
><vic:>
>  
>
>>Perphaps you mapped this bean in action mapping, thus no need for new,
>>
>>Struts does it for you.
>>    
>>
>
>rick:
>Ok, I didn't like that part either having to create my EmployeeBean
>there like that, but I'm not sure how else to do it. The problem is, as
>that my action to return me a List based on my SearchFormBean being
>filled out means I have to tie the SearchFormBean to the action mapping.
>In other words I need to have the user populate the JSP search form
>(which has a SearchFormBean mapped to it) so that when it submits it's
>carrying the populated SearchFormBean to the Action. How is it possible
>that I could have the EmployeeBean mapped instead? 
>

IF YOU IN ACION MAPING FOR THAT FORM, PLACED A FORM BEAN IN THE ACTION 
MAPING, STRUTS DID A NEW FOR YOU.

> 
><rick:>
>  
>
>>>	
>>>	//populate the bean using the employeeSearchBean
>>>
>>>       employeeeBean.populate( employeeSearchBean );
>>>
>>>      
>>>
><vic:>
>  
>
>>I do not do this.
>>I would do
>>
>>employeeeBean.populate (employeSeachBean.getFirstName(),
>>employeSeachBean.getDept(), ....);
>>
>>this way it is... clenaer, more reusable.
>>    
>>
>
>rick:
>Great suggestion. Thanks.
>
><rick:> 
>  
>
>>>       
>>>	
>>>	//now use the ActionEvent to put this bean in scope
>>>
>>>	ae.setBean( employeeeB );
>>>
>>>      
>>>
><vic:>
>  
>
>>Again.... if you mapped in action, Struts took care of this.
>>    
>>
>
>rick:
>(See earlier comments) Still not sure how to do this since I'm thinking
>when the form submits to "/do/getMeTheListBasedOnSearchCriteria" it will
>have to have the SearchFormBean mapped to it wouldn't it? (meaning I
>could't have the EmployeeBean mapped to the action also).
>

OK, LET ME UNDERLINE.
SEARCH FORM, HAS A SEARCH BEAN, HAS A SERCH ACTION, AND HAS NOTHING TO 
DO WITH LISTOFEMPLOYEESBEAN.
ONCE YOU SUBMIT ON SEARCH FORM, YOU GO TO LISTOFEMPLOYUESACTION.
THIS ACTION MAPING, IF YOU HAVE A FORMBEAN MAPPED IN ACTION MAPING (YOU 
DO NOT NEED TO HAVE A FORMBEAN MAPED TO A READ ONLY FORM)  DOES NOT NEED 
A SET SCOPE OR A NEW.

HTH,
V

>
><snip>
>
><vic>
>  
>
>>Yes, this does come up a lot, and I would do it just like that. Maybe
>>I should have a serch scanario in basicPortal, like find users so one
>>can set what role they are in.
>>    
>>
>
>rick:
>Actually what I'm trying to do should actually be simple. What I have is
>a list of "projects" that I want displayed. I then want to be able to
>click on the project and it will query for a list of notes that have
>been entered about this project. So all the query needs is a
>'projectId'. The simple thing is to just submit to some other
>non-BaseBeans action and pull out the projectId as a requestParameter
>and then create ProjectBean and call ProjectBean.populateAll( projectId
>). However, I can see in the future maybe other search criteria that
>will be added on a main search page, so why not build the SearchBean
>now. That's what started me down this path. I'd like to try following
>the BaseBeans approach as much as possible... otherwise I'll end up with
>all different kinds of Actions etc.
>
>Thanks again for any comments,
>
>  
>

-- 
Vic Cekvenich,
Struts Instructor,
1-800-917-JAVA

Advanced <a href ="baseBeans.com">Struts Training</a> and project recovery in North East. 
Open Source <a href ="baseBeans.com">Content Management</a>  basic
Portal sofware
Best practice<a href ="baseBeans.com">Supported Struts v.1.1</a>
framework ScafflodingXPress