Sunday, August 15, 2010

ADF tree navigation to third level and Workaround for “ADF Tree Not Inside Container”

Step 1: Create view object based on Product table. Structure of this table is shown in Figure 1.



Figure: 1

Create view object "CategoryViewObj" based upon below query on above product table.



Figure: 2

Create view object "ProducerViewObj" based upon below query on above product table.



Figure: 3

Create view object "ProductViewObj" based upon below query on above product table.



Figure: 4

Step 2: Create view link between CategoryViewObj and ProducerViewObj using CategoryId and ProducerViewObj and ProductViewObj using ProducerCode



Figure: 5



Figure: 6

Step 3: Wrap all ViewObjects and ViewLinks in application module like below.

Drag "CategoryViewObj" under ProductAppModule and named it CategoryViewInstance. Drag the viewlink immediate below it and put it under CategoryViewInstance and renamed it to "ProducerInstance" and drag the view link immediate below of "ProducerViewObj" and put it under "ProducerInstance".




Figure: 7

Step 4: Create ADF tree table by dragging "CategoryViewInstance" from data control palate and add its two level of children by clicking green add button adjacent to it. We can select our own display attributes for each level like below.



Figure: 8



Figure: 9



Figure: 10

Modify nodestamp facet under ADF treetable component like below.



Figure: 11

Add columns like below



Figure: 12

While testing the page we face this error.


<RegistrationConfigurator><handleError> Server Exception during PPR, #1
java.lang.IllegalStateException: ADFv: Not inside a container.
at oracle.adfinternal.view.faces.model.binding.FacesCtrlHierBinding$FacesModel.exitContainer(FacesCtrlHierBinding.java:672) at oracle.adfinternal.view.faces.model.FlattenedTreeCollectionModel.getRowIndex(FlattenedTreeCollectionModel.java:109)
at oracle.adfinternal.view.faces.renderkit.rich.TreeRendererUtils$1.getRowIndex(TreeRendererUtils.java:552)
at oracle.adfinternal.view.faces.renderkit.rich.TreeTableRenderer.handleExpand(TreeTableRenderer.java:520)



This will come because we did not set any key attribute in our view objects and ADF tree table is not able to find row index. So we need to set key attributes to our view objects like below.



Figure: 13



Figure: 14



Figure: 15

