What is your strategy for form validation when using MVC pattern?

This is more of a general discussion topic and will not necessarily have a correct answer. I'm using some of the Flex validator components in order to do form validation, but it seems I'm always coming back to the same issue, which is that in the world of Flex, validation needs to be put in the view components since in order to show error messages you need to set the source property of the validator to an instance of a view component. This again in my case seems to lead to me duplicating the code for setting up my Validators into several views. But, in terms of the MVC pattern, I always thought that data validation should happen in the model, since whether or not a piece of data is valid might be depending on business rules, which again should be stored in the model. Also, this way you'd only need to write the validation rules once for all fields that contain the same type of information in your application.
So my question is, what strategies do you use when validating data and using an MVC framework? Do you create all the validators in the views and just duplicate the validator if the exact same rules are needed in some other view, or do you store the validators in the model and somehow reference them from the views, changing the source properties as needed? Or do you use some completely different strategy for validating forms and showing error messages to the user?

Thanks for your answer, JoshBeall. Just to clarify, you would basically create a subclass of e.g. TextInput and add the validation rules to that? Then you'd use your subclass when you need a textinput with validation?
Anyway, I ended up building sort of my own validation framework. Because the other issue I had with the standard validation was that it relies on inheritance instead of composition. Say I needed a TextInput to both check that it doesn't contain an empty string or just space characters, is between 4 and 100 characters long, and follows a certain pattern (e.g. allows only alphanumerical characters). With the Flex built in validators I would have to create a subclass or my own validator in order to meet all the requirements and if at some point I need another configuration (say just a length and pattern restriction) I would have to create another subclass which duplicates most of the rules, or I would have to build a lot of flags and conditional statements into that one subclass. With the framework I created I can just string together different rules using composition, and the filter classes themselves can be kept very simple since they only need to handle a single condition (check the string length for instance). E.g. below is the rule for my username:
library["user_name"] = new EmptyStringFilter( new StringLengthFilter(4,255, new RegExpFilter(/^[a-z0-9\-@\._]+$/i) ) );
<code>library</code> is a Dictionary that contains all my validation rules, and which resides in the model in a ValidationManager class. The framework calls a method <code>validate</code> on the stored filter references which goes through all the filters, the first filter to fail returns an error message and the validation fails:
(library["user_name"] as IValidationFilter).validate("testuser");
I only need to setup the rule once for each property I want to validate, regardless where in the app the validation needs to happen. The biggest plus of course that I can be sure the same rules are applied every time I need to validate e.g. a username.
The second part of the framework basically relies on Chris Callendar's great ErrorTipManager class and a custom subclass of spark.components.Panel (in my case it seemed like the reasonable place to put the code needed, although perhaps extending Form would be even better). ErrorTipManager allows you to force open a error tooltip on a target component easily. The subclass I've created basically allows me to just extend the class whenever I need a form and pass in an array of inputs that I want to validate in the creationComplete handler:
validatableInputs = [{source:productName, validateAs:"product_name"},
                     {source:unitWeight, validateAs:"unit_weight", dataField:"value"},
               {source:unitsPerBox, validateAs:"units_per_box", dataField:"value"},
                    {source:producer, validateAs:"producer"}];
The final step is to add a focusOut handler on the inputs that I want to validate if I want the validation to happen right away. The handler just calls a validateForm method, which in turn iterates through each of the inputs in the validatableInputs array, passing a reference of the input to a suitable validation rule in the model (a reference to the model has been injected into the view for this).
Having written this down I could probably improve the View side of things a bit, remove the dependency on the Panel component and make the API easier (have the framework wire up more of the boilerplate like adding listeners etc). But for now the code does what it needs to.

