Where do I write business Logic?

Hi,
Where do I write bisiness Logic?
Tutorial said "It is common practice to include the bean property and the Action
implementation to which it refers within the same bean class".
But I thought EventHander Impl is better to write business Logic
like retrieving the data from database.
Which is common use?
Or I need to choose them depending on the situation?
Thanks in advance for you help.
tomo

Thanks for the reply!!
But I am still confused.
I thought I can write business logic A and B.
What is difference between A and B ??
Hi tomo,
In the two options you provide the difference is not that much. The ActionListener instance willhave to be registered in your JSP of course to listen to the button or hyperlink with the f:action_listner tag. But in both cases your biz logic is in your ui. I think that is the wrong direction for you to head.
I think the real question should be (forgive me if I'm pulling the discussion away from your question, but I think this is relevant) where does the business logic go.
As Kito said your biz logic belongs apart from your UI logic (classic MVC approach). So in the real world what does that mean? As you suggest in option B in your last post a bean provides an action so that it can be specified via the actionRef attribute. This action in turn invokes a method on the bean it comes from which then invokes the business logic on the 'real' business logic.
The Action becomes simply a translator (or part of the Adaptor pattern from the GoF book).
For example lets say you have a bean that does biz processing like this;
public interface CatalogFacade {
  public Collection getProducts(ProductSearchCriteria criteria);
}And you want to invoke that 'business logic' from your JSF UI. The button would be declared with this code
<h:comman_button id="searchCommand" type="submit"
                    label="Search"
                    commandName="search"
                    actionRef="searchBean.searchAction"/>In your searchBean you have many options to return the searchAction but I prefer the following
public class SearchBean {
   public SearchFacade searchFacade = null; // this could be a managed bean or an EJBSession or whatnot
   public ProductSearchCriteria productSearchCriteria = null; // this should be 'filled' in by the form the button is on
   private transient Action searchAction = new Action() {
    public String invoke() {
      return search();
  public Action getSearchAction() {
    return searchAction;
  public void search() {
    Collection products = searchFacade.search(productSearchCriteria);
    // place the products collection into the next page's bean so that is can be found via valueRef attributes
}Notice that no database hits are happening in the UI code. Also there is no business logic here either.
It is very important to keep these two concerns divided for ease of maintenance. The typical reasoning goes something like this, 'your ui is very likely to change so keep it separate from your business logic'. Other reasons to be careful about mixing UI and biz logic is the likely hood that you will get very different behavior (one probably wrong) if you have to and another client to your biz logic.
For example in the earlier product search stuff. If we needed a web service front end to the 'searchProducts' functionality and we had the db hit happening in the action or page bean we would be stuck. With the above impl we get to just put a WS over the facade and we are done.
Hope this helps.
You can also look at some of the blueprint patterns for more info. They start here;
http://java.sun.com/blueprints/patterns/index.html
While some of the EJB specific patterns might be more involved than you need they provide excelent archtectural guidence for web only apps as well.
Good luck,
-bd-

Similar Messages

  • Where to implement my Business Logic in ADF?

    Hi,
    I am new to Oracle ADF. I found this forum very useful to get my queries and doubts answered. Thanks to the participants.
    I am basically from Struts background,
    Where i design my UI in jsp pages using Struts tags,
    Actions and some utility classes handles my most of the business logic (generally called as Business Layer)
    Then i have custom DAOs or Data Layer to query or update the data in database.
    Now as I am into new Project and I have to learn Oracle ADF.
    I started learning this by following some questions in the forums and various sites (from Google).
    I got info on How to create Entity Objects, Value objects etc.
    But my major doubt is where shall i write my Business Logic in this stack?
    I can easily drag and drop my data controls into my JSF page and create table, forms or charts. But if i have a multi line business logic, say for a Submit button, In which i may be doing the following steps -
    a.  Get data pertaining to user role , department, his tenure in the department etc
    b. On submit do processing based on data collected in above step.
    c. update data in data base.
    d. initiate an approval process
    e. call some business process for Approval
    f. Audit Trail
    g. Transaction handling
    and so many other steps (I know most of you will have gone through these situation before starting work on ADF)
    Now, in the above scenario in Oracle ADF layers where shall i write this whole bunch of logic or steps and then forward the user the page depending upon the outcome of this logic.
    Please let me know where to write all this??
    Thanks a lot,
    Amit
    Edited by: ur.amit on May 13, 2010 4:58 PM

    Generally speaking all of that code would reside in the app module Impl classes or the View object Impl classes - for VOs and AMs you can expose subclasses and add code in there - you can then define whether any of your methods should be exposed to the client, in which case they appear in the Data Controls panel as operations.
    General word of advice -keep business logic code in the Model - don't be tempted to start trying to access your AMs and do any of this stuff from the ViewController project. Keep it nice and simple and just access ALL the business logic code through ADF Model.
    Hope this helps
    Grant

  • Where I put my business logic?

    For example i create a simple JSP page with his DataAction. The JSP page contains a simple Input Form created with drag and drop from the Data Control Palette. The Submit button is also on the JSP page, now I want to insert the commit option without showing this to the user, like in 9.0.3 app.getTransaction().commit(); ...where I insert my source? Also if I want to insert source bevor i launch the JSP page, always using DataAction (without using BasicADFAction from Steve Muench), where can I do this? The execute method in DataAction is final!

    One way to acheive auto commit is with Data Action chaining.
    For ex:- You could have pageflow like:
    createEmpDA ---> /createEmp.jsp
    createEmpDA DataAction would create an empty row.
    and forward to createEmp.jsp which will show an input form with a submit button.
    Now wire the submit button as follows.
    createEmpDA ---> /createEmp.jsp ---> commitEmpDA
    Change the submit action in createEmp.jsp to commitEmpDA.
    In StrutsPageFlow.
    Drag-n-drop commit operation from DataControl palette onto commitEmpDA DataAction.
    This would commit the transaction.
    Page flow could end up to browseEmp JSP page which shows all the employees including the newly created one.
    createEmpDA ---> /createEmp.jsp ---> commitEmpDA --> browseEmpDA ---> /browseEmp.jsp
    raghu
    JDev Team

  • Can Write Full business logic in web Dynpro ?

    Hi All
           We are developing many Iviews with WebDynpro and
           same time where we need to write the pure business logic ?
           Can we write in Web Dynpro ? Any issues on this ?
    Any one can help me on this pl
    regards
    rakesh

    At a purely technical level, then you can of course write business login in Web Dynpro - after all, it is still just Java (or ABAP). The real question here is whether that is a good idea.
    I think that Web Dynpro works best as a presentation and application-flow framework - actual business logic is best implemented in another layer. This can be done in EJBs in Java, but in most SAP landscapes my experience is that the business logic layer is best implemented in ABAP, since the ABAP back-end is most naturally the place where all business logic exists. Of course, if you only have Java developers and you are using Java Web Dynpro, then an EJB-based business logic layer may be more comfortable to implement.
    Hope this helps,
    Darren
    <a href="http://www.fortybeans.com/">blog</a>

  • Where is the best place to implement business logic in ADF application?

    I am using jdeveloper 11g R2 , JSF Facelet
    Where is the best place to implement business logic in ADF application?
    I mean something like service layer in Spring
    Appreciate your comments
    Regards
    Mohsen

    Depends on what your logic does and what data it deals with, but in general business logic is in the ADF BC layer.
    Some goes into entity objects - for things like attribute or row validation.
    Some goes into view objects - for things like calculation.
    Some goes into AM - for things like service methods for UI clients.

  • ADF11g: business logic in ADF BC or PLSQL?

    Hi All,
    For a new development in ADF 11g , where we should put our business logic: In ADF BC or in PLSQL?
    What if we write all the bussiness logic in plsql? Because if tomorrow ADF goes(which I know is not ging to happen soon), we can expose pl/sql as web services, and new UI technology can use it. And we will not struggle on migration, as we are struggling today from Forms to ADF.That's what my manager says......
    Though I know that we can write our business logic in ADF BC, and that too can be exposed as web service.
    But I still need more suggestion on this, which one is better to write bussiness logic.
    Thanks
    Vikram

    We have a team with mixed skill sets, so consequently some of our business logic is in ADF/BC and some is in PL/SQL.
    Having some in PL/SQL allows my project manager to divide and conquer the work to be done on an adf project easier than I can train the pl/sql guy to be an adf guy...supposedly.
    Also our project manager is also a techy with a primarily pl/sql orientation.
    I like Java better because it is new and fun for me, but that is not much of a reason.
    I have been to many presentation's of Paul Dorsey's BRIM product. Paul is absolutely certain that you and your manager are doing good when you put business logic in the database. Paul goes even further. I respect him and his arguments are sound.
    I still like Java better...mostly because I have done pl/sql for ages and am tired of it. :-)

  • Segregating business Logic from JSP files.

    I have an application with around 150 jsp files, out of which almost half of them are containing business logic.
    I am actually in a process of segregating the java code from the jsp files.
    Could you please guide me in finding out the best practices, dos and don'ts while engaging in such a process.
    Thanks in Advance

    I've been through this hellish experience. I’m not sure any “best practices” for this exist.
    gimbal2 idea of starting a new project would be ideal, if costly. The other extreme is “it works”, don’t touch ‘em until you need to change the functionality then work out the cost/befit of a rewrite for that slice.
    If you really want to take this route:
    How bad is the code that does not live in the JSPs? Should it be reused or avoided?
    What level of functional test coverage do you have?
    The approach my team and I took was to cut it down into slices and try to rewrite that slice as cleanly as possible. Where interactions between slices exist try to write a facade which calls the legacy code but looks like how you would want the new code to look.
    This did not work perfectly. The facades were rarely used well and we had to drop major slices of work to complete on time leaving us with large chunks of legacy code that we can’t delete.
    We started with no automated functional tests, but a goal of getting to a decent amount. We failed on this, which caused major issues - mop up lasted a month and a half after release. Drop functional slices to ensure that you end up with a solid set of automated tests. If you can not get your team to buy into this don't bother with the project.

  • Real app business logic, access serialization

    Hi,
    in our real application we have some business logic.
    The bc4j examples show for example how to limit the value
    of a colum between two values.
    But our business logic is not limited to a so
    simple case.
    For us is very common that business logic involves
    more (aggregate) tables.
    For example consider a invoice and
    the line of the invoice. These are two tables but
    a business rule say that the sum of the line should
    be the total column of the invoice. Moreover the
    total of the invoice can't be zero. The need the
    existence of the total column in invoice is required
    because speed up queries and for the constraints and
    we can't make it only a display value of a
    query.
    To avoid data corruption we have noted that access
    should serialized for a invoice. Otherwise two user
    can change the lines and the total can be correct in the
    session but may not be correct at the end of the
    two commit.
    How can we obtain this in bc4j? Where should we place
    the code? How to make access of the invoice serialized?
    There is some documentation or code example of this?
    Very thanks in advance!

    By marking the lines entity to be composed with the invoice entity, and marking the "lock top-level entity" you can automatically achieve the serialization you're looking for using BC4J.
    If anything in the invoice, or any composed children are modified, it will lock the top-level parent (invoice) before allowing the edit to proceed.
    To express a rule that asserts a rule about the sum of the detail lines, write a entity-level validation rule in the invoice (parent) entity which uses the association accessor to iterate the lines and calculate the sum.

  • Can we use WHO columns in Business Logic implementation

    Hi,
    Can we use WHO columns for business logic implementation..?
    From one table I need to pick up the latest record. I have a ActionDate column in the table which stores the date of the action.
    But on the same day there can be multiple action records. ie Multiple records have same ActionDate.
    Select * from action_table where action_date=(maximum action_date)
    The above query will return more than 1 record.
    Now can I use the Creation_Date which is a WHO column to identify the latest record..?
    Will it introduce any issues if I use creation_date WHO column?
    Usage of WHO column in application logic, Is it against the Standards ?
    Thanks a lot.

    I guess you are talking about populating the value using the history column creation_dt from EO.
    If so, you can use then. We are using them in all our applications to populate WHO columns of our table.
    Infact as far as I know, even Oracle application uses them.
    They generally populate the timestamp, so you may need to format them when doing date comparisons.
    Hope that helps.
    Amit

  • Where to define third party logical system name in file to idoc scenario

    Hi Friends,
      I am shalini shah.
    I have one doubt, where I can define the logical system name in File to Idoc scenario.
    I created Logical system for R/3 system in SALE t.code, but where to define the Third party logical system ,
    In SALE or any where.
    Please give me solution.
    Warm Regards,
    Shalini Shah

    Hi Shalini,
    You need to create Business system in SLD and import the business system in ID.Then u will start with the configuration.
    Just refer the below link for configurations with step by step solution.
    File To IDOC - Part1 (SLD and Design):
    https://www.sdn.sap.com/irj/sdn/wiki?path=/display/profile/2007/05/11/fileToIDOC&
    File To IDOC - Part2 (Configuration):
    https://www.sdn.sap.com/irj/sdn/wiki?path=/display/profile/2007/05/11/fileToIDOC-Part2+(Configuration)&
    File To IDOC - Part3 (Steps required in XI and R3):
    https://www.sdn.sap.com/irj/sdn/wiki?path=/display/profile/2007/05/11/fileToIDOC-Part3(StepsrequiredinXIandR3)&
    Thnx
    Chirag

  • SRM Smartform - How to write custom logic to get data

    Hi Experts,
    I am new to SRM 7.0 now. I want to know where the code logic can be written to print the custom smart form?
    I have already create custom smarts form ZBBP_PO, and implement the BADI  BBP_OUTPUT_CHANGE_SF to pass the custom form name.
    But i don't know where to write the code for fetching the source data. In ECC, we can write the code in a separate report program. How it does in SRM now? It is said some class and method will print the form. How to find it? and how to add custom logic.?
    Or the logic of fetching source data should be embeded in the smart form? I don't like to write much more codes directly in smart form.
    Thanks!

    Yeah, I know it. but I don't want to write code logic into the Smartforms. in ECC, i always write the code in a separated program which will pass the data to smartform and call function module to print it.
    i just want to know whether i can write the code in somewhere else in SRM, not in smartform.

  • BPEL Process with complex Business logic

    Hi,
    So far my knowledge,complex business logic can be implemented by different way in bpel process.
    1. Business rule
    2. ejb with java callout
    3.ADF BC as servcie
    Can anybody please suggest which approach do I need to follow,what are the pros and cons of each one,and best practices to use when and where?
    Thanx in advance.-Aswini

    Hi
    In addition to what Naresh already mentioned, you can consider these points also.
    1. If your process is complex, see if some part of the process can be common across and it can run by itself. Then you can use SubProcess concepts also. Say for example, if process involves credit card processing, it can be in a sub-process and you can call it in the main process. Like that any common approval flows can be put in a separate sub-process.
    2. I would discourage using Java invocations if possible as they have some limitations and you can use reasonable amout of code in invoking java code within the bpel process. If you have lots of validations to do on a bpel process, you can consider using CallBackHandlers and do the validation on a task assignment, submission or any task action in general.
    3. Business Rules can be used to control the actual flow of the process itself. Based on busiiness rule, you can decide if a set of tasks needs to be included or not in the approval flow. This is in addtion to the actual data that controls the business rules, that can be changed dynamically without the code change to core bpel process.
    Which version of SOA are you using or plan to use. I would recommend the latest version SOA 11.5 + Feature Pack applied.

  • Push messages from business logic into backing bean

    In my simple web application a table with the contents of a database table is shown to the client. Now I want this table in the browser to be updated each time the db table is updated. In my business logic a jms message is fired to a specified topic each time the db table is updated. The reverse ajax stuff needed for the client update is provided by the Icefaces jsf implementation. There is a backing bean for each session which is responsible for the server side rerendering of the client. Now my question is: How do I connect the bussiness logic firing a jms message if the db table is updated, with the backing bean?
    My thoughts:
    1. Create a message listener for the topic. Each time the message listener receives a message it notifies the backing beans of each session to rerender the client. But how does the message listener know about the backing beans?
    2. The backing bean responsible for rerendering the client adds itself as a listener. But where? As I understand it cannot be a backing bean and a jms MessageListener at the same time.
    Has anyone an idea/pattern for this problem?

    You could keep a list of beans that need to be notified in the application scope. (You should probably use weak references so that they may be garbage collected.) Then you JMS listener could get access to them.
    Somebody posted a thread recently where they were doing something very similar, you might want to try to find it.

  • What can be considered as the business logic of simple data entry form

    Hi all,
    I want to separate my applications logic into layers. It is a simple data entry form and doesn't contain any complex business logic. So I want to get this simple business logic to different layer. But the problem is, I cannot clearly identify what are business logic of this kind of simple data entry form.
    How do I separate business logic of this simple data entry form to another layer?
    any help is appreciated,
    Thanks in advance,
    Dil.

    dcminter wrote:
    It is a [form] and doesn't contain any complex business logic. So I want to get this simple business logic to different layer. But the problem is, I cannot clearly identify what are business logic of this kind of [form].Are you asking which bits are business logic?
    Suppose that the data comes into your system immaculate from some external system. Imagine that it will go out into some other system. The bits that you would still have to write are your business logic.That's a nice practical definition. Thank you, I'm stealing it.
    Also interesting to note that validation falls into that category... say you're recieving data from a magical external source... you still have to validate it.
    And of course you'd still have to store it somewhere, ans retrieve it.
    Yep, I definately like that definition.
    Cheers. Keith.

  • How to get Custom Time Correction business logic implement for ESS in R/3?

    Hi Experts,
    I am in trouble of implementing the custom requirement of correcting the time in ESS. I have to implement the time corrections as per business logic.
    Can any body tell me where to do this?
    What I need is suppose employee DWS is from 9:30 AM to 6:00 PM and suppose he forgot to punch the In time and then corects the entry for 9:30 AM in ESS then it get inserted into the R/3 data but now requirement is if support the employee has punched but at 10:00 AM and then corrects to 9:30 AM then it does not change the 10:00 AM and we wanna deleted these 10 AM entry.
    Thanks in advance.

    I have solved by created enhancement spot in PT_COR_REQ
    for method IF_EX_PT_COR_REQ~POST_VIA_BLOP
    Regards,
    Gaurav Patwari

Maybe you are looking for