Best place to put validation code?

Hey,
When using jsp and html forms for passing information from the
client to the server, where should i put the validation code? Is
it better to put the code in the bjc4 classes or to make some
FormHandler.jsp which checks wheter correct values/types typed
in the form by the user?
If i put the code in the bc4j classes, how can i then interact
with user, when he makes an error?
thx

The question is the classic stand off between resuablity and
modularity and user interface.
If you put the validation code in the client (jsp) then the user
sees the error quickly and it is relatively painless. However,
if the rules change, you must change ALL of the clients that
enforce that rule.
If you put it in the middle-tier then there is the delay in the
user feedback. The middle-tier will only validate the code on
some sort of post. However, your validation code will be in only
one place and therefore easy to maintain over time.
So what's the solution. I suggest for JSPs a combination. If the
rule is a real business rule then it needs to be validated in
the middle-tier. If it is something that is prone to user typing
error and is simple enough to be enforced within html, then it
should go there also. You must remember that those client based
rules can spread and your maintenance effort will go up.
Gary
JDev Team

Similar Messages

  • Best place to put startup code in EJB deployment?

    Hi,
    I'm working on an application which involves timer services and JMX, and I'd like to ask for your opinion on how to deal with startup of those services in an EJB deployment. If you dealt with those issues before, I'd appreciate it if you could share your experiences/best practices on the subject.
    Timer services need to be started, and MBeans need to be registered with the MBeanServer, so I'd like to see how can this be done upon application deployment.
    I'm using Sun Server as an EJB server.
    Thanks,
    Mark

    Since the ejb spec doesn't define an application initialization event, the only portable way of doing this that I've heard of is to use the ServletContextListener.contextInitialized() event to send a message to an MDB within the same application. Since EJB Timers are persistent and their identity is tied to a particular application component, the MDB's onMessage method can use getTimers() to see whether the timer already exists. If not, it's the first time the application has been deployed.
    I agree the auto-creation of timers upon deployment would be a good addition to the spec :-)
    --ken                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Where to put Validation Code?

    Up until now, Im still having second-thoughts of where to put validation code when setting attributes of an entity.
    Right now I have created lots of custom validators --(implement JbovalidatorInterface) that calls stored procedures to validate the value entered. But sometimes, i just use a ViewObject and query it on the setterAttribute method of the Entity and just manually throw a JboException of the value is invalid based on some business rule.
    Question is, what are the best practices where to put validation codes? do we have to be strict that we always put all validations on Validators or are we free to just throw JboExceptions anywhere on the BC classes' code.
    regards,
    Anton

    1. The reason I have a custom validator and I don't normally use the built in declarative validators is that the error message generated when the validation fails is fixed, only one message. I decided to have create a custom validator is that I need to test a one attribute for many cases in each case should produce a distinct error message. So if I use the built in validators, I would have to create lots of built in validators for that single attribute only. (and i have lots of entities and lots of attributes that needs business rule validation). So, I decided to create a custom validator, that calls the stored procedure, the stored procedure takes care of all test cases, for that attribute only, and I can return a dynamic error message depending on the test case that failed. What do you think about the approach?
    It's a little extra work to create a reusable validator class that will only be used once, but whether you do it that way or encapsulate the call in a helper class that your one-off method validator code delegates too, it seems similar to me. So it's more of a stylistic choice for you which you like better. Now, if your reusable validator were enable to encapsulate
    2. When I said anywhere; I meant inside the setterAttribute methods on the Entity and on the ViewRowImpl, orThe ViewImpl class or inside a method on an ApplicationModule?
    Rather than writing code in the setAttribute, I recommend using attribute-level method validators. This makes it more clear where all your validation code lives.
    I don't recommend performing validation in the view object level since entity objects are the component in the system that are tasked with handling validation. It would be easy to circumvent view level validation checks unless you make a lot of assumptions about exactly how your application is working.
    3. One other issue is that Validator methods are for validation purposes only. So its not a good idea to put in attribute setters to other attributes inside there. So you put the attribute setter logic outside of the validator usually inside the setAttribute() just after validator returns. But there are cases that is very straightfoward to put validation logic inside the setAttribute; meaning, inside the setAttribute() method, I test for a condition, if it fails, just throw a JboException, if its true, continue with the otherAttributes setter logic.
    Whether attribute setting of other attributes is performed in a setter method or in an attribute-level method validator, either way you will need conditional logic to avoid going into a validation "loop" (which eventually will throw an exception if after 10 attempts the object is still not valid at posting time.

  • Where is the best place to put custom functions?

    Hi,
    I have a composition which has a number of symbols. I have to call some custom methods externally and was wondering where is the best place to put the custom methods?
    I have seen posts that I should put the code in the CompositionReady event of the stage but I would like to put it a bit closer to the symbol.
    Is this the best place?
    Sham.

    Here is a case:
    It's a good idea if you well understand global and local variables.
    About complete event, you are right.

  • Where is the best place to put cfqueries?

    Where is the best place to put cfqueries, in the <head> </head> or before the html tag? Thanks

    So before the doctype tag? Thanks
    I just doesn't really matter.  the doctype, head, body, etc only matter to the browser; the CF tags only matter to CF.  The browser doesn't see the CFML, and CF doesn't care about the mark-up one bit: it just ignores it.
    The best place - as I said - is not in the same file at all.  But if you insist on slapping your business logic in with your display logic, then the only consideration is that you need to set your variables before you use them.  Other than that: it simply doesn't matter.
    One consideration you might make is - even if it's all thrown into the same one file - at least separate the file itself into sections: have all your CFML code that gets your data at the top, and try to limit the CFML you have mixed in with the mark-up, eg: limit it to stuff like loops and conditionals.
    But, seriously, separate your concerns.  Dan's pretty much just wrong when he said it's over-engineering. It's just sloppy to not to write tidy, well-maintained, well-organised code.
    Adam

  • Best place to put cffunctions?

    Hi All,
    I've created a cffunction which I need to access more or less from every page. Where is the best place to put it?
    Can I put it in the Application.cfc? If yes how, and how can I call it from a page?
    Thanks!

    ianskinner wrote:
    Just realize if you are putting the function into the session scope, each and every user is getting an entire copy of the function in the server's memory.
    Depending on the purpose of the function and how you are using it, this may or may not be a lot of memory used up unnecessarily.
    If the function is something that each user does not need their very own copy then it might make more sense to put it into the application scope.  Then there would be one copy of the function that all users utilize.  You could, of course, do that in the OnApplicaitonStart() function of the Application.cfc.
    I agree with Ian that Dan's advice in this case is suboptimal.
    The only things that should go in the session scope are things that specifically related to the session.  Which is not the case here.
    Adam

  • The best place to put the global parameter

    hello:
    i am now studying the petstore1.3,and find that the global parameters are kept in the servlet context,i wonder if it is a good solution.in my project,i seldom use the servlet context,session context etc,i feel more like to put the global parameter in a singleton that is loaded when the app is started. i don't know where is the best place to put the global parameter,servlet context or singleton?

    thanks for your answer.
    1 do your mean that the singleton can be shared among the different "war"
    packages if both of them are within the same jvm?if yes,must they be in the
    same "ear" package?
    2 if my app is deployed in the weblogic cluster environment,which one can be
    shared? singleton or servlet context?

  • Best place in VOimpl java code to call a stored proc to populate results

    Hello all,
    Using JDev 11g, ADF BC and Trinidad.
    I am building an application that is primarily used for searching large amounts of data. We already have stored procedures on the database that perform the searches and dump the results into a holding table (together with a "search id"). I have easilly built a prototype of this application: my view object is simply "select a, b, c from results where search_id = :bv" - I have a service method in the AM that runs the stored procedure, obtains the search ID, binds it to the :bv in the VO and executes the VO's query - it's all working really nicely. Range paging is effective, the VO itself performs well, and I am able to control how long the stored proc runs via setting a timeout value.
    Now, I'd like to generalize this. My thinking is this:
    1). I'll add a custom property to my VO that is the SQL statement needed to call the stored procedure.
    2). I'll add some bind variables to the VO to represent all the query parameters that can be passed to the stored proc. I'll also use custom properties to indicate these are "fake" bvs, and not in the SQL query itself.
    3). The VO's SQL will remain simply "select a, b, c from results where search_id = :bv"
    4). I will (have already tested) override bindParametersForCollection so that the "fake" bind variables aren't bound into the SQL.
    Now, the question: I want to override some method in the VO's java code to call the stored procedure. The stored proc needs to be called before the actual query for the VO is run, and also before the method getQueryHitCount is called (so that the count is correct). What is the method that would be the "best" place to do this? My current thinking is that I would put the call in an over-ridden executeQueryForCollection call. As far as my analysis has gone, it seems to be always called before getQueryHitCount, but I have no way of knowing if this is completely safe.
    Any thoughts from the BC experts out there?
    Best regards,
    John

    John,
    from your description I understand that you essentially program the VO yourself. So I suggest that you read chapter 35.9 of the 'Fusion Developer’s Guide for Oracle Application Development Framework' (I guess you know where to find it). Since you still call the actual SQL not all of the chapter apply, but you get the idea how it works.
    And yes you analyzed the behavior correct. executeQueryForCollection() is allways called bevore getQueryHitCount().
    Timo

  • Where is the best place to put programs to start on X/Openbox startup?

    Hi,
    There are several places to put programs to startup when you start X or a WM.  I'm using Openbox and presently have placed these into my .xinitrc file, but I'm not sure this really the best place.  Openbox has a autostart file, which sorta looks like a better bet.
    Any suggestions would be great.
    Thanks,
    Jon

    Hadn't heard of consolekit; it's not clear to me from looking at their website what it's supposed to be offering? Maybe after it matures more, the documentation will improve, and all will become clear.
    When I used Openbox, I just launched everything such as conky from the Openbox autostart file. I guess if you had a weird set up such as some of your Openbox configs sitting on unmounted partitions, their mount commands would go in .xinitrc, otherwise autostart.sh seems better.
    Just IMO of course, do what you want on your own machine :-)
    Last edited by /dev/zero (2011-10-27 21:04:37)

  • Place to put a code for dunning level change in F150

    Hi,
    I have a requirement to block the credit management of a customer ( KNKK-CRBLB) when dunning level of a customer reaches 3 (KNB5-MAHNS or MHND-MAHNS).
    I put my code in FM 'CHANGE_DUNNING_DATA'. But this  FM is executed only for the few cases. Reasons are unknown to me. It may be because this FM is called in another FM 'PRINT_DUNNING_NOTICE'.
    I believe that dunning is completed when the dunning notice is successfully mailed, faxed or printed. Then only the customer master is updated.
    The program for F150 is SAPF150V. But neither KNB5 or MHND is updated in this program.
    I tried BTE's also. But none of the BTE's is called when a dunning notice is printed.
    I am not able find the place where i can put my code.
    Kindly help..!!!!

    Hi
    With the field that I told you in OVA8 you can achieve to lock some SO or delivery because the customer has some level in dunning (it's updated from F150 but you can change it in customer master). To know BTE's in dunning see SAP Note 156985 - Reference Note: BTE for dunning, but I have doubts that it will help you
    Regards
    Eduardo

  • 2 HD laptop setup - Best place to put Catalog, Cache, and Images??

    If I have two 500GB 7200rpm hard drives in my MBP, what is the best place for LR3, the catalog/previews, ACRcache, and the image files themselves?
    SATA3 connection for both HDs
    Should the boot drive hold the app and cache, while the second drive hold the files and catalog?
    Should the catalog and cache always stay on the same drive?
    Does it matter at all where the image (raw) files sit?
    Thanks!!

    I'd just keep the images on a different drive with a 2 internal drive setup.

  • Where is the best place to put music for itunes

    I have just downloaded Itunes
    I have a lot of music I want to add to the Itunes Program
    Where do I store the music I have in the Windows 7 there is a folder called music
    do I place all the folders into this (Music Folder)
    and then have Itunes find the music folder and add them into the program
    Is the best way to do it.
    Over time I will add more songs do I just keep placing them into the music folder and have Itunes fiund the new songs and add?
    I need your assistance
    THanks
    Mike

    iTunes will not find files, you need to add them to your library.
    launch iTunes, go preferences > advanced and verify the copy files ... when adding and keep ... organized options are checkmarked.
    next, look inside the iTunes folder for a subfolder called automatically add to iTunes. drop your music files in there. when iTunes has finished adding the files to your library, you may delete the original files.

  • Best place to put shared folders

    Switching from pc to mac. In windows you have a "shared folders" folder for all accounts and under each account a public shared folder. Where would I put the "shared folders" folder? at the HD root?

    I usually recommend the bootdrive -> Users ->Shared folder.

  • Best place to put the event listener?

    Hey there!
    I am loading several images using a loop. My question is, would it be better to put the "contentLoaderInfo.addEventListener(Event.COMPLETE..." in the loop so it loads the compelte handler each time it goes through the loop, or is it fine to put it outside of the loop at the end?
    Also, could you explain the reason for your answer?
    Thanks!

    alright. here is what I have:
              public function placePictures():void {
                   private var imageURLs:Array = ["images/1.jpg","images/2.jpg","images/3.jpg","images/4.jpg",
                                         "images/5.jpg", "images/6.jpg","images/7.jpg", "images/8.jpg",
                                         "images/9.jpg"];               
                   var ba:Array = new Array();
                   ba.push(b1,b2,b3,b4,b5,b6,b7,b8,b9);
                   for(var i:uint=0;i<ba.length;i++) {
                        trace(name + ba[i]);
                        ba[i].name = i;
                        imageLoader = new Loader();
                        imageLoader.load(new URLRequest(imageURLs.shift()));
                        //HERE...///////////////////////////////////////////////////////
                        //imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadCompleteHandler);
                        imageHolder = new Sprite();
                        imageHolder.graphics.lineStyle(5, 0x000000, 100, false, LineScaleMode.NORMAL, CapsStyle.NONE, JointStyle.MITER);
                        imageHolder.graphics.drawRect(0, 0, 180, 100);
                        imageHolder.addChild(imageLoader);
                        if (i<=2){
                             imageHolder.x = 250 + i * 300;
                             imageHolder.y = 0;
                        } else if (i<6) {
                             imageHolder.x = 250 - 900 + i * 300;
                             imageHolder.y = 200;
                        } else {
                             imageHolder.x = 250 - 1800 + i * 300;
                             imageHolder.y = 400;
                        ba[i].y = 230;
                        ba[i].x = 0;
                        ba[i].buttonMode=true;
                        ba[i].addChild(imageHolder);
                        peHolder.addChild(ba[i]);
                        ba[i].addEventListener(MouseEvent.CLICK, onButtonClick);
                   //OR HERE...//////////////////////////////////////////////////////////////
                   imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadCompleteHandler);
              public function loadCompleteHandler(e:Event) {
                   trace ("load complete handler loaded");
                   imageLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE, loadCompleteHandler);

  • The better place to put EJB Initialization code

    I have some stateless session beans that need to be initialied from a few sources
    to set
    some internal variabes. Where would be the best place to put this code.
    In the ejbCreate , in a default constructor, or in the setSessionContext method.
    Thanks.

    Thanks.
    Rob Woollen <[email protected]> wrote:
    They're all roughly equivalent.
    When the container wants to create a new slsb instance, it will call
    the
    ctor, setSessionContext, and ejbCreate in that order.
    FWIW, setting initial-beans-in-free-pool to > 0 will instruct the
    container to precreate instances if you're looking to do that as well.
    -- Rob
    Tim Bounds wrote:
    I have some stateless session beans that need to be initialied froma few sources
    to set
    some internal variabes. Where would be the best place to put thiscode.
    In the ejbCreate , in a default constructor, or in the setSessionContextmethod.
    Thanks.

Maybe you are looking for

  • ITunes account for minors ?

    Is there any way possible to create an iTunes account for minors ? I was thinking of one that will allow them to download free songs, but not make purchases. I was thinking of creating an account without a credit card information. Would this be the o

  • Word Wrap In Excel File

    Hi experts, I am trying to send an excel file as attachment . I have a column called remarks which is way too long. So  i need to Wrap the text Can any one help me out in this? CONCATENATE DUMMY BUKRS WERKS  it_inv-bstnk_vf IT_INV-ORT01 VEHNO 'SUGAR'

  • Connecting a servlet using a midlet

    Hi, I am trying to connect to a servlet using a Midlet. The servlet is running fine on Apache Tomcat and I m able to build the MIDlet using J2MEWTK . But when I execute the Midlet on an emulator it shows me some code of html page of which the importa

  • Icons not displaying in oracle forms.

    Hi All, I am trying to display icons on Oracle forms 10g.I just brought over these forms from another system and I am trying to display the icons like next record, clear form etc.. I have done the following steps so far. The icons are still not displ

  • Create a preset in lua module

    I want to experiment with applying develop adjustments from a plug-in.  noticed the photo:applyDevelopPreset( preset, plugin ) function. Question: Is there a way to create a preset on the fly within the plug-in, for example a preset for  setting the