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.
Similar Messages
-
Where to put javascript code?
Hello,
I am trying to set some columns in a list as "read-only" and is using the following code:
<script type=”text/javascript”>
function SetReadOnly()
var elements=document.getElementById(’4_ctl00_ctl00_TextField’);
elements.readOnly=true;
_spBodyOnLoadFunctionNames.push(“SetReadOnly()”);
</script>
But I am not sure where to put the code in. Should I put it in the space in Content Editor Web Part,
or through a link to a txt file, or in "Edit HTML"? I've tried them but none works.
Thanks a lot!
PatrickYou can try this:
1) Open your Sharepoint List. Go to List edit view.
2) On right side of Ribbon you will find "Form Web Parts" option as shown in figure.
3) Choose your List form which you want to edit.
4) Now you can add web part in new window.
5) Add Content Editor Web part.
6) In content editor web part add the path of your "txt" file in which you have written your script, for eg.
<!DOCTYPE html>
<html>
<body>
<script type=”text/javascript”>
function SetReadOnly()
var elements=document.getElementById('4_ctl00_ctl00_TextField');
elements.readOnly=true;
_spBodyOnLoadFunctionNames.push("SetReadOnly()");
</script>
</body>
</html>
I haven't tried this method so I am not sure but hope it works...:D
***If my post is answer for your query please mark as answer***
***If my answer is helpful please vote*** -
Where to put java code - Best Practice
Hello. I am working with the Jdeveloper 11.2.2. I am trying to figure out the best practice for where to put code. After reviewing http://docs.oracle.com/cd/E26098_01/web.1112/e16182.pdf it seemed like the application module was the preferred spot (although many of the examples in the pdf are in main methods). After coding a while though, I noticed that there were quite a few libraries imported, and wondered whether this would impact performance.
I reviewed postings on the forum, especially Re: Access service method (client interface) programmatically . This link mentions accessing code from a backing bean -- and the gist of the recommendations seems to be to use the data control to drag it to the JSF, or use the bindings to access code.
My interest lies in where to put java code in the first place; In the View Object, Entity Object, and Am object, backing bean.....other?
I can outline several best guesses about where to put code and the pros and cons:
1. In the application module
Pros: Centralized location for code makes development and support more simple as there are not multiple access points. Much like a data control centralizes services, the application module can act as a conduit for different pieces of code you have in objects in your model.
Cons: Everything in one place means the application module becomes bloated. I am not sure how memory works in java -- if the app module has tons of different libraries are they all called when even a simple query re-execute method is called? Memory hog?
2. Write code in the objects it affects. If you are writing code that accesses a view object, write it in a view object. Then make it visible to the client.
pros: The code is accessed via fewer conduits (for example, I would expect that if you call the application module from a JSF backing bean, then the application module calls the view object, you have three different pieces of code --
conts: The code gets spread out, harder to locate etc.
I would greatly appreciate your thoughts on the matter.
Regards,
Stuart
Edited by: Stuart Fleming on May 20, 2012 5:25 AM
Edited by: Stuart Fleming on May 20, 2012 5:27 AMFirst point here is when you say "where to put the java code" and you're referring to ADF BC, the point is you put "business logic java code" in the ADF Business Components. It's fine of course to have Java code in the ViewController layer that deals with the UI layer. Just don't put business logic in the UI layer, and don't put UI logic in the model layer. In your 2 examples you seem to be considering the ADF BC layer only, so I'll assume you mean business logic java code only.
Meanwhile I'm not keen on the term best practice as people follow best practices without thinking, typically best practices come with conditions and people forget to apply them. Luckily you're not doing that here as you've thought through the pros and cons of each (nice work).
Anyway, back on topic and off my soap box, as for where to put your code, my thoughts:
1) If you only have 1 or 2 methods put it in the AppModuleImpl
2) If you have hundreds of methods, or there's a chance #1 above will morph into #2, split the code up between the AppModuleImpl, ViewImpl and ViewRowImpls. Why? Because your AM will become overloaded with hundreds of methods making it unreadable. Instead put the code where it should logically go. Methods that work on a specific VO row go into the associated ViewRowImpl, methods that work across rows in a VO go into the ViewImpl, and methods that work across VOs in the associated AppModuleImpl.
To be honest which you ever option you choose, one thing I do recommend as a best practice is be consistent and document the standard so your other programmers know.
Btw there isn't an issue about loading lots of libraries/imports into a class, it has no runtime cost. However if your methods require lots of class variables, then yes this will have a memory cost.
On a side note if you're interested in more ideas around how to build ADF apps correctly think about joining the "ADF EMG", a free online forum which discusses ADF architecture, best practices (cough), deployment architectures and more.
Regards,
CM. -
Architecture question...where to put the code
Newbie here, so please be gentle and explicit (no detail is
too much to give or insulting to me).
I'm hoping one of you architecture/design gurus can help me
with this. I am trying to use good principals of design and not
have code scattered all over the place and also use OO as much as
possible. Therefore I would appreciate very much some advice on
best practices/good design for the following situation.
On my main timeline I have a frame where I instantiate all my
objects. These objects refer to movieClips and textFields etc. that
are on a content frame on that timeline. I have all the
instantiation code in a function called initialize() which I call
from the content frame. All this works just fine. One of the
objects on the content frame is a movieClip which I allow the user
to go forward and backward in using some navigation controls.
Again, the object that manages all that is instantiated on the main
timeline in the initialize() function and works fine too. So here's
my question. I would like to add some interactive objects on some
of the frames of the movieClip I allow the user to navigate forward
and backward in (lets call it NavClip) . For example on frame 1 I
might have a button, on frame 2 and 3 nothing, on frame 4 maybe a
clip I allow the user to drag around etc. So I thought I would add
a layer to NavClip where I will have key frames and put the various
interactive assets on the appropriate key frames. So now I don't
know where to put the code that instantiates these objects (i.e.
the objects that know how to deal with the events and such for each
of these interactive assets). I tried putting the code on my main
timeline, but realized that I can't address the interactive assets
until the NavClip is on the frame that holds the particular asset.
I'm trying not to sprinkle code all over the place, so what do I
do? I thought I might be able to address the assets by just
providing a name for the asset and not a reference to the asset
itself, and then address the asset that way (i.e.
NavClip["interactive_mc"] instead of NavClip.interactive_mc), but
then I thought that's not good since I think there is no type
checking when you use the NavClip["interactive_mc"] form.
I hope I'm not being too dim a bulb on this and have missed
something really obvious. Thanks in advance to anyone who can help
me use a best practice.1. First of all, the code should be:
var myDraggable:Draggable=new Draggable(myClip_mc);
myDraggable.initDrag();
Where initDrag() is defined in the Draggable class. When you
start coding functions on the timeline... that's asking for
problems.
>>Do I wind up with another object each time this
function is called
Well, no, but. That would totally depend on the code in the
(Draggable) class. Let's say you would have a private static var
counter (private static, so a class property instead of an instance
property) and you would increment that counter using a
setInterval(). The second time you enter the frame and create a new
Draggable object... the counter starts at the last value of the
'old' object. So, you don't get another object with your function
literal but you still end up with a faulty program. And the same
goes for listener objects that are not removed, tweens that are
running and so on.
The destroy() method in a custom class (=object, I can't
stress that enough...) needs to do the cleanup, removing anything
you don't need anymore.
2. if myDraggable != undefined
You shouldn't be using that, period. If you don't need the
asset anymore, delete it using the destroy() method. Again, if you
want to make sure only one instance of a custom object is alive,
use the Singleton design pattern. To elaborate on inheritance:
define the Draggable class (class Draggable extends MovieClip) and
connect it to the myClip_mc using the linkage identifier in the
library). In the Draggable class you can define a function unOnLoad
(an event fired when myClip_mc is removed using
myClip_mc.removeMovieClip()...) and do the cleanup there.
3. A destroy() method performs a cleanup of any assets we
don't need anymore to make sure we don't end up with all kinds of
stuff hanging around in the memory. When you extend the MovieClip
Class you can (additionally) use the onUnLoad event. And with the
code you posted, no it wouldn't delete the myClip_mc unless you
program it to do so. -
Any event in lov where I put my code
hi master
Sir
Any event in lov where I put my code
Such as after selection value my curser move to next text box and total all bill amount
For example
When press enter
Begin;
Select sum(billamount) into :billamount from billtable where clientno=:lov.values;
End;
Please give me idea
Thanking you
AamirKEY-LISTVAL trigger:
if Show_LOV(<yuo_lov_name>)
then
Select sum(billamount) into :billamount from billtable
where clientno=:<CONTROL.values>;
end if;
<CONTROL.values> is a LOV returning item(s) -
Urgent where i put this code for delete
hi master
sir this code is right for my requirment but when i put on_delete event system not respons or not delete record
where i put this code for conditional deletion
this is my code
declare
recno number;
begin
if :system.cursor_block='accbal' then
delete accbal where accid=:chartofacc.accid;
go_block('chartofacc');
next_record;
elsif :system.cursor_block='chartofacc' then
select count(*) into recno from accbal where accid=:chartofacc.accid;
if recno=0 then
delete_record;
go_block('chartofacc');
previous_record;
else
message ('system found matching record then no delete master record');
message ('system found matching record then no delete master record');
end if;
end if;
end;
please gide me which event i use
thanking you
aamirHello,
The ON-DELETE triger fires only after a COMMIT statment and only for those records that have been deleted in the block.
Francois -
Where to put validation logic...
Hi,
We have a lot of validation logic in our database. Next to the normal foreign key, check, unique constraints, we use triggers for validation (which throw errors with custom error codes when needed).
On top of the database we are building a fairly large JClient based application using the BC4J framework. BC4J offers the possibility to use validation beans for validating the entity row. We are wondering if we should use this. If we implement the validation logic for each entity we are actually duplicating the validation logic that's already available in the database. And some database constraints are easily implemented using the standard validation beans (like not null and unique checks), but more complex validation rules can sometimes only be done in the database (so we need to use the database for validation using a method validation bean).
Like I said this means a lot of duplicating validation logic. Which first of all is an inefficient thing to do. Second validation logic can change over time, which means we need to change the logic on two places. It's easy to forget to change the logic on one place.
We found a way to somewhat use the database validation logic for validating entity rows. We just simple insert a row in the database and post the changes. If the new row contains an error an exception is thrown. This JBO exception contains a reference to the SQL exception. Which can be used to retrieve the database error code. Unfortunately we have not found a good way (yet) to find out where the error occured (in which trigger for example). Error codes don't have to be unique so it's important to know in which context they occured. Another problem with this method is we can't do an early validate on a limitted set of row data. E.g. we sometimes use wizards in our application for adding new rows. We really want to check the data after each step in the wizard (step by step). This is ofcourse impossible with the database logic. This means we again need to create the same validation logic again. I don't think it's even possible to use the row.validate() method for this (and ofcourse implement the validation logic in the entity too), because this method validates the complete row.
In short, where is the best way to put validation logic? And (how) can this be done without duplicating (to much) logic?
Regards,
Peter
P.S.
Does anyone know how to retrieve the context of an SQL exception?Do you users have access to the data/tables outside
of using your application? (as in using sqlplus?)Not at the moment.
Ideally the database should just be going
constraint--data integrity type of checks. The
business rules would be in the business layer not
persitance layer..So in this case, they would be in
the bc4j entity objects.. Well most of them are simple integrity constraints, but sometimes we have to check things using triggers which are way more complicated and need extensive database access. It's more logical to do that in the database. If the trigger runs into a problem it raises an application error. We are hoping we can use this error somehow in our application.
That assumes that the only way a user can modify that
data is through your application only.Well it is, and if another application is written for it the BC4J entities etc. will probably be re-used, but like I said there are other reasons for not having all the business-rules in the BC4J layer.
by the way, are you migrating an existing application
that already has all the business rules in the
database?No, it's a brand new application, but we started out with defining a lot of business rules in the database because that seems a more logical place to put them (to us). I understand that some business-rules can better be implemented in the BC4J entities, but it's not that easy for every business rule we have.
Regards,
Peter -
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?
thxThe 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 -
Where to put the code for dynamically change dataprovider
I have a table bound to dataprovider1 by default ( by the SJC ). In the same page, I also have a dataprovider2 which is for the same fields of the same table of dataprovider1. The only different is to put some criteria on one field ( like F_D1 = '5' ) so that one provider will show all rows, the other just some rows.
The code to change the dataprovider is as follows :
tableRowGroupWorksheet.setValueBinding("sourceData", getApplication().createValueBinding("#{WorksheetPage.dataprovider2}") );
If I put this code into some button_action() and then I click that button, then the page displays the corresponding data just fine.
But if I put this code in either preprocess or prerender, then things seems messed up : the number of pages is for data of dataprovider1, but when I click button Next of the table then it shows the number of pages of dataprovider2. ( I also try to put it in init but this does not help either ).
I need this code to be run when this page is selected but right now it requires me to click on a button :(
The reason I need it runs automatically is because of the logic generated from the previous page.
Thanks for your advive,
VuAfter re-reading the life-cycles of JSF and the injected phases of SJC, I think I know why it does not work when the page is first called. In this case, AplyRequestValue phase is skipped therefore preprocess is never called. Also in this case, the component tree, with binding, validators, ... is only built in the Render Response phase and this phase is right after PreRender is called therefore the binding code I put in prerender is overwritten by Render Response.
When using a button action, the component tree is already built and not rebuit under Render Response, therefore that code is not overwritten. Also in this case, preprocess is called so putting that code under either preprocess or prerender will work.
Please correct me.
Thanks,
Vu -
Hi All
I'm using anchors in flash, and they work fine. I can add an anchor to a URL and it'll jump to the right frame in a flash document, no problem.
Apparently (according to Ned), the problem is that other functions stop working if I've put the code on frame1 for example but jump to frame5 with an anchor.
I thought that a function on frame1 would be accessible anywhere on the timeline. Is this correct? If not, how do I make a global type function?
Thanks for any ideasIf you've got an extra keyframe, simply remove it using Shift + F5.
Having said that though, when I try to click on a link to the same swf
file but with a different anchor, the link doesn't work unless I
navigate away to another swf file and then come back. It seems as though
it thinks it's already at the right place or just ignores the link.
Yes, that's another subject.
You need to explain in details, what you're doing and how you've
done it. Show some of your code or a link to the swf file.
Start a new thread for this..
Your primary answer has been answered here.
Best regards
Peter -
Title, meta tags for seo, where to put in code..?
Hi guys
Im trying to optimise my first ever site and Im doing it in dreamweaver. Ive figured out the title and meta tags are html and was just wondering whereabouts in my html code should I put them...?
Are they before the body tag..? Are they before my first div tag in the code..?
Are they in a specific div tag, e.g header div=title tag, meta tag = main content div....?
Any help would be great
Cheers :-)I wasnt recommending he use meta-keywords, I was just answering his question. However, my employer has a huge static site with thousands of products and he is always listed in the top 5, if not number one in google searches. His site is all text with one image on each product page with an alt tag. He doesnt have ANY back links whatsoever, but uses page text content, meta-keywords, and meta-descriptions extensively. He doesnt even use heading tags. His site layout is with tables, and he uses deprecated html such as <font> and <center> tags on every page. Of course we have discussed the problems his site is going to encounter eventually with regards to his layout and use of the deprecated tags.
I'm not saying search engines use meta-keywords, but I have to say what ever he's done has worked very well.
My point is, I read and read about what search engines use and dont use to rank and index pages, yet I see contradictions everyday to both sides. -
Where to put init code for static variables? (for UIImages)
I know that static variables are sorta a global, is that how UIImage is usually stored? What is the convention to declare UIImage variables that exists throughout the lifetime of the app? Where is a good place to init it if I choose to use static variables?
OK, in that case do something like this:
MyClass.m
#import "MyClass.h"
static UIImage *classImage;
@implementation MyClass {
+ (void)initialize {
classImage = <whatever to load image>;
Code like the above makes the 'classImage' variable work like a typical class variable. It is available to all instances of MyClass but is not visible to other classes. Like a 'private static' class variable in Java. Nothing goes in the header for this variable.
The 'initialize' method is called once the first time anything ever references MyClass. Kind of like a static initializer in Java. Notice the use of '+' instead of '-' for the method. The '+' makes it a class method instead of an instance method.
Does that help?
Message was edited by: RickMaddy -
Where to put my customized formatting that Control Hints does not provide?
To whom that know or have experience with it:
The control hints does not provide solutions for all possible formatting needs. For example, I need to display only last four digits of social security numbers (i.e., for "123-45-6789", display "***-**-6789"). Another data table column stores school semesters as YYYYMM, e.g., 200902, where 2009 is the year and 02 is the month that represents Spring (MM can also be 06 and 09 that represent Summer and Fall). I need to display the semester in a more user-friendly way (i.e., for "200902", display "Spring 2009"). Of course, I can not change data format in the table; I only seek to format the display of the data.
I would think that it takes only a few lines of java code to do these formatting by splitting the string into sub-strings, replace some of them with appropriate new values, then re-assemble them. But where to put such code? Does any documentation cover this topic?
NewmanShay,
I read the document, tried it, and it worked out nicely.
There is not the getAttributeName() method in the ViewObjectImpl class in version 10.1.3.4, which is the version I am using. But the EO class has it and it works out all the same.
I don't know how long it would otherwise take me to read and fumble to find out where to put the custom formatting code. Your experience and familiarity with the technology really saved me a huge amount of time. Thank you so much for your help!
Newman -
Where should I put my code?
Where should I put my code, on the buttons and other items in question, or in a separate Layer, referencing the items I need...?
Background :
I'm REALLY new to Flash with Adobe. I've used SwishMax a little in the past, but nothing of recent.
At work there's a project where I'm getting to use FlashPro CS6 and I've run into an odd issue with code to move forwards, backwards, and back to the beggining on 3 different buttons.
It's in a layer called Actions, and on frame 1 - And remember... uber newbie here folks, so forgive any glaring issues in my code that most people would see quickly...
//NEXT BUTTON
NEXT_BUT.addEventListener(MouseEvent.MOUSE_DOWN, nb_mouseDownHandler);
function nb_mouseDownHandler(event:MouseEvent):void
this.nextFrame();
//MAIN MENU BUTTON
MAINMEN.addEventListener(MouseEvent.MOUSE_DOWN, mm_mouseDownHandler);
function mm_mouseDownHandler(event:MouseEvent):void
gotoAndStop(1, "Scene 1");
//BACK BUTTON
BACK_BUT.addEventListener(MouseEvent.MOUSE_DOWN, bb_mouseDownHandler);
function bb_mouseDownHandler(event:MouseEvent):void
this.prevFrame();
The code for the first two work's exactly as I need, the code for the back button, initially it only appeared on from the second frame onwards, but during debugging I've popped it on all pages. On the first frame, it takes you back to a black page with nothing on it, on all others it does absolutely nothing...
Another question as I've written above, should my code be in a separate layer regerencing the items it needs to affect, or... as a colleague told me in a ridiculously over the top brimming with distaste, create layers for each item, or groups of items and place the code in there... which to me, see's odd...
Thanks once again in advance, and I'm sorry to post such a newbie question, but the internet gives mixed anwers, not specific to my situation.
Tim.In AS3 you cannot put code on buttons and other items like you could with AS1 and AS2. Beyond that, your choices are to place code in the timeline frame(s) or in separate actionscript files. While there are a number of recommended best practices, what usually works best is whatever you are able to understand and work with at the time. While there are benefits to having all code located in one place (a frame or a file) since it makes finding it much easier, when you are creating a timeline-based design, that is not always a possible/practical approach.
Over time you will gain experience with the different approaches and can make the choice based on that experience. -
Where do we put Validations in Internet Sales Application
Where do we put validation on user input data in ISA.
like in Actions,BO,BE.Please tell where exactly we do it.
I need to compare Sold to Party with Ship to Party and Bill to Party.Any idea how i can do it.There was some problem from crm side....It working now
Maybe you are looking for
-
Web Analysis Error -- Error while executing query and retrieving data
Regarding Web Analysis: We have a number of reports that we created. yesterday they were all working fine. today we try to open them and most are generating an error. The error is: Error while executing query and retrieving data.; nested exception is
-
SUM function in select statement
Hi I have table like this empno,ndahrs,swipedate 101,00:01,01-apr-2013 101,01:03,02-apr-2013 102,02:00,01-apr-2013 102,03:00,03-apr-2013 104,01:00,04-apr-2013 104,00:30,03-apr-2013 now I want SELECT EMPNO,NDAHRS,SWIPEDATE,SUM(NDAHRS) FROM TABLE; how
-
Database performance is poor after upgrading to 9i
hi Guys My system was upgraded to 9i by the third party after that I took over from that and I am getting the continuous complaints regarding performance of Database. there are 150 Users who connects using citrix , from different locations and DB siz
-
Prb 1 > Whenver we are creating the Subtype then it is Compalsoury that to Copy the Standard Bus to Customised Bus ( i.e Z Bus ) and then Creating Subtype ? Or We can Directly Create Subtype for Standard Bus . Please Provide
-
JRE picking up wrong path to dll's
Hi, I've got multiple JRE/JDKs installed on my machine currently - e.g: 1.6.16 1.6.17 1.5.14 - JAVA_HOME points to 1.5.14 - PATH points to the same - If I do a java -version from the command line, I get "1.5.14" However, if I go to the bin director o