aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes What is the best way to transmit the find criteria from View to Model and to Business Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "What is the best way to transmit the find criteria from View to Model and to Business" Watch "What is the best way to transmit the find criteria from View to Model and to Business" New topic
Author

What is the best way to transmit the find criteria from View to Model and to Business

Olena Golub
Ranch Hand

Joined: Jan 17, 2005
Posts: 113
Hi All,

How do you think what is the best way to transmit the find criteria from View to Model (MVC) and than to Business logic?
Transmit it as String[] or just as two values :String name, String location? (URLyBird)
From View to Model it will be sure just two String (return nameTextField.getText(), return locationTextField.getText()).
Because IMHO it's not a good idea to write some logic in the view that creates the String[] array. But I am not sure

But what about the busines logic? What is the best way to pass the find criteria to server?

Your reply will be very much appreciated!
Olena


SCJP 1.4<br />SCJD 1.4 (in progress)
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11481
    
  94

Hi Olena,

Your view is possibly using a table model, and the table model possibly contains the record number - in which case I would only be passing the record number and customer number back to the model.

If you are not storing the record number anywhere, it could make life difficult when you try to do the update.

Regards, Andrew


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Olena Golub
Ranch Hand

Joined: Jan 17, 2005
Posts: 113
Dear Andrew,

Thanks a lot for your answer.
I do store the record number on the client: my server transmits an Array of my Records object. Every Record-Object has one recordNumber field where I store the record number.
After the user called the book-method, my update method transmits the record number and the owner to server. Am I right?

But my question was about how to avoid the hardcoding of the field�s indexes and how is efficient to define my find method. I read all records information with DataSchema, I don�t store it static.

But I need to store somewhere the indexes of name, location, owner and the deletion fields. From another side I try to avoid hardcoding. Therefore I am thinking about not to store any field�s indexes in the code but store it in the properties file and read it from the file only on the server. If the Database structure or the sequence order of the field is changed, the program shouldn�t be recompiled. I need to change the indexes only in the properties file and restart the server.
I have defined a find-Method in DataClient that will be called from the client to perform the find functionality:


My client communicates with the server with this DataClient (DataAdaptorRemote implement DataClient; I use Connection Factory).
But using my idea to handle the indexes on the server I cannot implement this method in the DataClient in this form:
find(String[] criteria)
I cannot make this because my client doesn�t know the index of the name and the index of the location. That means I cannot create the criteria on the client in this form:
String[] criteria = {selectedNameForSearch, selectedLocationForSearch, null, null, null�};
And pass this to the server (in DataClient define the findByCriteria(String[] criteria)).

And my idea is to pass only the name and location (this values from the textFields) to the server as two Strings to perform the find functionality. And the server will generate the criteria in the String[] form. Because only the server knows the indexes of the name and location (which are stored in the properities file).
And my question is. Is this idea correct?
Store the indexes in properties file, pass to the server only two Strings (name and location) and than generate the search-criteria on the server? (I have 3-tier architercture)
In other words to implement the DataClient in this way that I showed above.


Please let me know if you don�t understand what I mean (My English isn�t very good). If not, I will try to rephrase my question and idea.

Thanks a lot for your attention and help!
Olena
[ April 05, 2005: Message edited by: Olena Golub ]
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11481
    
  94

Hi Olena,
After the user called the book-method, my update method transmits the record number and the owner to server. Am I right?


Correct.

But I need to store somewhere the indexes of name, location, owner and the deletion fields. From another side I try to avoid hardcoding.


Personally I created some constants in my Data class for field names and indexes, then used these constants in my GUI to create my array of Strings to pass into the find function. I then explained this in both the Data class and in my choices document as being my way of handling potential future changes to database structure - change the order of fields and you only have to change the constants in the Data class.

Does this give you some hints?

Regards, Andrew
[ April 05, 2005: Message edited by: Andrew Monkhouse ]
Olena Golub
Ranch Hand

Joined: Jan 17, 2005
Posts: 113
Hello Andrew,
Thanks a lot for your hints!
I decided to make almost the same, but implement the storing of the indexes as a constand and create the criteria array on the server-side.
I use the 3-tier architecture and I think it should be also okey.
I need to bring forward many arguments in choises why I implement this and it should be Ok.
Thanks a lot for your useful help!
Olena
 
wood burning stoves
 
subject: What is the best way to transmit the find criteria from View to Model and to Business