From: Tony F. <ton...@ya...> - 2003-03-04 21:51:14
|
John, Here's my understanding of how it currently works. Let's consider a normal Java Exception. To create an exception that has text associated with it you must create the exception instance using the Exception(String s) constructor. As an example let's assume we create an exception that contains the message "Unable to communicate with the Credit Processing System at this time.". It is often helpful for errors that are to be displayed to the user to also contain an errorCode. In the mainframe world, an errorCode like "22" would usually be associated with this msg. The framework allows for such an errorCode, only it's more flexible since it is a string. Thus for our errorCode we might choose something like "CreditSysDown". This errorCode need not ever be shown to the user (though in some cases it can be helpful) but some of the advantages it provides are: 1) Quite often the same Exception class is used for various exceptions (ie: SystemDownException) but with various messages for each exception. Having an errorCode associated with the message would allow you to perhaps setup a mapping table to know what field on the screen might need to be turned to red. Consider a fat client GUI that shows a graphical status of all systems it monitors. If a system is down it changes that icon red (it's not the best example, as you could argue why not just ping that system - but in calls to mainframes you might have to wait for a JMS call to throw an exception to know if that system is down). In such an example the exception might be a SystemDownException, but the errorCode might be "CreditSysDown", "MortgageSysDown", etc. The mapping table might be driven off of these codes then. 2) With an errorCode associated to a message, you can use the errorCode as a key to resolving the actual msg from within an external file. This allows for internationalization since the msg will be resolved using a ResourceBundle, and it also keeps all your messages in a single place. (An added benefit of this is that no longer do you need to change the text of the exception in multiple places throughout your code if you decide you don't like the text being shown for a message. If you aren't familiar with ResourceBundles, please see Struts docs for examples of errorKeys contained in text files. As it stands the Errors object is limited in 2 ways: that it cannot resolve msgs from a file, and it doesn't allow you to pass in args that need to be replaced in a msg. This will be part of the code I am soon to put into CVS. I do not have the code with me at the minute, but off the top of my head I believe these are some of the method signatures it will have: rejectValue(String field,String errorCode, String message) - NOT resolving from a file (literally take the msg I am passing in) rejectValue(String field, Locale locale, String errorCode, Object[] errorArgs, String defaultMessage) - TO resolve the errorCode to a message contained within a file To be honest, I'm not as familar with the Validator pattern. From my recollection of that chapter in the book, I thought Rod advocated having a separate object that contained all validation logic that both the Business Object layer, and the Controller could call. Better to have Rod field that question. John Cavacas <joh...@sa...> wrote:Tony, Thanks for the reply. That was my guess as well about the code property. But it also leads to another question. The method signature is also includes the "message" parameter. So that is point of having both "code" and "message" if the "code" would contain the message? Do I perhaps not understand the intended use? In my tests the functionality seems to be working as expected (not including the codes as I'm not currently using them). I'm using the BindException implementation class to hold the errors for my domain object validator. My original idea was to use this validator to perform syntactic and semantic validation, but I've quickly realized that the only way this validator can do that is if it has access to the business object, which in my opinion it can't or shouldn't have. It seems that the validator interface is really more suited for syntactic validation to occour for example before the object is sent to the business method. The only way that I can think of making that work is if somehow the validator object and the business object had access to the same Errors object. To be more specific... My validator object can check for example to see if an email address looks like it is properly formatted. However I also need to know if this particular email message already exists in my database because my business rule dictates that there cannot be duplicate email addresses. In order for the validator object to know that, it would have to ask the business object to perform that look up, which in my opinion doesn't seem right. So my current solution is to perform the syntactic validation on the validator, pass the domain object (a command) to the business method, and let the business method perform the business rules, which in case of problems would be expressed as typed exceptions. Does this make sense? Or is there a way to actually make the validator perform both functions? Thanks, John > -----Original Message----- > From: Tony Falabella [mailto:ton...@ya...] > Sent: Monday, March 03, 2003 8:58 PM > To: joh...@sa...; spr...@li... > Subject: RE: [Springframework-developer] purpose of code in > Errors.rejectValue() > > John, > > I believe the "code" field refers to an "ErrorCode" that could be used > as a string value of an error msg that is associated with that Error. > (Similar to a mainframe returning an error code when a bad message is > returned to a user, only since it's a string it can actually be a bit > descriptive for the user.) See the javadocs for the > com.interface21.core.ErrorCoded interface for a detailed description. > > I am making some changes to the framework (then will pend review from > Rod) to allowing ResourceBundles to be tied into a few things within the > framework a little better. > > Right now, I believe the API to obtaining messages for anything in the > framework is limited in 2 ways: > 1) Does not allow parameters to be passed to it. > 2) Some of the APIs do not allow a Locale to be passed into them (the > Errors.rejectValue(...) is a good example. > > My changes should address both these issues. Also, I am attempting to > add a subclass to the NestedException class (that merely calls a helper > object) that will allow Exceptions themselves to obtain their messages > from a ResourceBundle. I have this working now for myself, but wish to > make a few changes to it to model the behavior of how log4j allows you > to point various classes to various files (ie: Exceptions in this > package look to this file for their msgs). I am a few days away from a > code review on this. > > As far as answering your question about examples, I'm sorry but I don't > have any examples to give you. > > > -----Original Message----- > From: spr...@li... > [mailto:spr...@li...] On Behalf > Of John Cavacas > Sent: Monday, March 03, 2003 4:03 PM > To: spr...@li... > Subject: [Springframework-developer] purpose of code in > Errors.rejectValue() > > I was wondering if someone, most likelly Rob, could tell me what the > purpose of the String code parameter is in Errors.rejectValue(String > field,String code,String message) method. > > And like my previous email "Validation usage examples and questions" i > am looking for further clarification and proposed usage of the > validation and DataBinding techniques in the framework. > > Thanks, > John > > > > ------------------------------------------------------- > This SF.net email is sponsored by: Etnus, makers of TotalView, The > debugger > for complex code. Debugging C/C++ programs can leave you feeling lost > and > disoriented. TotalView can help you find your way. Available on major > UNIX > and Linux platforms. Try it free. www.etnus.com > _______________________________________________ > Springframework-developer mailing list > Spr...@li... > https://lists.sourceforge.net/lists/listinfo/springframework-developer This communication is intended for the use of the individual(s) or entity it was addressed to and may contain confidential and/or privileged information. If the reader of this transmission is not the intended recipient, you are hereby notified that any review, dissemination, distribution or copying of this communication is prohibited. If you receive this communication in error, please notify the sender immediately and delete this communication from your system(s) to which it was sent and/or replicated to. (c) 2002 Sapiens Americas Corp. |