How to create a Servlet and use it from a JSP page (ADF 10g)

Create the Servlet

  1. Right-click on the package you need it for and select New…
  2. From the new gallery select Web-Tier > Servlets on the left and on the right select HTTP Servlet
  3. Click Next and give the Servlet:
  1. Class name (ImageServlet)
  2. the Package it will reside in
  3. select doGet() method to implement
  • click Next and set the Mapping details:
    1. Name: the name to use in the application
    2. Url pattern: the url path to use in jsp pages (/somePath)
  • Finish
  • In the class, complete the method doGet() with what the servlet should do. If it is a DB query i.e.:

    We need a connection to the DB to make a tranaction…

    [java]

    public static Connection getConnection() throws Exception {

    String amDef = “bc.datamodel.common”;
    String config = “ModelNameLocal”;
    Connection con = null;
    ApplicationModule am = null;

    try {
    am = Configuration.createRootApplicationModule(amDef, config);
    con = ((DBTransactionImpl)am.getTransaction()).getPersistManagerConnection();
    } finally {
    Configuration.releaseRootApplicationModule(am, true);
    }

    return con;

    }

    [/java] (more…)

    How to add a new field to an existing View Object in ADF 10g

    Case: You need a new field on a table in the DB and need to use it on a jspx page in ADF 10g.

    After you have added the column in the relevant table in the DB, turn to the ADF application and find the relevant view you need to add the new field.

    1. Double-click on the view object in your project (View Object Editor pops-up)
    2. Select Attributes on the left pane
    3. Click New to add the new field
    4. New View Object Attributes
      • Attribute:
      • Name: a java name that’ll be used by java classes
      • Type: set the type of this field to be used in java
      • Maped to column or SQL: selected
      • Queryable: selected
      • Updatable: select “Always”
      • Query column:
      • Alias: type the name to be used by ADF Model
      • Type: set the type as set in the DB
      • Expression: type the column name as set in the DB or a relevant SQL expression for the column
    5. From the selected attributes on the View Object Editor you should now see the new attribute you just created and be set as “calculated”
    6. Rebuild the Model project and you should then have the new field available in the relevant DataControl object.

    How to add a OutputText/InputHidden field on a jspx page (ADF 10g)

    Level: Advanced
    Prerequisits: Model, DataControl and Backing-bean class

    1. Find the page you need to add the field to i.e. CreateNewEmp.jspx

    2. In the body > form of the jsp(x) page you should typically have a “panelForm” where fields are placed on, add a “panelLabelAndMessage” item:

    r-click on af:panelForm > Insert inside af:panelForm > PanelLabelAndMessage

    3. Then add an “OutputText” item (to display the field):

    r-click on af:panelLabelAndMessage > Insert inside af:panelLabelAndMessage > browse… > OutputText

    4. Switch to source-view and set a value to the item, to be able to display it:

    [javascript]<af:outputText value=”#{uploadSession.empid}”[/javascript]

    If you need to save it to a database table you need to add a “Binding” to it:

    [javascript]binding=”#{backing_app_CreateNewEmp.empid}”/>[/javascript]
    Note: if the binding doesn’t exist inside the backing bean, it will be created (a set and get method).

    The full chunk of code (.jspx):

    [javascript]<af:panelLabelAndMessage label=”Emp Id”>
    <af:outputText value=”#{uploadSession.empid}”
    binding=”#{backing_app_CreateNewEmp.empid}”/>
    </af:panelLabelAndMessage>[/javascript]

    java backing-bean (declaritively created from jsp):

    [java]public void setEmpid(CoreOutputText empid) {
    this.empid = empid;
    }

    public CoreOutputText getEmpid() {
    return empid;
    }[/java]

    To make the field hidden from user view, do the same procedure as with OutputText but use InputHidden instead. Note that you shouldn’t just change the code inside the jsp as it will not change the variables created in the backing-bean class. This depends on what you select at first when adding the new field type on the jsp page.

     

     

    how to find the java backing-bean of a jspx SQL command

    Example:
    If I have a HistoryPage.jspx has a table which displays a list of the History records. This means -whenever the Dept. creates a new Decision, it is added to the decisions table.
    If we look at the config-faces.xml diagram (User Interface > r-click > config*) we will see that HistoryPage.jspx is used in the navigation-cases and is called from-to other relational pages.
    As a procedure of ADF, HistoryDecision should probably have an XML page definition, mapped to a DataControl and possibly to some java-backup-bean. To find out:
    1. If HistoryPage.jspx has an xml definition then when r-clicked within the jspx, it should take you to this xml page. This xml should implement most importantly:
      • InvokeAction -an action to perform when called
      • Iterator -an iterator to read records based on a Data Control
    2. A table on a jspx page would access this data-collection via its ‘value’ attribute:
      • <af:table value=”#{bindings.HistoryDecision.collectionModel}”…

        This is ‘bound’ to an iterator to be able to display records. A jspx can include multiple ‘bindings’ to iterators configured in the xml page definition file. 

        Note: To create an xml PageDef, r-click on jspx. By default the xml is empty. R-click > Insert* on page-title inside Structure-pane to firstly create the bindings, executable and parameter folders. Then start creating the InvokeActions, Iterators, Tables, etc. objects.

    3. HistoryDecision in the PageDef is a table created using the HistoryDataControl, selecting attributes from available views in the data control.
      Note: A DataControl in ADF is created using a java class in: Interface > Application Sources > Java class
    4. The Iterator is bound to HistoryDecision(the table) using the HistoryDataControl (the DataControl) as:
      <iterator id=”HistoryDecisionIterator” RangeSize=”10″
      Binds=”
      HistoryDecision” DataControl=”HistoryDecisionDataControl”/>
    5. The InvokeAction is bound to a refreshSearchDefault (the method found in the relevant model view implementation)