Thursday, April 25, 2013

Create DB connection in JDev 11g using Custom JDBC URL

Sample: jdbc:oracle:thin:@(DESCRIPTION=(ENABLE=BROKEN)(ADDRESS_LIST=(LOAD_BALANCE=on)(ADDRESS=(PROTOCOL=tcp)(HOST=uslaxorcstgdb13v.hrbl.net)(PORT=1524))(ADDRESS=(PROTOCOL=tcp)(HOST=uslaxorcstgdb14v.hrbl.net)(PORT=1524)))(CONNECT_DATA=(SERVICE_NAME=SOMEDB)))


Friday, April 5, 2013

How to Customize the ADF Page Lifecycle to Work Programmatically with Bindings


Globally Customizing the ADF Page Lifecycle

To globally customize the ADF Page Lifecycle, do the following:
  • Create a class that extends oracle.adf.controller.faces.lifecycle.FacesPageLifecycle
  • Create a class that extends ADFPhaseListener and overrides the createPageLifecycle() method to return an instance of your custom page lifecycle class.
  • Change your faces-config.xml file to use your subclass of ADFPhaseListener instead of the default ADFPhaseListener. As shown in Figure 10-12, you can do this on the Overview tab of the JDeveloper faces-config.xml editor, in the Life Cycle category.

Note:
Make sure to replace the existing ADFPhaseListener with your custom subclass of ADFPhaseListener, or everything in the JSF / ADF lifecycle coordination will happen twice!

Figure 10-12 Setting Up a Custom ADFPhaseListener To Install a Custom Page Lifecycle Globally
Image of faces-config.xml editor
The SRDemo application includes a SRDemoPageLifecycle class that globally overrides the reportErrors() method of the page lifecycle to change the default way that exceptions caught and cached by the ADF Model layer are reported to JSF. The changed implementation reduces the exceptions reported to the user to include only the exceptions that they can directly act upon, suppressing additional "wrapping" exceptions that will not make much sense to the end user.

Customizing the Page Lifecycle for a Single Page

You can customize the lifecycle of a single page setting the ControllerClass attribute of the pageDefinition to identify a class that either:
  • Extends oracle.adf.controller.v2.PageController class
  • Implements oracle.adf.controller.v2.PagePhaseListener interface
The value of the page definition's ControllerClass attribute can either be:
  • A fully qualified class name
  • An EL expression that resolves to a class that meets the requirements above
Using an EL expression for the value of the ControllerClass, it is possible to specify the name of a custom page controller class (or page phase listener implementation) that you've configured as a managed bean in the faces-config.xml file. This includes a backing bean for a JSF page, provided that it either extended PageController or implements PagePhaseListener.
Figure 10-13 illustrates how to select the root node of the page definition in the Structure window to set.
Figure 10-13 Setting the ControllerClass of a Page Definition
Image of setting a controller class in Property Inspector

Note:
When using an EL expression for the value of the ControllerClass attribute, the Structure window may show a warning, saying the "#{YourExpression}" is not a valid class. You can safely ignore this warning.

ADF VO Record Status Display


When building pages you'll often want to display some kind of record status indicator like: "Record 5 of 25". If you display multiple rows on a page, then you may also want to display a variant like "Record 5-10 of 25". You can build a record indicator like this using simple text components, each of which displays an appropriate value from an iterator binding or table binding using an EL expression. The iterator binding's rangeSize property defines how many rows per page it makes available to display in the user interface. If your page definition contains either an iterator binding named SomeViewIter or a table binding named SomeView, you can reference the following EL expressions:
  • Number of Rows per Page
    #{bindings.SomeViewIter.rangeSize}
    #{bindings.SomeView.rangeSize}
  • Total Rows
    #{bindings.SomeViewIter.estimatedRowCount}
    #{bindings.SomeView.estimatedRowCount}
  • First Row on the Current Page
    #{bindings.SomeViewIter.rangeStart + 1}
    #{bindings.SomeView.rangeStart + 1}
  • Last Row on the Current Page
    #{bindings.SomeViewIter.rangeStart + bindings.SomeViewIter.rangeSize}
    #{bindings.SomeView.rangeStart + bindings.SomeView.rangeSize}
  • Current Row Number
    #{bindings.SomeViewIter.rangeStart + bindings.SomeViewIter.currentRowIndexInRange + 1}
    #{bindings.SomeView.currentRowIndex + 1}

    Source:http://docs.oracle.com/html/B25947_01/bcdcpal005.htm#sthref826



