Friday, November 24, 2017

Creating ADF Model Project as Library to be reused in other Application

The requirement here was to reuse one of the Model Project in a different ADF application. The new application needed to use few of the view objects from already created in Model project of different application. For this purpose we created ADF Library JAR of the Model project and reused in the new application.

Please refer official Oracle link for more details

Steps:

First we shall create deployment profile for the existing Model Project

1. In the Project Properties dialog, select Deployment and then click New.

2. In the Create Deployment Profile dialog, select ADF Library JAR file for Profile Type, enter a name or accept the default name for Deployment Profile Name, and click OK.

Description of Figure 50-6 follows
3. In the Applications window, right-click the project and choose Deploy > deployment, where deployment is the name of the deployment profile.

4. The Jar would be available in <Applicatio_Home>/Model/deploy


Now we need to use this library in our new project.
Steps for the same:
5. In consuming project, from the main menu, choose Tools > Manage Libraries.

6. In the Manage Libraries dialog, click Load Dir.

7. In the Load Directory dialog, select the directory where the secondary JAR files are located and click Select. This should be the same location specified in Step 4.


8. Right-click the project and select Project Properties.

9. In the Project Properties window, select Libraries and Classpath and click Add Library.

10. In the Add Library dialog, select the library, click OK and then click OK again.


After this the view objects shall be available in new appmodule of the new Model project(If not, restart the Jdeveloper).

Please post further question in comments if you have any



Thursday, March 9, 2017

Get Selected Value and Id from selectOneChoice in ADF

I must confess that every time i come across this requirement i have to google for it.
I go across 10 different links before arriving at solution.

So i am writing this post for MY FUTURE REFERENCE, so i that i can go through the post and get an answer for me!!!

Problem:

Suppose i have a LOV populated as



Lets say the value/Id combination in the lov is:
10/A
20/B
30/C


I need to find a way to get both Id and value of the selected item.


Solution:

Lets assume the af:selectOneChoice  is populated as :



 <af:selectOneChoice value="#{bindings.TypeNameList.inputValue}"
                                              label="Role Type" autoSubmit="true"
                                              required="#{bindings.TypeNameList.hints.mandatory}"
                                              shortDesc="#{bindings.TypeNameList.hints.tooltip}"
                                              id="soc3">
                            <f:selectItems value="#{bindings.TypeNameList.items}"
                                           id="si3"/>
              </af:selectOneChoice>


The following will print the Value on the jspx page as:

<af:outputText value = "Id : #{bindings.TypeNameList.attributeValue}" id="ottext2" partialTriggers="soc3"/>


<af:outputText value = "Display Value: #{bindings.TypeNameList.selectedValue ne ' ' ? bindings.TypeNameList.selectedValue.attributeValues[1] : ''}"
                                         id="ot18" partialTriggers="soc3"/>


On Backing bean if you want to fetch them, follow this:



    /**Method to get value from Expression (EL)
     * @param data
     * @return
     */
    private String getValueFrmExpression(String data) {
        FacesContext fc = FacesContext.getCurrentInstance();
        Application app = fc.getApplication();
        ExpressionFactory elFactory = app.getExpressionFactory();
        ELContext elContext = fc.getELContext();
        ValueExpression valueExp =
            elFactory.createValueExpression(elContext, data, Object.class);
        String Message = null;
        Object obj = valueExp.getValue(elContext);
        if (obj != null) {
            Message = obj.toString();
        }
        return Message;
    }


and call it as :
getValueFrmExpression("#{bindings.TypeNameList.selectedValue}")



This might be a simple problem but i come across this all the time and struggle every time to get the value