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

Vic Cekvenich <[email protected]> Tue, 27 May 2003 09:57:33 -0400
Newsgroups gmane.comp.java.mvc.devel
Organization baseBeans Engineering
Message-ID <[email protected]>

Rick Reumann wrote:

>On Thu, 08 May 2003 13:03:59 -0400, Vic Cekvenich wrote:
>
>  
>
>>You need 2 beeans.
>>One is a search bean, that will capture the submit of the search screen. 
>>(deartment, name, etc.)
>>After submit, you pass values to employeeBean.populate(v_dept, 
>>v_firstName, etc.). This then display a list of employees.
>>Also, the select statment needs to be dynamic.
>>
>>    
>>
>
>Vic, after you call employeeBean.populate( v_dept, v_fisrtName, etc), you,
>at some point, need to put these properties back into bean or HashMap
>again in order for IBatis to use them for building the query (don't you) ?
>So, although I like calling employeeBean.populate( ..) like you have
>above, I end up having to build a new bean all over again? I'm wondering
>if maybe there is a better way to do this?
>  
>

Struts does this for you. On a submit, all the bean properties are set 
by Struts before the action gets executed. There is not new bean, since 
it's in scope already.
(ignore ibatis for a second, this is formbean). So Struts before the 
action gets called calls all the setters. So look at setFirstName, 
setLastName.
This sets it back to the bean's collection. (A list backed bean!).
So the formbean has it, that is key.

Then, you might want to persist this information (form bean is just in 
memory of course). So maybe you have a DB, but maybe you have MQ, or 
something else. ( I am taking you the long way there, it will help you).  
So you might want in the action chouse to say bean.save().
So action asks for the save.
But bean does the save.
So bean might need to have something like this, using a "MQ" helper.
save() {
   EmployeeMQ myEmpMQ = new EmployeeMQ();
    myEmpMQ.save(_list); // the list is the beans list (a list backed bean)

}

So the form bean delegates the save to MQ helper object. Form bean 
should never never know how the data gets saved or where, becuase... it 
a form bean, not DAO.

So then EmployeeMQ needs to recevie a list, enumerate it and save it, 
usualy using custom processing for the employee.

Of course, with use iBaits DAO. So in theory we would write 
EmployeDAO.save(List lst) that does the cusomt processing to enumerate 
the list and save.

After you do that a few times.... you notise that enumeratine employe 
list to save is similar to enumerating Departnemtn list to save.
So you get the idea of hey, lets use a generic (not specific to employe) 
helper object, or some OO techniqe to reuse the code and increase 
reliabiulity and producivity.

So iBatisHelper class in scaffolding enumerates any list and persists in 
a OO way.

XP (scaffoldingXPress) uses struts, OO and iBaits to automaticlay 
execute the CRUD. Actions have CRUD events, place holder.
But bean and dao have helper methods that automiaticaly save the list 
for you, if you have you DAO map right.
Use XP please, maybe DOC it, etc. you have CVS.

(more bellow)



>Also, what is the best way for IBatis to do a search based on "IN (var1,
>var2, var3)" Do I just build a comma-delimeted String of parameters and
>pass that into IBatis such that...
>
>unitNumbers = "101,102,103,210"
>
>Put the above String unitNumbers into my bean and pass to IBatis...
>
>then in Ibatis...
>
>WHERE unit_number IN #unitNumbers# ??
>

It says in iBatis DOCs how iBatis processes a "custom" SQL parm. You can 
need to create the SQL ending dynamically. It's done a lot on search 
screens, dynamic WHERE.
Read that and let me know if you need more help.
.V

>
>
>Thanks again
>
>
>  
>

-- 
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>  basicPortal sofware
Best practice<a href ="baseBeans.com">Struts Support</a> v.1.1 helper ScafflodingXPress