ADF



  • What are commonly used keyboard shortcuts in the editor?
  • How do I write JDeveloper extensions?
  • Can I change the default IDE font size?

    • Why would I choose Subversion over CVS for my file version control system in JDeveloper?
    • What happens when I delete a workspace or project in 10.1.3?
    • The page WSIWYG design editor doesn't show my page's components, it just shows a bunch of boxes

    ADF General

    • What do I modify ADF to set dbms_application_info for the database session so DBAs can monitor performance of my application?
    • What's the difference between ADF and OAF?

    ADF Business Components

    • (This link has been lost via the removal of OraBlogs. Contact Frank Nimphius for assistance in retrieving this post)
    • Is there a better way to rollback inserts and edit changes?
    • Does ADF support Oracle Flashback queries?

    JavaServer Faces (JSF)

    • Rather than a JSF sessionScope or requestScope, how do I implement a pageScope in JSF 1.x?
    • How do I implement a progress indicator for slowing running operations?
    • What changes to ADF Faces\RC does JDeveloper's support for JSF1.2 deliver?

    ADF Faces


    • How to I create a delete record facility for each record in an ADF Table?
    • How do I populate an af:tree component programmatically?
    • Can I prevent keyboard navigation to a rendered component?
    • How to display an open file dialog and upload a file from the UI?
    • Is it possible to change the color of values in a table?

    ADF Faces Rich Client (RC)

    • How do I implement templating in ADF Faces RC?
    • How do I work with the drag and drop features in ADF Faces RC?
    • Can ADF Faces RC work with JavaScript?
    • How do I remove that annoying spinning Oracle logo?
    • How does the user's experience with ADF Faces RC differ from ADF Faces?
    • The client insists field level validation errors should stop the user from moving out of the field, how can I do this?

    Security


    • How do I reference the current user in my components/backing beans/ADF BC application module?
    • Can I use database tables for authentication?
    • Can I use database users for authentication?

    Deployment

    • What do I need to worry about when deploying my ADF application?

    Version Control


    HTTPAnalyzer


    • How do I configure JDeveloper's HTTP Analyzer?

    Caching

    • What deployment issues can caching solve?

    Product integration

    • How do I integrate technology X, Y, Z with JDeveloper or ADF?

    How to Add a Validation Rule in EO


    To add a validation rule to an entity object, use the Validation page of the Entity Object Editor, as shown in Figure 6-17. To add an attribute-level validation rule, select the attribute in the Declared Validation Rules tree, and click New.... Defining an entity-level validation rule is similar, except that you select the root entity object node in the tree before clicking New....

    Figure 6-17 Validation Page of the Entity Object Editor
    Image shows Validation Page of the Entity Object Editor

    When you add a new validation rule, the Add Validation Rule dialog appears. Use the Rule dropdown list to select the kind of validation rule you want, and configure its declarative settings using the other controls in the page. The controls will change depending on the kind of validation rule you select. Figure 6-18 illustrates what the Add Validation Rule dialog would look like when defining a range validation rule for the ProdId attribute of the ServiceRequest entity object. This validation rule has been selected to enforce that the value lie between 100 and 999 inclusive. When you add a validation rule, you also can enter an error message that will be shown to the user if the validation rule fails.

    Figure 6-18 Adding a New Range Validation Rule for the ProdId Attribute
    Image shows Add Validation Rule page for ProdId Attribute

    Using Custom ADF Page Lifecycle to Invoke an onPageLoad Backing Bean Method


    The SRDemo application contains a OnPageLoadBackingBeanBase class in the oracle.srdemo.view.util package that implements the PagePhaseListener interface described above using code like what's shown in Example 10-2. The class implements the interface's beforePhase() and afterPhase() methods so that in invokes an onPageLoad() method before the normal ADF prepare model phase, and an onPagePreRender() method after the normal ADF prepare render phase.


    Example 10-2 PagePhaseListener to Invoke an onPageLoad() and onPagePreRender() Method
    // In class oracle.srdemo.view.util.OnPageLoadBackingBeanBase
    /**
     * Before the ADF page lifecycle's prepareModel phase, invoke a
     * custom onPageLoad() method. Subclasses override the onPageLoad()
     * to do something interesting during this event.
     * @param event
     */
    public void beforePhase(PagePhaseEvent event) {
      FacesPageLifecycleContext ctx =
        (FacesPageLifecycleContext)event.getLifecycleContext();
      if (event.getPhaseId() == Lifecycle.PREPARE_MODEL_ID) {
        bc = ctx.getBindingContainer();
        onPageLoad();
        bc = null;
      }
    }
    /**
     * After the ADF page lifecycle's prepareRender phase, invoke a
     * custom onPagePreRender() method. Subclasses override the onPagePreRender()
     * to do something interesting during this event.
     * @param event
     */    
    public void afterPhase(PagePhaseEvent event) {
      FacesPageLifecycleContext ctx =
       (FacesPageLifecycleContext)event.getLifecycleContext();
      if (event.getPhaseId() == Lifecycle.PREPARE_RENDER_ID) {
        bc = ctx.getBindingContainer();
        onPagePreRender();
        bc = null;
      }
    }
    public void onPageLoad() {
      // Subclasses can override this.
    }
    public void onPagePreRender() {
      // Subclasses can override this.
    }
    
    
    If a managed bean extends the OnPageLoadBackingBeanBase class, then it can be used as an ADF page phase listener because it inherits the implementation of this interface from the base class. If that backing bean then overrides either or both of the onPageLoad() or onPagePreRender() method, that method will be invoked by the ADF Page Lifecycle at the appropriate time during the page request lifecycle.

    The last step in getting such a backing bean to work, is to tell the ADF page definition to use the backing bean as its page controller for that page. As described above, this is done by setting the ControllerClass attribute on the page definition in question to an EL expression that evaluates to the backing bean.
    The SRMain page in the SRDemo application uses the technique described in this section to illustrate writing programmatic code in the onPageLoad() method of the SRMain backing bean in the oracle.srdemo.view.backing package. Since that backing bean is named backing_SRMain in faces-config.xml, the ControllerClass property of the SRMain page's page definition is set to the EL expression "#{backing_SRMain}".

    Source: http://docs.oracle.com/html/B25947_01/bcdcpal005.htm#sthref826

    Named Bind Variable in VO

    Adding Named Bind Variables to VO:
    Image of View Object Editor for defining bind variables

    After defining the bind variables, the next step is to reference them in the SQL statement. While SQL syntax allows bind variables to appear both in the SELECT list and in the WHERE clause, you'll typically use them in the latter context, as part of your WHERE clause. You could edit the UserList view object created above, and open the SQL Statement page to introduce your named bind variables like this:
    select USER_ID, EMAIL, FIRST_NAME, LAST_NAME
    from USERS
    where (upper(FIRST_NAME) like upper(:TheName)||'%'
       or  upper(LAST_NAME)  like upper(:TheName)||'%')
      and USER_ID between :LowUserId and :HighUserId
    order by EMAIL
    
    
    Notice that you reference the bind variables in the SQL statement by prefixing their name with a colon like :TheName or :LowUserId. You can reference the bind variables in any order and repeat them as many times as needed within the SQL statement.

    Accessing Named Bind Variables Programatically:

    ViewObject vo = am.findViewObject("UserList");
    vo.setNamedWhereClauseParam("TheName","alex%");
    vo.setNamedWhereClauseParam("HighUserId", new Number(315));
    vo.executeQuery();

    How do I populate the primary key of my entity object from a database-trigger-assigned sequence value?


    Trigger-Assigned Primary Key Values from a Database Sequence

    One common case where Refresh After Insert comes into play is a primary key attribute whose value is assigned by a BEFORE INSERT FOR EACH ROW trigger. Often the trigger assigns the primary key from a database sequence using PL/SQL logic similar to this:
    CREATE OR REPLACE TRIGGER ASSIGN_SVR_ID
    BEFORE INSERT ON SERVICE_REQUESTS FOR EACH ROW
    BEGIN
     IF :NEW.SVR_ID IS NULL OR :NEW.SVR_ID < 0 THEN
       SELECT SERVICE_REQUESTS_SEQ.NEXTVAL
         INTO :NEW.SVR_ID
         FROM DUAL;
       END IF;
    END;
    
    
    Set the Attribute Type to the built-in datatype named DBSequence, as shown in Figure 6-14, and the primary key will be assigned automatically by the database sequence. Setting this datatype automatically enables the Refresh After Insert property.

    When you create a new entity row whose primary key is a DBSequence, a unique negative number gets assigned as its temporary value. This value acts as the primary key for the duration of the transaction in which it is created. If you are creating a set of interrelated entities in the same transaction, you can assign this temporary value as a foreign key value on other new, related entity rows. At transaction commit time, the entity object issues its INSERT operation using the RETURNING INTO clause to retrieve the actual database trigger-assigned primary key value. Any related new entities that previously used the temporary negative value as a foreign key will get that value updated to reflect the actual new primary key of the master.

    Note:
    As shown in Figure 6-14, you will typically also set the Updatable property of a DBSequence-valued primary key to Never. The entity object assigns the temporary ID, and then refreshes it with the actual ID value after the INSERT option. The end user never needs to update this value.


    Figure 6-14 Setting Primary Key Attribute to DBSequence Type Automates Trigger-Assigned Key Handling
    Image shows setting DBsequence type


    How can I make JDeveloper faster?

    Tip 1:
    I find at sites with aggressive network virus scanners, the speed of JDeveloper on Windows is hindered by the virus scanner inspecting all the JAR files and other files on your local machine during normal JDeveloper r/w to the filesystem. As you can appreciate a JAR file is a zipped file, so the virus scanner has to unzip the JAR to scan for viruses, which is a double speed whammy (technical term for sloooooow).

    From experience a version of McAfee disk-hog was 1 culprit, but luckily you can turn the scanner off for certain types of files (eg. JARs) or subdirectories (eg. the JDev install directory or your project directory).

    Source:http://one-size-doesnt-fit-all.blogspot.in/2007/01/making-jdeveloper-faster-another-tip.html

    Monday, April 1, 2013

    ADF Security: Enterprise Roles and Application Roles


    An enterprise role is a role that is maintained in the domain policy store (as opposed to an application policy store). Enterprise roles are available to every application deployed in the domain and defined in the domain identity store, typically represented by an ordered list of authenticators configured in the domain.

    An application role is a role used by a Fusion web application. It is specific to the application, defined by the application policy, and not necessarily known to the Java EE container. Application roles are scoped in the sense that they can contain only users and roles defined in the application. Application roles must be mapped to enterprise roles.

    You use the Users and Roles overview editor for the jazn-data.xml file to create enterprise roles to group users that you add to the identity store. You can use this mechanism to assign entire groups of users to application roles that you have defined for the purpose of conferring access rights defined by ADF security policies, as described in Section 30.6.3, "How to Associate Test Users with Application Roles."

    However, Integrated WebLogic Server does not require you to create enterprise roles to run the application within JDeveloper. For the purpose of testing the application, it may be sufficient to create a few test users and assign them directly to application roles. When you run the application in JDeveloper, the users and any enterprise roles you defined will be created in the default security provider (which is embedded LDAP for Integrated WebLogic Server).

    Typically, when you deploy the application for staging, you will migrate only the policy store to the target server. You can configure JDeveloper deployment options so that the identity store, including test users and enterprise roles, is not migrated, as described in Section 30.8.1, "How to Configure, Deploy, and Run a Secure Application in JDeveloper."

    After you deploy the secure application, Oracle Fusion Middleware will merge your application's policy store with the policies of the domain-level policy store. To complete this task, the administrator for the Oracle WebLogic Server will eventually map the application roles of your policy store to the existing domain-level enterprise roles. This application role mapping at the domain level allows enterprise users to access application resources according to the ADF security policies you have defined. The domain-level application role mapping by the administrator also allows you to develop the ADF security policies of your application without requiring any knowledge of the identity store in the production environment.
    Related Posts Plugin for WordPress, Blogger...