Managed Bean Best Practices

Hi
Are there any best practices for using Managed Beans?
We plan to use our own custom-built JSF components. Need to understand how to design backing beans for performance/effort optimization.
For example :
1. How to make managed beans thread-safe for concurrent requests, without compromising on efficiency/speed?
2. How to enforce the J2EE security with managed-beans?
3. How to decide the scope of these beans to ensure minimal data-storage in session?
4. How to decide the granularity at which a managed-bean should be used for example :
4.1 One bean-per-component
Advantages :
a) if complex components require special data-holding/processing/event-handling capabilities from bean
(e.g. datagrid model,tree model,menu model)
Problems :
- with multiple components in a page/form
a) it becomes tedious to debug/change/track which bean serves which component
b) if session scope is required, too many beans will be cached in session
c) unnecessarily too many beans will be created on server (= n pages * m components-per-page)
d) unnecessarily increases the length of faces-config.xml
4.2 One bean-per-form
Advantages :
a) in multi-form web pages, to ensure the functional behaviour of each form is separate/modular in its own bean.
b) each managed-bean would map to specific/meaningful functionality/user-interaction in use-case.
Problems :
- if form includes complex components (datagrid/tree/menu) requiring a specialised bean class, then
a) either one of the specialized bean has to be augmented with additional logic to handle data/events for all other components within the form
(Not good, as it mixes-up the responsibilities of component-specific-beans, and the bean may no more be reusable in another form)
b) or without using component-specific beans, only single form bean should handle the data/events for all components in the form?
(Neither good, since if a complex tree-compoent is reused in multiple forms, then the logic to handle data/events for such a component will be repeated in those many form-specific managed beans)
4.3 One bean-per-page
Advantages :
a) seems more modular/meaningful way - since a page would map to some feature within the use-case
b) bean will contain only behaviour which is relevent for the associated page/function within use-case
Problems :
a) in multi-form pages, can single bean handle data/events for multiple forms?
b) if page uses complex component (e.g datagrid, tree) that needs its own bean - how does page-bean exchange data with component-bean?
Thanks,
Arti

Are there any best practices for using Managed
Beans?There are no best practices for using Managed Beans in terms of Sun, or other vendors recommendations. But there are some patterns that can be applied to the managed beans (The managed bean is already a pattern). Also common sense is allways a good practice.
For example, the managed bean should not have business logic code, only presentation logic code, etc.
1. How to make managed beans thread-safe for
concurrent requests, without compromising on
efficiency/speed?The beans can be created by request, so concurrency is not an issue. If they are session scope, also is not an issue because, a user can only have one thread running. Only in application scope you must have carefull.
>
2. How to enforce the J2EE security with
managed-beans?see this:
http://jsf-security.sourceforge.net/
About jsf-security
>
3. How to decide the scope of these beans to ensure
minimal data-storage in session?If you wnat minimal data-storage in session the answer is request or none.
In question 4, you make the question and give the answer ;-)

