[RSS]

On-demand Managed Bean Corss Reference

Introduction

As of NetBeans 6.0, the VW ensures that there is an accessor for every managed bean of outer (larger?) scope when a new Page, Page fragment, or lifecycle (subclasses of Abstract*Bean's from appbase library) Request, Session and Application bean is created. This is done in anticipation that the user may want to script these managed beans in Java code. For example:

  • Page1.java
    /**
     * <p>Return a reference to the scoped data bean.</p>
     *
     * @return reference to the scoped data bean
     */
    protected SessionBean1 getSessionBean1() {
        return (SessionBean1) getBean("SessionBean1");
    }

    /**
     * <p>Return a reference to the scoped data bean.</p>
     *
     * @return reference to the scoped data bean
     */
    protected RequestBean1 getRequestBean1() {
        return (RequestBean1) getBean("RequestBean1");
    }

    /**
     * <p>Return a reference to the scoped data bean.</p>
     *
     * @return reference to the scoped data bean
     */
    protected ApplicationBean1 getApplicationBean1() {
        return (ApplicationBean1) getBean("ApplicationBean1");
    }
  • RequestBeans1.java
    /**
     * <p>Return a reference to the scoped data bean.</p>
     *
     * @return reference to the scoped data bean
     */
    protected SessionBean1 getSessionBean1() {
        return (SessionBean1) getBean("SessionBean1");
    }

    /**
     * <p>Return a reference to the scoped data bean.</p>
     *
     * @return reference to the scoped data bean
     */
    protected ApplicationBean1 getApplicationBean1() {
        return (ApplicationBean1) getBean("ApplicationBean1");
    }

This is a problem because it bloats the Java source files. Moreover the user may never script all those managed beans in their Java code. Therefore this automatic insertion of managed beans accessors will be replaced by on demand management of managed beans cross reference.

Functional specs

  • The new templates will not start with any managed bean accessors. These will not be added at the time of template instantiations or copy/paste.
  • The user will be able to manage the managed bean crossreferences in a Java file using the following action:
    • Manage Managed Bean Getters action. This action will be integrated with the Generate code (Alt+Insert) action of the Java editor. When the action is invoked the following dialog will be shown:
+-------------------------------------------------------------------------------+
|                                                                               |
+-------------------------------------------------------------------------------+
| Name:  Page1                                                                  |
| Class: webapplication1.Page1                                                  |
| Scope: Request                                                                |
|                                                                               |
|  Add   Remove Name             Class                            Scope         |
|  ---   ------ ----             -----                            -----         |
|  [ ]   [ ]    RequestBean1     webapplication1.RequestBean1     Request       |
|  [ ]   [ ]    SessionBean1     webapplication1.SessionBean1     Session       |
|  [ ]   [ ]    ApplicationBean1 webapplication1.RequestBean1     Application   |
|                                                                               |
|                                                   [Help] [Generate] [Cancel]  |
+-------------------------------------------------------------------------------+

The checkboxes in the Add and Remove column will be disabled depending on the pre absence and presence of the accessor in the current bean. For page beans only non page request beans will be shown in the table. The accesors will be added and removed based on the selected checkboxes. The action label and the text in the dialog will be I18Ned. The action and the dialog will be A11Yed.

The generate action will be covered by an atomic Undo/Redo.

Test Cases