Similar Messages

  • What's your strategy for in-memory databases?

    The recent Lattanze Center research study identified trends that you cannot afford to ignore.  Dr. Elliot King will present the latest research during an informative webinar entitled: u201CIn-Memory Database Adoption is Gaining Momentum.  Whatu2019s your strategy?u201D
    For more information: http://bit.ly/kDpsfH 
    When:                 June 2 at 10:30 AM PDT.
    Duration:     45 Minutes
    Cost:               Free
    Location:          At your computer
    Space is limited, so register now @ http://bit.ly/ilgFot
    Besides learning about the latest trends within In-Memory Database technologies, youu2019ll also receive a free copy of a new White Paper, u201CMaking the Business Case for In-Memory Databasesu201D and the Executive Summary of the recent research from the Lattanze Center for Business Excellence.
    Thursday, June 2, 10:30 AM PDT. Register now @ http://bit.ly/ilgFot  Space is limited!

    Well, it seems like most of you simply read the
    various texts and try the vendors' examples. I'm
    surprised that no one mentioned ever having bought a
    prototype application from the onset. "bought"? What's that mean? You don't buy prototypes. You download evaluation versions, maybe.
    I try to find sample code and tweak it to see the effects. Otherwise, I start writing small sample code an build on that.
    I consider myself a reasonably competent core Java
    programmer, but I had serious difficulty configuring
    and merging its related technologies. There were so
    many disjointed pieces of instructional information
    that the additional research time really hurt our
    budget severely. Not an uncommon thing, I'm sure. There's a lot of stuff. But don't bother learning all of it. Not in detail, at least. It's a good idea to familiarize yourself with the names of packages/libraries and what they do. But only really learn what you need to learn for what you need to do. The next project you will probably need other things, so you learn them then.
    bsampieri,
    I've setup Tomcat and tried the examples--in fact, I
    normally follow tutorials for all products I hope to
    use. Problem is, the examples and tutorials never
    address my specific needs. So, I usually inch toward
    my goal by spending weeks or months in forums to
    continue where the tutorials leave off. Anything complex is going to not be there.... the trick is to identify pieces that you can pull out to build more complex apps. And the fact that JSP/servlets have the issue of being compounded by all the HTML/CSS/JS and HTTP protocol ... I don't want to say limitiations, exactly... Well, it just makes things more complex and harder to know what you need.
    Perhaps you guys are much faster and smarter than
    I...or you have a much bigger budget :)Probably not... on either account.

  • What's your strategy for WebService errors that aren't raised through fault handler?

    Is there a way to underride the default functionality of
    WebService.as? I can't find the source code in the SDK, so I'm
    assuming this part of Flex isn't Open Source.
    I find that using WebServices that there are a lot of errors
    that potentially occur that I can't capture in the UI. Or, let me
    rephrase that, that I haven't been able to figure out how to
    capture in the UI.
    For example, the following "Could not load WSDL" error
    occurs. Now, I could probably devise a strategy around checking
    that the connection is alive and such, but then I've seen other
    errors that occur in the WebService base classes that are all fired
    asyncronously.
    Is there a way to add a default handler that capures these
    types of errors? (They're not captures by FaultHandlers).
    I can't have a UI that displays the big white box to end
    users with a stack trace. Thanks.
    [RPC Fault faultString="Could not load WSDL"
    faultCode="Server.NoServicesInWSDL" faultDetail="No
    <wsdl:service> elements found in WSDL at ."]
    at
    mx.rpc.wsdl::WSDL/getService()[E:\dev\flex_3_beta3\sdk\frameworks\projects\rpc\src\mx\rpc \wsdl\WSDL.as:256]
    at
    mx.rpc.wsdl::WSDL/getPort()[E:\dev\flex_3_beta3\sdk\frameworks\projects\rpc\src\mx\rpc\ws dl\WSDL.as:182]
    at mx.rpc.soap::WebService/
    http://www.adobe.com/2006/flex/mx/internal::wsdlHandler()[E:\dev\flex_3_beta3\sdk\framewor ks\projects\rpc\src\mx\rpc\soap\WebService.as:267
    at flash.events::EventDispatcher/dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at
    mx.rpc.wsdl::WSDLLoader/checkLoadsOutstanding()[E:\dev\flex_3_beta3\sdk\frameworks\projec ts\rpc\src\mx\rpc\wsdl\WSDLLoader.as:195]
    at
    mx.rpc.wsdl::WSDLLoader/resultHandler()[E:\dev\flex_3_beta3\sdk\frameworks\projects\rpc\s rc\mx\rpc\wsdl\WSDLLoader.as:173]
    at flash.events::EventDispatcher/dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at mx.rpc::AbstractInvoker/
    http://www.adobe.com/2006/flex/mx/internal::dispatchRpcEvent()[E:\dev\flex_3_beta3\sdk\fra meworks\projects\rpc\src\mx\rpc\AbstractInvoker.as:175
    at mx.rpc::AbstractInvoker/
    http://www.adobe.com/2006/flex/mx/internal::resultHandler()[E:\dev\flex_3_beta3\sdk\framew orks\projects\rpc\src\mx\rpc\AbstractInvoker.as:198
    at
    mx.rpc::Responder/result()[E:\dev\flex_3_beta3\sdk\frameworks\projects\rpc\src\mx\rpc\Res ponder.as:48]
    at
    mx.rpc::AsyncRequest/acknowledge()[E:\dev\flex_3_beta3\sdk\frameworks\projects\rpc\src\mx \rpc\AsyncRequest.as:81]
    at
    DirectHTTPMessageResponder/completeHandler()[E:\dev\flex_3_beta3\sdk\frameworks\projects\ rpc\src\mx\messaging\channels\DirectHTTPChannel.as:387]
    at flash.events::EventDispatcher/dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at flash.net::URLLoader/onComplete()

    I found out at FlexCOders, that when I'm not using the Debug
    version of the Player that these errors should correctly propogate
    to the Fault handler.

  • What's your strategy for learning Java technologies?

    Or, in other words, how do YOU acquire knowledge that is necessary for implementing Java technologies?
    After having spent one-and-a-half years developing an enterprise app, I've gained lots of knowledge about Java and some surface knowledge about its related technologies (JBoss, Hibernate, Ant, XDoclet, NetBeans and probably some others I can't think of at the moment).
    I'm now realizing that -- although the standalone prototype version of my program is growing mature -- I've still got lots to learn for refactoring it to a web platform. For example, I 've done small test projects using Servlets, but haven't done any work with JSP (or HTML for that matter) yet.
    Now, I'm sure I can learn JSP etc., but the questions I ask myself are: how long will it take?
    It's a rhetorical question of course (I don't expect an answer from you, the reader) However, it's an important issue because the months or years I spend fumbling around learning these new technologies, are time I could otherwise spend on the business logic and functionality of my program.
    So, how do you guys acquire knowledge of technologies? Official training perhaps? Or do you simply experiment until it works? Or do you rely on your company's knowledge base (e.g. someone in your company knows how it works)? Or do you get prototypes built from someone who already knows how it works?
    I�m really curious about this and would appreciate your thoughts.
    Thanks in advance,
    P

    Well, it seems like most of you simply read the
    various texts and try the vendors' examples. I'm
    surprised that no one mentioned ever having bought a
    prototype application from the onset. "bought"? What's that mean? You don't buy prototypes. You download evaluation versions, maybe.
    I try to find sample code and tweak it to see the effects. Otherwise, I start writing small sample code an build on that.
    I consider myself a reasonably competent core Java
    programmer, but I had serious difficulty configuring
    and merging its related technologies. There were so
    many disjointed pieces of instructional information
    that the additional research time really hurt our
    budget severely. Not an uncommon thing, I'm sure. There's a lot of stuff. But don't bother learning all of it. Not in detail, at least. It's a good idea to familiarize yourself with the names of packages/libraries and what they do. But only really learn what you need to learn for what you need to do. The next project you will probably need other things, so you learn them then.
    bsampieri,
    I've setup Tomcat and tried the examples--in fact, I
    normally follow tutorials for all products I hope to
    use. Problem is, the examples and tutorials never
    address my specific needs. So, I usually inch toward
    my goal by spending weeks or months in forums to
    continue where the tutorials leave off. Anything complex is going to not be there.... the trick is to identify pieces that you can pull out to build more complex apps. And the fact that JSP/servlets have the issue of being compounded by all the HTML/CSS/JS and HTTP protocol ... I don't want to say limitiations, exactly... Well, it just makes things more complex and harder to know what you need.
    Perhaps you guys are much faster and smarter than
    I...or you have a much bigger budget :)Probably not... on either account.

  • To set the short cut key for the menu when using CommandDesign pattern

    Hi All
    I have a menu File which has two menu items Load and save.
    Here for implementing the actionperformed iam using the command design pattern.
    Now iam not able to set the short cut key for the menu item......
    Please help me..............
    Thanks
    Arch

    The Java Tutorials: [How to Use Menus|http://java.sun.com/docs/books/tutorial/uiswing/components/menu.html]
    db

  • What is a valid location for autorecovery files when using Word for MAC?

    What is a valid location for autorecovery files when using Word for MAC?

    Microsoft Word for Mac support forums is probably a better place to ask.

  • Hi Apple! My iphone 4g has restored and I can't retrieve the account. I have tried the password renewal that will be send on my mail but unfortunately my mail has been deactivated also.what is your solution for this kind of cases? This is so unfair.

    Hi Apple! My iphone 4g has restored and I can't retrieve the account. I have tried the password renewal that will be send on my mail but unfortunately my mail has been deactivated also.what is your solution for this kind of cases? This is so unfair.

    http://support.apple.com/kb/HT5312
    If you established a rescue email address, there will be a link on the "Passwords & Security" page of id.apple.com.  Clicking the link will send the reset to your rescue email address (NOTE:  This is not the same address as your Apple ID email)
    If there is no link on the page, then you didn't establish a rescue email address.  Contact AppleCare at 800.694.7466, and ask for account security.  You will need to answer some questions to verify your identity, AND you will need access to a computer to generate a temporary support pin.
    HTH

  • Hello, I would like to know what is your policy for higher educational institutes or with whom should I be in touch with? Thanks

    I would like to know what is your policy for higher educational institutes or with whom should I be in touch with?
    Thanks a lot for your help,

    Apple HED has no published email addresses, and since Apple does not sell their products directly in Israel, you will probably need to work through local distributors or dealers in any case. I would suggest contacting Apple's authorized distributor, iConGroup:
    http://www.icongroup.co.il
    Regards.

  • What are the ranges for correct skin tones using RGB%?

    What are the ranges for correct skin tones using RGB%?  Used to using a scale from 0 to 255.  But with LR it's RGB  , I know 100% RGB is white.  What do you use for %?

    While I whole heartedly agree that we should not be constrained to hard and fast numbers for accurate skin tones ... LR does offer an RGB color readout ... I am assuming they made those percentages available for the user to monitor the breakdown of specific color values for a reason ... so we could have an indication of how a specific color in an image will be reproduced ...
    I liken this to using a speedometer ... while many experienced drivers in well tuned vehicles can travel on the highway at the prescribed legal speed limit without really monitoring the readout on the dashboard ... however, there are times when they would like to verify the speed at which they are traveling ... the RGB color percentage readout in LR is no different ... just a source of information to verify you are achieving what you desire ...
    Again, going by specific numbers in this instance, I believe, could lead to problems ... there may be times when you may desire or actually need to adjust skin tones ... even though a pleasing WB has been achieved ... the relationship of R, G and B can be used to get you there.
    From what I have researched and put into practice with LR the following seems to be a good starting point and the data was borrowed from "the pixelation" blog:
    R: highest %
    G: middle %
    B: lowest %
    To get a little more specific. In general,
    R: Y + (15-20)
    G: average of R and B
    B: R – (15-20)
    For example, the following values represent common Caucasian skin tones using the rules above:
    * R: 80%; G: 70%; B: 60%. R is 20 points higher than B, and G is midway between R and B. That’s perfect.
    *  R: 86%, G: 78%; B: 70% also reflects a nicely balanced skin tone.  Again, G is midway between R and B, and R is 16 points higher than B. This, too, illustrates a great relationship among the colors.

  • I have a late 2009 iMac, with a Nvidia 9400 Graphics card.  I was wondering what my options are for upgrading.  I use Windows 7 via Bootcamp, so I need a card that is compatible.

    I have a late 2009 iMac, with the default Nvidia 9400 Graphics card.
    I was wondering what my options are for upgrading.  I use Windows 7 via Bootcamp, so I need a card that is compatible/has available drivers.
    This is for gaming. On the lowest settings of "Call of Duty 4", I get about 100 FPS... Was hoping to be able to play on higher resolution w/o the fps lag.
    I'm not good with the hardware part of computers at all, but know how to get around the OS.

    In most cases the graphics cards in iMacs are Not upgradeable.  They are usually soldered to the logic board.  RAM is considered, along with harddrives, the only component that is upgradeable in an iMac, unlike in PC's.  So basically you would need to sell your unit and purchase an iMac with a more powerful graphics card.
    Hope this helps

  • I need to publish a magazine in arabic and english - what should I buy - for how much to use 15 mac books for my students to use indesign?

    I need to publish a magazine in arabic and english - what should I buy - for how much to use 15 mac books for my students to use indesign?

    You can only return the machine if you're within 14 days of purchase - otherwise you're just 'stuck' with what you purchased (unless you sell it, of course).
    I always recommend that Retina owners order 16GB of RAM as the RAM is not upgradable - it's soldered onto the logic board.
    Your call - if you're with 14 days of purchase, take it back and exchange for a 16GB model. Or sell it and buy a model with 16GB. The higher amount of memory will allow you to run far more memory-hungry apps concurrently.
    Good luck,
    Clinton

  • [svn:fx-trunk] 10545: Make DataGrid smarter about when and how to calculate the modulefactory for its renderers when using embedded fonts

    Revision: 10545
    Author:   [email protected]
    Date:     2009-09-23 13:33:21 -0700 (Wed, 23 Sep 2009)
    Log Message:
    Make DataGrid smarter about when and how to calculate the modulefactory for its renderers when using embedded fonts
    QE Notes: 2 Mustella tests fail:
    components/DataGrid/DataGrid_HaloSkin/Properties/datagrid_properties_columns_halo datagrid_properties_columns_increase0to1_halo
    components/DataGrid/DataGrid_SparkSkin/Properties/datagrid_properties_columns datagrid_properties_columns_increase0to1
    These fixes get us to measure the embedded fonts correctly when going from 0 columns to a set of columns so rowHeight will be different (and better) in those scenarios
    Doc Notes: None
    Bugs: SDK-15241
    Reviewer: Darrell
    API Change: No
    Is noteworthy for integration: No
    tests: checkintests mustella/browser/DataGrid
    Ticket Links:
        http://bugs.adobe.com/jira/browse/SDK-15241
    Modified Paths:
        flex/sdk/trunk/frameworks/projects/framework/src/mx/controls/DataGrid.as
        flex/sdk/trunk/frameworks/projects/framework/src/mx/controls/dataGridClasses/DataGridBase .as
        flex/sdk/trunk/frameworks/projects/framework/src/mx/controls/dataGridClasses/DataGridColu mn.as

    Hi Matthias,
    Sorry, if this reply seems like a products plug (which it is), but this is really how we solve this software engineering challenge at JKI...
    At JKI, we create VI Packages (which are basically installers for LabVIEW instrument drivers and toolkits) of our reusable code (using the package building capabilities of VIPM Professional).  We keep a VI Package Configuration file (that includes a copy of the actual packages) in each of our project folders (and check it into source code control just as we do for all our project files).  We also use VIPM Enterprise to distribute new VI Packages over the network.
    Also, as others have mentioned, we use the JKI TortoiseSVN Tool to make it easy to use TortoiseSVN directly from LabVIEW.
    Please feel free to contact JKI if you have any specific questions about these products.
    Thanks,
    -Jim 

  • Choose accent color for hovered icons when using dark interface in Bridge?

    How about add the ability to choose the accent color for hovered icons when using a dark interface in Bridge?  Currently, the icon color remains orange and unchangeable.  Personally, I would prefer a blue accent color to match my system.  Any chance of making this possible in CS6?

    Oh, I should add that I'm looking for solutions somewhat up-to-date and/or are related to or designed for 10.6 Snow Leonard. I did a search for answers before asking the question, and the (mostly unsatisfactory) answers I found were all from several years ago and applied to earlier versions of OSX (10.3, 10.4, etc.), and therefore no longer were relevant or usable.

  • Any solution for 4280 error when using Itunes to burn CDs?

    Any solution for 4280 error when using Itunes to burn CDs?

    http://support.apple.com/kb/TA38101?viewlocale=en_US

  • What's best strategy for dealing with 40+ hours of footage

    We have been editing a documentary with 45+ hours of footage and presently have captured roughly 230 gb. Needless to say it's a lot of files. What's the best strategy for dealing with so much captured footage? It's almost impossible to remember it all and labeling it while logging it seems inadequate as it difficult to actually read comments in dozens and dozens of folders.
    Just looking for suggestions on how to deal with this problem for this and future projects.
    G5 Dual Core 2.3   Mac OS X (10.4.6)   2.5 g ram, 2 internal sata 2 250gb

    Ditto, ditto, ditto on all of the previous posts. I've done four long form documentaries.
    First I listen to all the the sound bytes and digitize only the ones that I think I will need. I will take in much more than I use, but I like to transcribe bytes from the non-linear timeline. It's easier for me.
    I had so many interviews in the last doc that I gave each interviewee a bin. You must decide how you want to organize the sound bytes. Do you want a bin for each interviewee or do you want to do it by subject. That will depend on you documentary and subject matter.
    I then have b-roll bins. Sometime I base them on location and sometimes I base them on subject matter. This last time I based them on location because I would have a good idea of what was in each bin by remembering where and when it was shot.
    Perhaps, you weren't at the shoot and do not have this advantage. It's crucial that you organize you b-roll bins in a way that makes sense to you.
    I then have music bins and bins for my voice over.
    Many folks recommend that you work in small sequences and nest. This is a good idea for long form stuff. That way you don't get lost in the timeline.
    I also make a "used" bin. Once I've used a shot I pull it out of the bin and put it "away" That keeps me from repeatedly looking at footage that I've already used.
    The previous posts are right. If you've digitized 45 hours of footage you've put in too much. It's time to start deleting some media. Remember that when you hit the edit suite, you should be one the downhill slide. You should have a script and a clear idea of where you're going.
    I don't have enough fingers to count the number of times that I've had producers walk into my edit suite with a bunch of raw tape and tell me that that "want to make something cool." They generally have no idea where they're going and end up wondering why the process is so hard.
    Refine your story and base your clip selections on that story.
    Good luck
    Dual 2 GHz Power Mac G5   Mac OS X (10.4.8)  

Maybe you are looking for

  • Table of contents in PDF files

    IBooks gives two options for displaying the Table of Contents for PDF files-thumbnails or a conventional table. The thumbnails view is useless to me, and I would like the conventional table view to appear by default. Unfortunately, the TOC almost alw

  • Reports hide data lines in footer or header

    Hi there, not sure this is the right section. But I'll try anyhow. We recently moved our reports from VS2005 to VS2010. The reports worked fine with the old redist package at our clients systems. Since we migrated to the new development environment a

  • How to I get search at open window upper right corner to work.

    How to I get search at open window upper right corner to work. I click on "search" and nothing happens in Yosemite.

  • Client side configuration

    Hi Everybody, Thanks to all of the oracle experts. We installed oracle 10.2 RAc database on the server side using 2 nodes on solaris 10. Raw devices are used for clusterware installation. ASM is configured for database shared files. Now i want to con

  • How to delete my balance from itune gift card.

    how can i delete itune balance from my account. i cant change my region.