Similar Messages

  • Bean best practice question

    Simple questions (hopefully), I know how to code this but just want some advice on the best way to do the following:
    1. User enters data into HTML form and submits
    2. Some Java at the backend grabs these details and emails them off somewhere
    I am thinking of doing the following, but what’s the best way?
    1. HTML form submits and data is sent directly to a JavaBean (FormBean.java)
    2. FormBean.java contains standard getters/setters but also contains a method called sendMail(), is this bad practice? Do I need a second Bean sendMail.java? Or is this completely the wrong way to do things i.e. should I do this entirely in a servlet with only 1 bean to grab the data (FormBean) and then access from servlet?
    Just a bit confused on what’s best practice for this stuff?
    Thanks!

    2. FormBean.java contains standard getters/setters but also contains a method called sendMail(), is this bad practice? Do I need a second Bean sendMail.java? A better approach is this way
    a) Have all the form data in the form bean
    b) Write sendMail in a all together different class, as action.
    c) Send the form bean as a parameter to sendMail for processing and sending an email
    This way your sendMail() will become a kind of a service. Tomorrow you might have some other data, which you will have to send it in an email. In that case, you just reuse sendMail() method. Otherwise, if you have sendMail() in form bean itself, then if there are many form beans, then you would have to write sendMail() in every form bean, which is a bad practice. One principle of OOAD is to separate the functionality, which is redundant in your classes and make it as a separate module. If there are changes to the sendMail() functionality then, by having it in one module, you only have to change it at one place.
    Or is this completely the wrong way to do things i.e. should I do this entirely in a servlet with only 1 bean to grab the data (FormBean) and then access from servlet?You can have a servlet which acts like a controller, which receives the request parameters, constructs the form bean and invokes appropriate Action (in your case sendMail()). This is same as an MVC framework. Instead of you re-inventing the wheel to create a servlet controller, form bean, action etc. You could use one of the several MVC frameworks available in the market, such as Struts or Spring MVC.

  • Handling units management SAP Best Practices Document Links

    Hi Friends
    I would like know more about handling units management .
    Could you please send me  SAP Best Practices Document handling units management Links .
    Thanks in Advance.
    Thanks
    SR

    Might be useful:
    [Click here|help.sap.com/bp_bblibrary/500/documentation/U43_BB_ConfigGuide_EN_IN.doc|weblink]
    Thanks and Regards,
    Naveen Dasari.

  • Business Transaction Management (BTM) Best Practices Sharing

    A client I am working with is interested in building relationships with other Oracle customers using Business Transaction Management (BTM). The goal is to share tips, tricks, and best practices. BTM came from Oracle's acquisition of AmberPoint. Please contact me if you are interested in engaging. I can be reached at [email protected]

    Unless there is some other reason, users should own the right to share their mailboxes - it shouldn't be something that demands administrator management (if only so that the administrators aren't swamped by user requests for sharing their mailboxes). 
    For true shared mailboxes, when the mailbox is created, full access is granted by an administrator.

  • Access AM method from backing bean - best practice

    Hello,
    I need to call an appModule method from a backing bean. What is better?
    1. Resolve bindings.AMDataControl.dataProvider, get AM and invoke the method directly
    or
    2. Create method action in page definition, resolve OperationBinding from it's binding expression and execute the operationBinding
    I don't need to have a button on the page for this method.
    Rado

    Good question Rado.
    With a "flexible" framework like Oracle ADF, I also ask myself sometimes what would be the preferred approach to do things.
    See also these forum threads:
    - about "ADF Faces: Passing values from a managed bean to ADF BC module"
    http://forums.oracle.com/forums/thread.jspa?threadID=486742
    - about : "ADF Faces: getting selected row data in multi select table ..."
    http://forums.oracle.com/forums/thread.jspa?threadID=503248
    regards
    Jan Vervecken

  • Managing connections best practices

    Hi,
    I have a web application that uses JDBC to retrieve information and display it. My question is: What is the best way to manage your connection objects? I know using a connection pool is probably best, but I'm curious to hear good alternatives? If I need a connection in several places in my web-app, then storing one Connection object in the session seems like a good idea. This way I don't have to create and close my connections each time and slow down performance. But what happens to the connection when the user is no longer in the session. Does the database close the connection implicitly and is there any cons to doing it this way?
    Thanks

    Hi,
    I have a web application that uses JDBC to retrieve
    information and display it. My question is: What is
    the best way to manage your connection objects? I know
    using a connection pool is probably best, but I'm
    curious to hear good alternatives? If I need a
    connection in several places in my web-app, then
    storing one Connection object in the session seems
    like a good idea. The term "session" usually refers to a 'space' that exists both on a client and a server.
    Connections never exist on more than one machine or even more than one application.
    This way I don't have to create and
    close my connections each time and slow down
    performance. But what happens to the connection when
    the user is no longer in the session. Does the
    database close the connection implicitly and is there
    any cons to doing it this way?
    Well one con is that in general you have no control over when the "session" is closed. Thus you must rely on finalize in a java class to close your connections via the GC. And unless you have a really unusual database, or you only use a couple of "sessions" an hour, you are going to run out of connections. This is because GC is optimized for memory handling and not any other resource (a connection is a resource.)

  • Intangible item management & SAP best practice

    All,
    I am wondering what is the best way to handle intangible flow within SAP.
    As a definition, intangible Items are any kind of assets or products that cannot be touched. As an exemple, it can be software / License / License keys. In this question, I am referring to intangible items that are mostly considered as Asset (meaning not standard cost exist for the intangible item).
    Thanks,

    Hi,
    As you wrote, you maintain intangible items as Assests in FI. You can then run depreciation from FI-AA moldule.
    Regards,
    Marcin

  • JSF - Best Practice For Using Managed Bean

    I want to discuss what is the best practice for managed bean usage, especially using session scope or request scope to build database driven pages
    ---- Session Bean ----
    - In the book Core Java Server Faces, the author mentioned that most of the cases session bean should be used, unless the processing is passed on to other handler. Since JSF can store the state on client side, i think storing everything in session is not a big memory concern. (can some expert confirm this is true?) Session objects are easy to manage and states can be shared across the pages. It can make programming easy.
    In the case of a page binded to a resultset, the bean usually helds a java.util.List object for the result, which is intialized in the constructor by query the database first. However, this approach has a problem: when user navigates to other page and comes back, the data is not refreshed. You can of course solve the problem by issuing query everytime in your getXXX method. But you need to be very careful that you don't bind this XXX property too many times. In the case of querying in getXXX, setXXX is also tricky as you don't have a member to set. You usually don't want to persist the resultset changes in the setXXX as the changes may not be final, in stead, you want to handle in the actionlistener (like a save(actionevent)).
    I would glad to see your thought on this.
    --- Request Bean ---
    request bean is initialized everytime a reuqest is made. It sometimes drove me nuts because JSF seems not to be every consistent in updating model values. Suppose you have a page showing parent-children a list of records from database, and you also allow user to change directly on the children. if I hbind the parent to a bean called #{Parent} and you bind the children to ADF table (value="#{Parent.children}" var="rowValue". If I set Parent as a request scope, the setChildren method is never called when I submit the form. Not sure if this is just for ADF or it is JSF problem. But if you change the bean to session scope, everything works fine.
    I believe JSF doesn't update the bindings for all component attributes. It only update the input component value binding. Some one please verify this is true.
    In many cases, i found request bean is very hard to work with if there are lots of updates. (I have lots of trouble with update the binding value for rendered attributes).
    However, request bean is working fine for read only pages and simple binded forms. It definitely frees up memory quicker than session bean.
    ----- any comments or opinions are welcome!!! ------

    I think it should be either Option 2 or Option 3.
    Option 2 would be necessary if the bean data depends on some request parameters.
    (Example: Getting customer bean for a particular customer id)
    Otherwise Option 3 seems the reasonable approach.
    But, I am also pondering on this issue. The above are just my initial thoughts.

  • JSF best practice for managed bean population

    hi;
    consider a simple session scope managed bean with 1 attribute which is calculated dynamically.
    there seem to be 3 ways of populating that attribute (that i could think of):
    1. have the bean's get<attribute> get the data and populate it
    2. have the constructor of the bean get the data and populate it
    3. have an action get the data, and set it from the action code (maybe use a valueBinding to get the bean if the bean which needs population is not the same bean that holds the action) .
    option 1 seems ok for situations where i need my data to be calculated for every valueRef for that attribute but is an overhead for data that need not be calculated for every valueRef.
    option 2 will ensure that te data is calculated only once per session. but it still looks kinda strange to do it
    with option 3, it seems you should populate the dynamic content of the next page and its intuitive but some places in the page might be common content with dynamic data and this has nothing to do with navigation and the next page to be displayed.
    is there a best practice of how to populate a managed bean data?
    are different cases fit different ways?
    any thoughts are appriciated.

    I think it should be either Option 2 or Option 3.
    Option 2 would be necessary if the bean data depends on some request parameters.
    (Example: Getting customer bean for a particular customer id)
    Otherwise Option 3 seems the reasonable approach.
    But, I am also pondering on this issue. The above are just my initial thoughts.

  • Managed bean inheritance best practice

    Hi!
    I'm new to JSF so I would like to apologize if my question is trivial, but I haven't been able to find proper solution.
    I'm using JSF 1.2 on WAS CE. I have a page where user can search for some entities, both person and company, which share some data, but have some different properties. Both inherit from entity class, so search results are displayed in dataTable as base entity objects. Each dataTable row has commandLink which should navigate user to specific (person or company) page for editing data. For example, if user clicks on commandLink in person data row, I would like to show personEdit page with all data set to components. I understand that I can use action to set navigation to proper page, and I have done so (following action() method). I have implemented EntityBean, PersonBean and CompanyBean:
    public class EntityBean {
        protected Entity entity;
        public int getId() {
            return entity.getId();
        public void setId(int id) {
            entity.setId(id);
        public String action() {
            // Some code which defines return value for action invoking.
        public void edit(ActionEvent event) {
            // Get entity data for edit.
    public class PersonBean extends EntityBean {
        public String getFirstName() {
            return ((Person)entity).getFirstName();
    public class CompanyBean extends EntityBean {
        public String getName() {
            return ((Company)entity).getName();
    }I tried combining action with actionListener method (+edit(ActionEvent event)+ method) invoked from commandLink, but if it is invoked on mapped entityBean, I get only entity properties set on any other page which is shown after invoked action. If method is invoked on i.e. personBean (same method, not overriden), I get NullPointerException for trying to access property for base entityBean.
    How should I invoke proper data initialization for bean shown on another page?
    Thanks in advance.

    Thank you for your quick reply. Beside the code for managed bean classes, here's the rest of the code for this specific problem.
    In faces-config.xml I have the following configuration:
         <managed-bean>
              <managed-bean-name>entitySearchBean</managed-bean-name>
              <managed-bean-class>entities.EntitySearchBean</managed-bean-class>
              <managed-bean-scope>request</managed-bean-scope>
         </managed-bean>
         <managed-bean>
              <managed-bean-name>personBean</managed-bean-name>
              <managed-bean-class>entities.PersonBean</managed-bean-class>
              <managed-bean-scope>request</managed-bean-scope>
         </managed-bean>
         <managed-bean>
              <managed-bean-name>entityBean</managed-bean-name>
              <managed-bean-class>legalentities.EntityBean</managed-bean-class>
              <managed-bean-scope>request</managed-bean-scope>
         </managed-bean>On my JSP, I have a dataTable loaded with entityBean objects, and the following code for showing editPage:
         <h:column>
              <h:commandLink id="editLink" action="#{entitySearchBean.editEntity}" actionListener="#{entityBean.edit}">
                   <h:outputText value="#{bundle.edit}" />
                   <f:param id="editId" name="editId" value="#{entity.id}" />
              </h:commandLink>
         </h:column>
    </h:dataTable>So, what I'm trying to do is to call entityBean.edit which should initialize EntityBean with entity data, and it sets i.e. person data to entity field of EntityBean class. I also call editEntity method on EntitySearchBean class (bean used just for searching entities with some criteria), and pass id property of selected entity in dataTable.
    What I'm expecting is to get personEdit.jsp with loaded personBean data initialized from actionListener on searchPage.jsp. Is it possible or is there some other way to do this?

  • What is a best practice for managing a large amount of ever-changing hyperlinks?

    I am moving an 80+ page printed catalog online. We need to add hyperlinks to our Learning Management System courses to each reference of a class - there are 100s of them. I'm having difficulty understanding what the best practice is for consistent results when I need to go back and edit (which we will have to do regularly).
    These seem like my options:
    Link the actual text - sometimes when I go back to edit the link I can't find it in InDesign but can see it's there when I open up the PDF in Acrobat
    Draw an invisible box over the text and link it - this seems to work better but seems like an extra step
    Do all of the linking in Acrobat
    Am I missing anything?
    Here is the document in case anyone wants to see it so far. For the links that are in there, I used a combination of adding the links in InDesign then perfecting them using Acrobat (removing additional links or correcting others that I couldn't see in InDesign). This part of the process gives me anxiety each month we have to make edits. Nothing seems consistent. Maybe I'm missing something obvious?

    what exatly needs to be edited, the hyperlink or content or?

  • Best practices for managing Movies (iPhoto, iMovie) to IPhone

    I am looking for some basic recommendations best practices on managing the syncing of movies to my iPhone. Most of my movies either come from a digital camcorder into iMovie or from a digital Camera into iPhone.
    Issues:
    1. If I do an export or a share from iPhoto, iMovie, or QuickTime, what formats should I select. I've seem 3gp, mv4.
    2. When I add a movie to iTunes, where is it stored. I've seen some folder locations like iMovie Sharing/iTunes. Can I copy them directly there or should I always add to library in iTunes?
    3. If I want to get a DVD I own into a format for the iPhone, how might I do that?
    Any other recommedations on best practices are welcome.
    Thanks
    mek

    1. If you type "iphone" or "ipod" into the help feature in imovie it will tell you how.
    "If you want to download and view one of your iMovie projects to your iPod or iPhone, you first need to send it to iTunes. When you send your project to iTunes, iMovie allows you to create one or more movies of different sizes, depending on the size of the original media that’s in your project. The medium-sized movie is best for viewing on your iPod or iPhone."
    2. Mine appear under "movies" which is where imovie put them automatically.
    3. If you mean movies purchased on DVD, then copying them is illegal and cannot be discussed here.
    From the terms of use of this forum:
    "Keep within the Law
    No material may be submitted that is intended to promote or commit an illegal act.
    Do not submit software or descriptions of processes that break or otherwise ‘work around’ digital rights management software or hardware. This includes conversations about ‘ripping’ DVDs or working around FairPlay software used on the iTunes Store."

  • SAP Best Practice Integrated with Solution manager

    We have a server in which we installed SAP Best practice baseline package and we have the solution manager 7.01 SP 25
    We maintained the logical port but when we try to check connectivity to solution manager we got the following error:
    Connectivity check to sap solution manager system not successful
    Message no. /SMB/BB_INSTALLER375
    Can anyone guide us how to solve the problem and also if there is another way to upload the solution defined on the best practice solution builder into sap solution manager as a template project
    Thanks,
    Heba Hesham

    Hi,
    Patches for SAPGUI 7.10 can be found at the following location:
    http://service.sap.com/patches
    -> Entry by Application Group -> SAP Frontend Components
    -> SAP GUI FOR WINDOWS -> SAP GUI FOR WINDOWS 7.10 CORE
    -> SAP GUI FOR WINDOWS 7.10 CORE -> Win 32
    -> gui710_2-10002995.exe

  • Basic Strategy / Best Practices for System Monitoring with Solution Manager

    I am very new to SAP and the Basis group at my company. I will be working on a project to identify the best practices of System and Service level monitoring using Solution Manager. I have read a good amount about SAP Solution Manager and the concept of monitoring but need to begin mapping out a monitoring strategy.
    We currently utilize the RZ20 transaction and basic CCMS monitors such as watching for update errors, availability, short dumps, etc.. What else should be monitored in order to proactively find possible issues. Are there any best practices you all have found when implimenting Monitoring for new solutions added to the SAP landscape.... what are common things we would want to monitor over say ERP, CRM, SRM, etc?
    Thanks in advance for any comments or suggestions!

    Hi Mike,
    Did you try the following link ?
    If not, it may be useful to some extent:
    http://service.sap.com/bestpractices
    ---> Cross-Industry Packages ---> Best Practices for Solution Management
    You have quite a few documents there - those on BPM may also cover Solution Monitoring aspects.
    Best regards,
    Srini
    Edited by: Srinivasan Radhakrishnan on Jul 7, 2008 7:02 PM

  • Manage vendor bank account in company code level - Best practice

    hi,
    we have on our client several company codes, and we are thinking how to manage the vendor bank accounts in company codes level or in centeral level.
    our problem with company codes level is that the vendor bank accounts define in a centeral level so technically with sap standard it is not possible. if anyone can tell me that this is possible i will be very happy to know.
    in centeral level our problem is with the business process because of we do not have a person (functionalism ) that can be responsible for all the company codes, basically every company shoule be responsible for her vendors
    please advice what is the best practice to manage vendor bank accounts in enviroment of several company code
    regards,
    meir

    hi Raghu,
    i know that but this is not my qusition.
    which company code will be responsible to enter the bank account in the vendor master data? as i say the vendor bank accounts manage in centeral level and not in company code level and this is our problem and i like to know how other companies with the same situation handle with this issue
    and also after we have the bank accounts in the vendor master data what happend if for one vendor has several bank accounts one for every company code? how the payment program F110 could know automaticaly which bank account to take (i know that there is an optoin to use Partner bank type in the vendor master data, and enter this PBT when posting the invoice of the vednor, but this is not good because of we do not want the the accountant will be responsible from which bank the vendor get his money).
    regards,
    meir

Maybe you are looking for

  • Seeking library with industrial HMI drawings

      Hello, I am Developing a nice HMI that communicates with PLC;s an d DCS's automation and control systems using visual studio 2008 and NModbus.dll lilbrary. The only thing I am still missing are the libraries for the HMI drawings, What I am looking

  • Why are these fonts auto activating?

    I've just updated to Tiger 10.4.8. One day later I install CS2 (previously had CS). I use FontAgent Pro. Now, whenever I open Safari or any CS2 app. (just the app, not an actual document) a bunch of fonts are auto activated which I don't want to be a

  • An error occurred while updating mail preferences

    Hi guys, i get this error "An error occurred while updating mail preferences" when try to enable vacation message in uwc.....any idea? is a hosted domain uwc...

  • Prime Infrastructure 2.1 - Fan-Failure SNMP-Trap Issue

    Hello, I am facing the following Prime Infrastructure (v2.1) issue: - A Fan-Failure SNMP-Trap from a Cisco 3650 switch doesn't appear on Prime, but a Link-Failure from the same switch does. - The both events appears on Prime with Syslog. - The comman

  • JavaScript and Content Server Portlets

    Header, footer, news, custom, doesnt matter. Can you use javascript in them and if so, to what extent? For mouseovers, animation, div tag management and manipulation, etc...