While testing we get our desired output.

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>

    Sunday, June 27, 2010

    Weblogic throws "java.sql.SQLException: ORA-01005: null password given" Work Around

    After Installing Weblogic server 10.3 when I am trying to run an deployed ADF application, then AdminServer.log in $WLS_HOME/user_projects/domain/<domain_name>/Server/AdminServer/logs shows below error. The application I had deployed having all JDBC credentials but still Weblogic is not able to find proper credentials.

    note: please click on each image to get full size





    As work around I have used property (-Djps.app.credential.overwrite.allowed = true) in JAVA_PROPERTY section of setDomainEnv.sh script file in $WLS_HOME/user_projects/domain/<domain_name>/bin directory.






    After modifying Weblogic server needs to be restarted.



    And I get my desire output


    Monday, June 21, 2010

    Changing Rich Components during Runtime in ADF 11g

    In ADF sometimes you need to access Rich Components like RichInputDate, RichOutputText, RichShowDetailItem, UIGauge and many more. Not only access, we may need to change some property of those Rich components during runtime. As an example we can frame one requirement like visibility of a component depends on some Condition. More preciously in a report page if we have report layout in table format and that table will be populated using a query if inputs are feed properly to the same.


    The Query as follows
    SELECT Order_Number, Order_line_number, Order_type, Line_type, creation_date, Quantity, Price, Model_NBR
    FROM cci_order_monitor_points
    WHERE TRUNC (creation_date) BETWEEN TO_DATE (:frmdate, 'MM/DD/YYYY') AND TO_DATE (:todate, 'MM/DD/YYYY') AND
    division = :division AND
    destinationsystem = :destination AND
    monitor_ref = :ref AND
    originatingsystem = :origin



    Now in User Interface we need to have



    • one <af:commandLink> or <af:commandButton> for firing event

    • two RichInputDate one for frmdate and another for todate.

    • Other values can be feed using RichInputText or RichSelectOneChoice as per designer choice.


    When that Command Button is pressed or Command Link is clicked then its corresponding ActionListener method will execute and this is the place where we can evaluate all validation and check whether right input is feed to that query or not.
    So First of all we need to get hold of those Rich components. Select the rich component and go to it's property

    Select Binding property and edit its value by clicking the down arrow just beside of that input box.

    We can create a new Managed bean or use an existing one ; it will create one Private variable and two methods one for setter and another for getter of the same.
    In the method for that Action Listener public void actionListenerImpl(ActionEvent actionEvent) we can refer that property and create our own validation logic.

    Tuesday, June 8, 2010

    Communicating between pages in ADF 11g (11.1.1.2.0)

    In this blog what I am trying to implement is communication between two ADF pages. Here I have a main page (Figure 10) where user can click on the search icon and control shifts from that page to a dialog page (Figure 11) . And when user clicks the done button from the dialog page then selected values (here I am using Empid as an example) will come from dialog page to main page for further use. Please refer below snaps

     

    Source Page                                                          Destination Page

    Now I will show as step by step way how we can achieve it.
    Creating a view is primary one as I had already shown in my previous blog.


    Figure 1

    Figure 2
    let’s design the destination page first i.e.the page where user can select an employee and the data is returned to the “Add Project page”. From Application Module we need to select the view which is got created as Figure 2 above and drag it to the page and then we will be prompted to select a container. Here I have selected trinidad table.


    Figure 3



    Figure 4



    Figure 5



    Figure 6

    In destination page we need to add a commandlink and it’s code looks like below

    1. <f:facet name="actions">
    2. <tr:commandLink>
    3. <tr:image source="/Icons/done.png" inlineStyle="width:30px; height:27px;"/>
    4. </tr:commandLink>
    5. </f:facet>


    where entry for “tr” and “f” are as follows xmlns:f=http://java.sun.com/jsf/core and xmlns:tr=http://myfaces.apache.org/trinidad.The image I have used like this .

    Please make sure that you have included below libraries.




    Figure 7

    And Finally the page looks like



    Figure 8

    Below figure shows the code snippet of source page (Add Project) from where user is navigated to the page shown in Figure 8. After selecting the container type as ADF form (after following the step like drag and drop view objects from data control palate), we get all viewable columns as wrapped in <af:panelLabelAndMessage>. As our objective is to add a command link beside Employee id which will direct us to the destination page we need to modify default ADF panel form. Before adding the command link the code will look like as left side and after adding it will look like as right side (code shown in red color is added only for command link).



    Figure 9

    Now here comes the tricky part , when user in destination page selects a particular row and click on the "done" button on left top corner then what will happen? Till now what I have shown the code will go nowhere as there is no ActionListener defined.

    So we need to define ActionListener as follows

    • Go to Properties of <tr:commandLink > and select Property Menu for Action Listener ( ) and select edit.
    • A new dialog wizard will open. We can create a new Managed Bean and method by clicking new or we can select an existing one.

       

      Figure 12

    • We can use JSFUtils.java (download Source code from: http://www.box.net/shared/mnhtms45hm ) to get Application module reference. We need to add it in our project.
    • My customization on managed bean (download source code from : http://www.box.net/shared/u5gn9g9rz8 )is as follows


    Step 1: Getting Application Module reference :

    Please refer below link http://anindyabhattacharjee.blogspot.com/2010/06/get-application-module-reference.html

    Step 2: (ActionListener functions) Earlier we had created an attribute named "Empid" and its data source is set as <ProjectAppModuleDataControl.EmployeeViewObj1 >. Now we need to set the value of this attribute to the value specified by user.

    Step 2.1: Take value from user specified row



    1. public String getSelectedRowValue() {
    2. System.out. println ("In Set Action Listener for Search Employee"); //Getting Application Module Reference as specified in Step 1. dataControlName is set to ProjectAppModuleDataControl
    3. ProjectAppModule prjappmdl = ( ProjectAppModule )getApplicationModuleForDataControl(dataControlName); Getting selected row of EmployeeViewObj1 view.Earlier we had created the read only table based on EmployeeViewObj1 and select the "Row selection" behavior getCurrentRow() gives reference of that row.
    4. Row row = prjappmdl. findViewObject ("EmployeeViewObj1"). getCurrentRow() ; // get the Empid value from selected row.
    5. String str = row. getAttribute ("Empid"). toString() ;
    6. System.out. println ("Employee Id selected " + str);
    7. return str;}


    Step 2.2 : Set value from Step 2.1 to created Attribute. This method is used as ActionListener

    1. public void setActionListenerMethod( ActionEvent event) { //Get Selected Row value
    2. String str = getSelectedRowValue();
    3. FacesCtrlAttrsBinding attribute = null;
    4. System.out. println ("Entering ButtAction");
    5. BindingContainer bindings = BindingContext . getCurrent() . getCurrentBindingsEntry() ; // Get List of all Attributes
    6. List attr = bindings. getAttributeBindings() ; // traverse all Attributes
    7. for ( Iterator it = attr. iterator() ; it. hasNext() ; ) {
    8. Object o = it. next() ;
    9. if (o != null) {
    10. if (o instanceof FacesCtrlAttrsBinding ) { //assign object reference from list of attributes to FacesCtrlAttrsBinding
    11. attribute = (( FacesCtrlAttrsBinding )o);
    12. System.out. println ("total attribute Count: " + (attribute. getAttributeCount() ));}}}
    13. String[] attributename = attribute. getAttributeNames() ;
    14. for ( int i = 0; i < attributename. length ; i++) {
    15. System.out. println ("attribute name " + attributename[i]);
    16. if (attributename[i]. equals ("Empid")) {
    17. attribute . setInputValue (str);
    18. System.out. println ("Attribute Value " +attribute. getInputValue ()); }}}

    We have created an attribute as figure 6. Now I am using that attribute value in line 16.

    Now we need to set a ReturnActionListener method in source page.Till now what we achieve is taking the value from user selected Row in destination page, but how come the data becomes available when control comes back to the main page from destination page. For that we need to define a method in returnListener attribute at source page.
    setEmployeeID is a custom method defined in Application module Implementation class.

    1. public void searchEmployeeReturnListener(ReturnEvent retevent) {
    2. System.out.println("In Return Listener"); //Getting Return Value
    3. oracle.jbo.domain.Number retval = ( oracle.jbo.domain.Number )retevent. getReturnValue ();
    4. System.out. println ("Return Value " + retval. toString ()); //Use Returned value in main page //Getting ApplicationModule reference programatically
    5. ProjectAppModule prjappmdl = ( ProjectAppModule )getApplicationModuleForDataControl(dataControlName);
    6. prjappmdl. setEmployeeID (retval);
    }

    But please note that We need to add this method as client interface so that the method is accessible from Managed bean . In Application Module XML file we need to add this

    1. <ClientInterface>
    2. <Method Name="setEmployeeID">
    3. <Return Type="void"/>
    4. <Parameter Name="num" Type="oracle.jbo.domain.Number"/>
    5. </Method>
    6. </ClientInterface>

    Get Application Module Reference Programmatically in ADF 11.1.1.2.0

    Getting Application Module reference using datacontrol name:

    We can write this piece of code in our managed Bean. Application Module has direct visibility to view and entity so we may need to access Application Module from our user interface.We can pass data control name as string to getApplicationModuleForDataControl function

    1. public static ApplicationModule getApplicationModuleForDataControl(String name) {
    2. System.out.println("#{data." + name + ".dataProvider}");
    3. return(ApplicationModule)resolveExpression("#{data." + name + ".dataProvider}");}

    Where resolveExpression()

    is defined as
    //Argument expression is #{data.ProjectAppModuleDataControl.dataProvider} where ProjectAppModuleDataControl is data control name
    1. public static Object resolveExpression( String expression){ //A FacesContext instance is associated with a particular request at the beginning of request processing, by a call to the getFacesContext() method of the FacesContextFactory instance associated with the current web application
    2. FacesContext ctx = getFacesContext() ; //Getting Application Reference
    3. Application app = ctx. getApplication() ; //createValueBinding(String expr) converts String expr to Value Binding expression which is used to bind UI Components i.e.(data. ProjectAppModuleDataControl.dataProvider) or their values to external data source
    4. ValueBinding bind = app. createValueBinding (expression); //Getting Value from ValueBinding Expression
    5. return bind. getValue (ctx); }