Sunday, July 18, 2010

Display Data as Tree format using Popup in ADF

Step1: Setting up Database Objects

  • // CREATING TABLES
  • CREATE TABLE JAVATOPIC (
  • TOPICNAME VARCHAR2(150 BYTE) NOT NULL,
  • TOPICINDEX NUMBER(2)
  • )

  • CREATE TABLE JAVA_TOPIC_DETAILS (
  • TOPICINDEX NUMBER(2),
  • SUB1 VARCHAR2(50),
  • )
  • Figure 1: Datbase Details

    Step 2: Creating EntityObjects, ViewObjects, ViewLinks

    Step 2.1 Create Entity Objects (JavaTopicEntityObject, TopicDetailsEntityObject)



    Create Entity Objects for JAVATOPIC database table.

    Create Entity Objects for JAVA_TOPIC_DETAILS database table.


    Step 2.2: Create View Objects (JavaTopicEntityObjectView, TopicDetailsEntityObjectView)

    Create View object for JavaTopicEntityObject


    Figure 4: Create View for JavaTopicEntityObject

    Create view object for TopicDetailsEntityObject

    Figure 5: Create TopicDetailsEntityObjectView view object

    Step 2.3 Create ViewLink

    We can create a view link between two created views shown in step 2.2. Corresponding query will be



    Select b.sub1 from JAVATOPIC a, java_topic_details b where a.topicindex = b.topicindex and a.topicindex = :topicindex







    Step 3: Wrap ViewObjects and ViewLinks in ApplicationModule

    Step 4: Create a Popup and attach it with CommandLink

    //Step 4.1 Creating Empty Popup
    1. <af:popup id ="trainpopup"> //Add contents here </af:popup> //Step 4.2 Attach a Command Link with a PopUp
    2. <af:commandLink text ="Training Contents" binding ="#{TrainingFeedbackBean.showContent}">
    3. <af:showPopupBehavior popupId ="trainpopup" align ="afterStart"/>
    4. </af:commandLink>
    Step 5: Create Tree Binding:

    Tree Model for Source Data

    Figure 6: Create ADF Binding Tree

    Tree Model for Target Data





    1. <tree IterBinding ="JavaTopicEntityObjectView2Iterator" id ="JavaTopicEntityObjectView2"> //Parent Node Definition
    2. <nodeDefinition DefName ="com.emerson.javatraining.model.view.JavaTopicEntityObjectView" Name ="JavaTopicEntityObjectView20">
    3. <AttrNames>
    4. <Item Value ="Topicname"/>
    5. </AttrNames>
    6. <Accessors>
    7. <Item Value ="TopicDetailsEntityObjectView"/>
    8. </Accessors>
    9. </nodeDefinition> //Child Node Definition
    10. <nodeDefinition DefName = "com.emerson.javatraining.model.view.TopicDetailsEntityObjectView" Name ="JavaTopicEntityObjectView21">
    11. <AttrNames>
    12. <Item Value ="Sub1"/>
    13. </AttrNames>
    14. </nodeDefinition>
    15. </tree>


    Step 6: Use Tree Binding in Popup
    1. <af:popup id ="trainpopup">
    2. <af:dialog okVisible ="false" cancelVisible ="false">
    3. <af:panelHeader text ="Training Contents" inlineStyle ="height:379px;width:400px;">
    4. <af:tree value ="#{bindings.JavaTopicEntityObjectView2.treeModel}"
    5. var ="node" selectionListener ="#{bindings.JavaTopicEntityObjectView2.treeModel.makeCurrent}"
    6. rowSelection ="single" id ="t1" visible ="true">
    7. <f:facet name ="nodeStamp">
    8. <af:outputText value ="#{node}" id ="ot1"/>
    9. <f:facet>
    10. </af:tree>
    11. </af:panelHeader>
    12. </af:dialog>
    13. </af:popup>


    Step 7: Output:

    Figure 7: View Output



    Please try to find similarity between data displayed as child node with Java_topic_details and data displayed as Root node with javatopic database objects (refer figure 1).

    Sunday, July 4, 2010

    Updatable View and Read Only View in ADF 11.1.1.2.0

    Difference in Components


    Both Types of views have some common components like ViewAttribute and DesignTime .Updatable View uses Underlying Entity objects where as Read only view doesn't require any underlying Entity Object as it uses SQL Query. Below snap shows the difference between an Updatable view based on "ExpertiseAreas" database object and a read only view for same (ExpertiseAreas) object from its component's stand point.



    DesignTime components are common in both types of view but <Attr> is having different values.

    Updatable View

    Read Only View

    <DesignTime>

    <Attr Name="_codeGenFlag2"

    Value="Access|VarAccess"/>

    </DesignTime>

    <DesignTime>

    <Attr Name="_isExpertMode" Value="true"/>

    </DesignTime>


    Updatable View uses Underlying Entity objects where as Read only view doesn't require any underlying Entity Object as it uses SQL Query.

    Updatable View

    Read Only View

    <EntityUsage

    Name="ExpertiesAreas"

    Entity="model.ExpertiesAreas"/>


    <SQLQuery>

    <![CDATA[SELECT ExpertiesAreas.PROD_ID,

    ExpertiesAreas.USER_ID,

    ExpertiesAreas.EXPERTISE_LEVEL,

    ExpertiesAreas.NOTES

    FROM EXPERTISE_AREAS ExpertiesAreas]]>

    </SQLQuery>


    As it is a read only view it contains two attributes IsUpdateable and IsPersistent and their value is set to false. Updatable view have EntityAttrName and EntityUsage as it is dependent on underlying entity Objects to represent a column where as Read Only View is using Type, ColumnType, Expression and SQLType to represent same. Please refer below table where an Updatable View having column ProdId represents it and same thing is represented in Read Only View.

    Updatable View

    Read Only View

    <ViewAttribute

    Name="ProdId"

    IsNotNull="true"

    PrecisionRule="true"


    EntityAttrName="ProdId"

    EntityUsage="ExpertiesAreas"

    AliasName="PROD_ID">

    </ViewAttribute>

    <ViewAttribute

    Name="ProdId"

    IsNotNull="true"

    PrecisionRule="true"


    IsUpdateable="false"

    IsPersistent="false"


    Type="oracle.jbo.domain.Number"

    ColumnType="NUMBER"

    AliasName="PROD_ID"


    Expression="PROD_ID"

    SQLType="NUMERIC">

    <DesignTime>

    <Attr Name="_DisplaySize" Value="22"/>

    </DesignTime>

    </ViewAttribute>