Re: Validation in swing using struts-like approach
sarath wrote:
I am looking for validation method like in struts, where we can
mention all the validation scenarios in an XML or a config file, and
the validation happens as mentioned in that file.
It requries that the validations should be done in the client side
rather than the server side (Like in ActionForm in struts)
Is it possible to have such an approach?
Can I use ActionForm itself in some way for the same?
I am not aware of a pre-existing framework to permit declarative validation
for Swing, but there may well be one.
I don't think ActionForms from Struts will give you a problem as such,
although you probably should not derive them from a Struts class but instead
use your own interface. I have done this myself for a few projects, most of
them from before I learned Struts. What you will not get this way is the
equivalent of the Struts controller servlet, that is, the dispatcher for the
UI event loop.
OTOH, ActionForms aren't inherently connected to declarative validation rules
anyway. That is something that the Struts framework takes care of; it parses
the validation declarations, including custom validation classes if specified,
in terms of predefined validator interfaces and classes within Struts. By the
time the controller invokes your ActionForm (or in more universal terms, the
action handler class), it's already loaded a bunch of classes and has methods
to call them to enforce the rules.
Swing itself follows a Model-View-Controller paradigm, same as Struts. The
rough equivalent to ActionForm is XxxListener. The EDT (Event Dispatch
Thread) is the equivalent of the Struts controller servlet.
It is likely that rich-client frameworks like Eclipse or Netbeans will give
you declarative validation. I am not familiar enough with either as a
rich-client platform to say for sure.
Java generally supports property sheets for JavaBeans, so that would let you
define validation via property files. You still need to define your own
property and value sets, and parse the properties in custom code, but it's not
hard to use beans this way.
--
Lew