JavaBean Models, Command Bean and J2EE Design Pattern

Hello,
I have read the available "How To", “Using EJBs in Web Dynpro Applications” where the author mentions that one should use a Command Bean (according to J2EE Design Patterns) so that one can invoke business methods in a Session Bean from our Web Dynpro Application. Well, although, I have read some available articles in the internet about J2EE design patterns, I still have some questions about command beans and its usage in Web Dynpro applications.
I have developed a WD App which uses EJBs to read data from the DB.
Let's suppose I only have two tables: BOOKS and AUTHORS.
Let’s also suppose I have to Entity Beans (one for each table) and a Session Bean with two methods: Book[] getAllBooks() and Author[] getAllAuthors();
I also have a Command Bean which I imported in my WD App.
My questions are:
How should I design my Command Bean?
Can I have only one Command Bean with two methods each calling one of the methods of the Session Bean?
Or instead should I design two Command Beans, one for each call?
In the last case do the methods must be named <b>execute</b> or can I name them whatever I want?
Furthermore, how should I store the data in my command bean? In instance variables?
If so, can I use array of a class representing a record in the database table (for instance, classes Book and Author) or do I have to store the data in a generic collection (such as ArrayList for instance)?
I ask this last question because if I try to store the data in an array when I am importing the Command Bean as a JavaBean model I always get an error.
One last question: Can the Command Bean execute method directly return the data or should I always store the data in an instance variable an then get it using getter methods?
I know this questions are more about J2EE Design Patterns and JavaBeans specification than they are about Web Dynpro but I also have doubts about the rules that the command bean must obey in order to accomplish a successful JavaBean model import in WD.
Some guidance or tips would be highly appreciated.
King Regards

I have the same problem.
Does anyone know the solution?
Thanks
Davide

Similar Messages

  • J2EE design patterns vs SAP component model

    Hello,
    does anyone have documentation or articles which makes a link between the J2EE design patterns and the SAP component model ?
    Thanks

    Hi Thierry,
    > What do you mean by assembling DC's into another DC ? Do you mean by using child DC's? Also , the J2EE server DC will have to be in a SC.
    If you create "Java" DC that DC will not have a deployable result on its own. Typically you create a public part with purpose "compilation" (API) and a public part with purpose "assembly". If you define a dependency from an EAR DC or a J2EE Library DC to that assembly public part then the Jar file contained in that public part will be assembled into your (deployable) .ear file or the J2EE library.
    Child DCs are just a means of limiting visibility/scope, similar to ACLs.
    As long as you are working with a "track" each and every DC will be part of an SC. You define a track, you add "developed" SCs, you get a "compartment" where you can create DCs. So each DC automatically belongs to an SC. (But not all DC types produce deployable results, EJB Module/Web Module also need to be assembled into an EAR).
    > is it typical to have an SC dedicated to utility classes?
    Depends on the size of the project/product. I'd start by putting utility classes into some utility package (pure Java). If that gets too large I'd put utility classes sorted by functionality into DCs (Java libraries = jars). If that gets too large its time to think about utility SCs. Otherwise the tradeoff between meta-information and real content might be too much. As the project/product grows the need for refactoring may arise...
    Regards,
    Marc

  • Suggest good book for J2EE Design Pattern.

    Is there any good book for J2EE Design pattern? I know Head First Design Pattern book, but is focuses oncore java. I want to learn in detail with examples J2EE design pattern.
    Please suggest good books.
    Thanks in advance.
    Rahul.

    most j2ee patterns are discredited now. they were mostly workarounds for deficiencies in ejb 1 & 2 specs.
    "core j2ee patterns" is your best bet, but take it with a grain of salt.
    better to learn spring, IMO:
    springframework.org
    %

  • Difference between n-layer software architecture and MVVM design pattern?

    hello everyone,
    I am not clear with this concepts of Software architecture pattern and design pattern.
    I am developing an wpf application using MVVM. Now, my question is, does MVVM come under n-layered architecture? 
    or n-layer architecture and MVVM both are different? 
    Regards,
    Rakesh.N
    Rakesh murthy

    "
    Now my question is, i want to process the data which i get from database. where should i write that processing logic after getting the data from database? in model classes? or in view model classes?
    The model is however the data comes from wherever it comes from.
    If there is any processing after you get it then that would be in the viewmodel.
    The viewmodel adapts your data to the view.
    If it needs any adapting then the viewmodel does that, not the model.
    EG here
    protected async override void GetData()
    ThrobberVisible = Visibility.Visible;
    ObservableCollection<CustomerVM> _customers = new ObservableCollection<CustomerVM>();
    var customers = await (from c in db.Customers
    orderby c.CustomerName
    select c).ToListAsync();
    foreach (Customer cust in customers)
    _customers.Add(new CustomerVM { IsNew = false, TheEntity = cust });
    Customers = _customers;
    RaisePropertyChanged("Customers");
    ThrobberVisible = Visibility.Collapsed;
    That logic is in a viewmodel.
    in this context , in which layer the viewmodel and model classes are put under in n-tier architecture?
    They're in two of the n layers/tiers.
    Or they're in one.
    Depending on how someone decides to classify a layer or a tier.
    There is no absolute definition.
    Why would you care?
    Hope that helps.
    Technet articles: Uneventful MVVM;
    All my Technet Articles

  • How to create plug and play design pattern on a environment

    Hi All,
    Help me to get a best design for my problem statement.
    Problem Statement: I have to create a platform where I should be able to plug and play different components. explaining better with example
    Example:
    1. I have to create a platform for school
    2. In this school platform we have to plug in multiple components like "Student", "Teacher", "Subjects", "ClassPeriods" etc.,
    3. These components should be easily plug/unplug and play
    4. Like, the component "ClassPeriods" want to purchase from Vendor 1 and plug it to "School" platform it should work.
    5. Incase if we want to unplug the "ClassPeriod" component provided bfy Vendor 1 from "School" platform and want to plug the "ClassPeriod" from Vendor 2. then the Design should support without any extra effort.
    Suggest me the best design pattern for the problem
    This design pattern is for ASP.Net
    Thanks,
    S.Kannan

    Sounds like you're looking at 'Composition'. As a background, and possible solution, take a look at MEF;
    http://mef.codeplex.com/
    http://pauliom.wordpress.com

  • Simple J2EE Design patterns for newbies

    Hey
    I've managed to get a basic understanding of how J2EE web applications are put together. I've done some simple stuff like jsp's posting to servlets to do database inserts for example.
    In an effort to get a more well rounded understanding of whats going on I want to write a simple phonebook web app. As my previous adventures in web development have been php pages that mixed php and html. I really want to get away from the bad habits that people say PHP can encourage and get a proper MVC setup going. I'll describe my plan and then all you guys can rip it apart and hopefully in the process I will learn something Smile
    In the case of a user wishing to insert a new record. I imagine the process to be the following.
    JSP/HTML form that posts to a servlet, the servlet then uses a bean to handle the database interaction and once the bean has finished the jdbc work the servlet forwards the user to another jsp that displays the current contents of the table.
    So, for example I will write a bean that has 4 methods. One to read the full contents of the table, one to insert a new record, one to update and finally one to delete.
    Depending on what parameters are passed to the servlet via HTTP POST it will call the corresponding javabean method.
    Am I on the right track?
    Thanks

    Ok well this is what I have come up with so far
    Servlet
    public void doGet (HttpServletRequest req, HttpServletResponse resp)
         throws ServletException, IOException
            out = resp.getWriter();
            String action = req.getParameter("action");
                String name = req.getParameter("name");
                String phone = req.getParameter("phone");
                DbWorker db = new phonebook.DbWorker();
                if (action.equals("insert")){
                db.doInsert(name,phone);   
                } else if (action.equals("delete")){
                db.doDelete(name,phone);   
                } else {
                out.println("you didnt ask me to do anything");   
                }  And the "Bean" it uses to do the database work is below. Note: The term java bean is used all in all the books and online forums I have seen. Whats so strange about its use today (just curious). Anyway the db stuff
    public void doInsert(String name, String phone){
            String query = "Insert into test(name,email) values(?,?)";
            try{   
                PreparedStatement stmt = con.prepareStatement (query);
                stmt.setString(1, name);
                stmt.setString(2, phone);
                stmt.executeUpdate();
            } catch (SQLException e){
            public void doDelete(String name, String phone){
                String query = "delete from test where name = ? and email = ?";
                try{   
                PreparedStatement stmt = con.prepareStatement (query);
                stmt.setString(1, name);
                stmt.setString(2, phone);
                stmt.executeUpdate();
            } catch (SQLException e){
            }  The code above works without any problems. However I now want to write a method to execute a select statement and I want it to be able to return the results to a jsp that can then iterate through and print out the results. My guess is that i create a method to return the resultsset array that a jsp page picks up by using the standard tag library to go through it and print out the results?

  • Recommanded J2EE design pattern

    I have a program with the following design:
    one WebService
    which calls one EJB (Session bean).
    The EJB is calling one of 9 STATIC(!) methods (depends on parameter that webservice accept) which can call another static methods etc...
    I know this design is bad, and I want your recommended design for this application.
    I am getting an outOfMemory exception when i run a loop that calls this webservice for many time.
    Is there any design which may help me avoid this outOfMemory exception ?
    Again , please refer this:
    ** one webservice
    ** one ejb who calls to static methods - depends on parameter that webservice accept.
    Thanks

    Hi duffymo, Thanks for attentionHi George, it's my pleasure. Maybe we'll both learn something here.
    answers :
    1) its a stateless session beanVery good. Any private data members in that SLSB?
    2) The out of memory error happens when i am running
    the application from 150 clients repeatly as a load
    testAre you monitoring memory using a tool like JVMStat from Sun, OptimizeIt, or JProbe? I'd recommend it.
    How much memory have you allocated to the JVM? What are the -Xms and -Xmx settings? Have you tuned any other JVM settings for memory and GC?
    3) you say : "none of these objects can be GC'd" ,
    why is that ?A static object is associated with a class. Once a class is loaded by the JVM it's never unloaded. The static objects will remain in memory for as long as the class does.
    4) The stack trace shows an outOfMemory exception and
    can happen in any phase, after ~X times.(depends on
    free JVM memory).Objects aren't being cleaned up. You're hanging onto references, so the GC can do its job.
    5) I can't run a profiler on this machine because of
    a technical reasons.You can certainly run JVMStats. It's non-invasive.
    6) I indeed saw the perm space growing with systemout
    methods
    The big question is about the coding,
    1) is there anyway to improve this kind of code
    writing ? Undoubtedly yes.
    2) Will the GC run better if these methods would be
    running from a nonstatic source ? should i write
    classes for these methods and invoke an object for
    each call ? If the methods are all related, differentiated only by a parameter, why have nine objects? Why not one SLSB with nine methods?
    3) Should i write 9 SLSB and let the webservice
    decide which one to call ? or should i write one SLSB
    with 9 methods and let the webservice
    decide which method to call ? I'd try the latter.
    are the 3 questions above have anything with
    memory/GC performance ? I don't know without more info.
    %

  • BusinessDelegate and ServiceLocator Design Pattern

    Hi guys,
    I have a question about the BusinessDelegate Pattern.
    I would like to know where the BusinessDelegate and the ServerLocator implementation must be done?
    On the client or on the server side.
    Let's suppose I have a simple java client which calls a method on a Remote EJB deployed on an EJB server on a different machine.
    The BusinessDelegate and the ServerLocator implementation must be either bundled with the client jar or
    in the client classpath.
    Is it correct??
    Otherwise, if they are on the server side (part of the EJB jar) the client will never succeed in calling the BusinessDelegate method because the JNDI Lookup is done on the server side and the client has no way to see the BusinessDelegate on the Remote server.
    Is it correct??
    Please, help me understand this pattern.
    I see all the time on the Diagrams the BusinessDelegate and the ServerLocator on the server side.
    Thank you very much.
    iako73

    Hi,
    The business delegate's purpose is to abstract the business tier implementation from the client.
    It is used in the web tier (or any presentation tier) to hide the business service behind an interface, reducing the coupling between application layers.
    If the business tier is implemented as EJB's or any J2EE container service accessible through JNDI. The Business delegate implementation uses the Service locator pattern to abstract and hide all JNDI calls from the delegate.
    Hence both patterns are applicable and used in the presentation tier.
    See core J2EE patterns for full description : http://java.sun.com/blueprints/corej2eepatterns/Patterns/

  • DAO J2ee design pattern

    Hi,
    I understood the structure of DAO pattern like : The business Object uses Data AccessObject which encapsulates the DataSource. The DAO creates/uses the Transfer Object and the BusinessObject obtains/modifies the Transfer Object.
    Can i get the sample code for this pattern and any links for the code.
    Thanks

    Hi,
    I understood the structure of DAO pattern like : The
    business Object uses Data AccessObject which
    encapsulates the DataSource. The DAO creates/uses the
    Transfer Object and the BusinessObject
    obtains/modifies the Transfer Object.
    Wrong.
    Can i get the sample code for this pattern and any
    links for the code.
    ThanksYou should be able to take it from there if you understood it that well. Too bad you don't
    %

  • Importing Java Bean Model (Command Bean) with Session Bean

    Hello all,
    I'm trying to import a CommandBean as a Java Bean Model in WebDynpro but I'm prompted with an error indicating that I cannot import the EJB (Session Bean) DC that is being accessed by my CommandBean - hence failing to import the CommandBean DC as well.
    How do I import this?
    Help please.
    -Regards,
    Jan

    HI,
    just add ejb20.jar as an external jar in your WD project.

  • J2EE Design Patterns

    If you don't have SessionFacade pattern implementation,is it possible to have a Business Delegate talking to a Session Bean
    Thanks in advance

    yes its possible

  • J2ee design pattern

    what's the role of the handle in the business delegate pattern sequence diagram

    Hi,
    If I get it clear, the String version of handle can be used to reconnect the business service. An example can be found there:
    www.javapassion.com/j2ee/DesignPatterns.pdf
    Hope this helps.
    L.P.

  • Cairngorm View Helper - Command resuability and tight coupling with view

    I am new to Cairngorm framework. Currently we are converting
    our project to Cairngorm framework. I have some very basic doubts
    regarding the framework. Basically I am a java/J2ee
    programmer and got very good experience in struts framework
    and other J2EE design patterns.
    I have some doubts and needs advice from the community .
    My very first doubt is regarding the ViewLocator pattern used
    in the Cairngorm framework to access
    the view from Command class. At a very high level my
    understanding about command pattern is that command object
    shouldn't know anything about the caller. Command should execute a
    the business logic and update the model.
    But if we use the ViewLocator pattern the command object
    should know about it's caller class and the method name of the
    view/viewhelper class which should be executed after the command
    logic. In this scenario we will not be able to reuse the command
    class and a very tight coupling is established between the command
    and view.
    I have read from flex and cairngorm related blogs about an
    'Observer' and 'ChangerWatcher' patterns which seems to be right
    approach for me rather than using the ViewLocator. But as far as I
    know these are not part of the framework.
    I would like to know what is the recommended approach from
    the cairngorm framework team for executing View related logic after
    firing the Cairngorm event.
    If we use the ViewLocator pattern, there is no reusability as
    far as the command is concerned and also a very tight coupling is
    happening with the command and view.
    Is this the right approach..?
    Please advice..

    Hi, the view Locator has very issues that we have to have in mind, y most of the  problems are similar when we are using the Drag Manager , when we are using modules and load this view dynamically.
    The solution is simple and you told it. Binding by Watchers in the model Locator and checking the model locator variables when we load a module.
    In the view that we want to change we can add a Change Watcher linking a model locator variable to a function in the view, we change the model in de command and automatically change the value in the view.
    There are 2 ways to do the same concept, but is good only when the call to a cairngorm only affects the view that its calling it and known more has to know, so in theory you don’t need to change the model to impact the view.
    First is adding a Iresponder in to the event by Get Set so in the view, when you create a event for cairngorm and have to pass through the event an IResponder  (mx.rpc.IResponder). When you are in the command in the result or fault you can do event.responder.result = event or event.responder.fault = event and this well go directly into the view result o fault. So you don’t have to pass through the model. (Responder is your get set in the Event of private var _responder:IResponder)
    The other way is the same but using UM cairngorm that has CallBacks. And it’s pretty much the same but the event and all the cairngorm has callbacks and notifyCaller.
    Well I hope I said something useful.
    I did a UM cairngorm diagram in English http://www.developyourdream.net/tutoriales/tutoriales_flex_avanzados/cairngorm_universal_m ind/Cairngorm.swf
    Sorry me English and if somebody talks Spanish you can go check my blog http://www.developyourdream.net/ 

  • Design Patterns w/o EJB

    Greetings, I am attempting to build a JSF application while learning JSR 127 and a few of the J2EE design patterns. The problem that I am having is that I don't plan on using EJB/Spring with my project and many of the tutorials I have been able to find place a focus on the EJB/Spring implementation details which are both overkill for this project. That said, I want to learn the appropriate patterns to build a functional application without catching "pattern fever".
    I have a general idea of some of the patterns I need to use to get from the presentation tier to the data tier, such as Business Delegate and Data Transfer Object. However, I'm not sure I understand how to use these in conjunction with the managed beans facility. Do the managed beans contain (as in composition) the Business Delegate objects? Or do I use a DTO to push the data from the managed bean to the Delegate? How much if any logic do I put in the managed beans if I'm using them in this fashion (or are they basically just fields and getter/setters)?
    All comments or suggestions are sincerely appreciated,
    Jon

    Hi,
    Have you taken a look at Java BluePrints Solutions Catalog:
    https://blueprints.dev.java.net/bpcatalog/
    The Solutions Catalog focuses on different topics specifically so that you can pick and choose which articles are most interesting to you.
    -Larry

  • What Design Pattern - Change Language functionality

    On my application, I will have a series of buttons to choose
    a language. When the user chooses a language, all control labels,
    pop-up messages and others will change at the chosen language.
    I would like to do this from an OOP point of view and use
    Design Patterns. Which one would you recommend to use?
    My guess is the Strategy Pattern. Am I right?
    Thanks for any comment or link.

    The Strategy Pattern is used to swap algorithms dynamically.
    Based on user input a decision can be made to run a (set of)
    function(s). This behaviour is encapsulated in seperate objects.
    You just want to swap data at runtime. Or maybe set some
    behaviour regarding specific functions in languages like the way
    currencies are handled, measurements and the like. The latter would
    be implemented as Interpreter Pattern.
    When it's merely data that needs to changed/loaded at
    runtime, than it's more like a change of the Model in the MVC
    design pattern, using an Observer to notify all registered
    'listeners' and using a Command to get the thing going.

Maybe you are looking for

  • HTTP response code: 500  (Internal Server Error) when updating CMS

    Hi all, I'm using NWDI to develop a component. After I have created Product and SC in SLD, I'm going to add SC into my Track. However the component doesn't appear in the list, even I have updated CMS. Then I checked the CMS log file, it says #1.5#001

  • Had to reinstall os ,and cannot access itunes although backed on time machine help

    had to reinstall OS last july after exel update installed virus  and cannot access itunes although backed on time machine help

  • Missing cover art swipe-back to song list-command after update

    Before when listening to music, you could swipe your finger to the right and the Touch would go back to the listing of songs. It seems after the last update this does not work anymore. Any tips? It makes it more difficult to use one-handed.

  • User exit for Delivery PGI

    Hi, I want to use user exit which can be triggered during Delivery PGI. I read on the forums that I can use BADI LE_SHP_GOODSMVMT. I searched for this BADI in transaction SE18 and there is no BADI with this name. Also I searched in Customization for

  • Tabular Form - Checkbox

    This is a simple requirement which I have for the first time. I want to have a checkbox in a tabular form, which will show checked value for 'Y' and unchecked for NULL. This sounds simple and is actually a usual requirement in many cases. However, I