Sunday, February 24, 2013

How to use af:selectManyChoice> Component in ADF

Usecase :  How to use af:selectManyChoice component.

Implementation

Below is the sample screenshot how this component looks like. User can allowed to select more than one item.


Below is the snippet in Page fragment,  ValueChangeListener method binding is optional. this is one way of getting selected values. <f:selectItems> value can bind to any data source. In this example I have pointed to one Java class that returns list of <SelectItem>'s



This is how we can populate List of SelectItem values, I have configured this class in faces-config.xml, so that every page fragment can access these values.




Below screenshot shows how to get the selected value from <af:selectManyChoice> component by changing value on it. valueChangeEvent.getNewValue() returns selected values in form of java.util.ArrayList<Object>

Note : If you bind <f:selectItems> to List<SelectItems> , You will always get the selected item(s) key value instead of index value.












Saturday, February 23, 2013

Validate Date from Date picker in Backing bean

Subject

Sometimes we might need to validate the date that is obtained from the date picker on the ADF screen in the backing bean.

Use-case: We might need to check if the age of the person is above 20.

Solution

Step 1:  Go to the property inspector for the text field where the date picker is used
Step 2:  Make auto-submit true
Step 3:  Enable ValueChangeListner to point to a method in a managed bean, else create a method as below


Step 4:  Use the following code to do the required validation


    public void validationMethod(ValueChangeEvent valueChangeEvent) {
        try {
            Date enteredDob = (Date)valueChangeEvent.getNewValue();

            Date currentDate = new Date();
            currentDate = (Date)currentDate.getCurrentDate();
            SimpleDateFormat displayDateFormat = new SimpleDateFormat("yyyy");
            String currentYear =
                displayDateFormat.format(currentDate.dateValue());
            String enteredYear = displayDateFormat.format(enteredDob.dateValue());

            if ((Integer.parseInt(currentYear) -
                 Integer.parseInt(enteredYear)) < 18) {
                FacesContext facesContext = FacesContext.getCurrentInstance();
                FacesMessage msg =
                    new FacesMessage(FacesMessage.SEVERITY_ERROR,
                                     "Age must be above 20",
                                     "Age must be above 20");
                facesContext.addMessage(null, msg);
            }
        } catch (Exception nfe) {
            // TODO: Add catch code
            nfe.printStackTrace();
        }
    }
}


Wednesday, February 20, 2013

ADF Shortcuts

Shortcut #- Search for a specific file in a Project
Command - Ctr -(minus) , Type the class name what you are searching for.. It will list you down with all the files matching


Shortcut # - How to identify the project name & package name of a specific file which you have already opened in Jdeveloper
Command : Place the mouse cursor anywhere on the file then choose Alt + Home








Tuesday, February 19, 2013

Sunday, February 10, 2013

Weblogic start up problem -The Server Instance cannot be started because the Integrated WebLogic domain was not built successfully.



If you notice below message while starting local weblogic application server from Jdeveloper, that means, after first time installation of Jdeveloper, you haven't properly configured weblogic application server for first time run


The Server Instance cannot be started because the Integrated WebLogic domain was not built successfully. 

Solution :  Look at below instllaed directory

AppData\Roaming\JDeveloper\system11.1.1.6.38.61.92\DefaultDomain\config

and delete the most recently created config files from here, and start application server from Jdeveloper and enter correct user id, password and host name.. Wait till the domain creation process complete successfullly

Friday, February 8, 2013

How to disable UI components in ADF using ClientListener and ServerListener components in ADF Faces

This blog article explains a common usage, how to invoke a server side method upon some action performed on a client side(UI Layer)

Usecase :  Invoke a backing bean method while loading a page.

Implementation:

The sample we develop in this blog shows how to invoke a backing bean method while loading .jspx page using <af:clientListener> and <af:serverListener> components

To implement this we use java script , client & server listener components.

<af:clientListener> component invokes a java script method shown in second screen shot. This component accepts two parameters type and method. type accepts various values from the drop down like load, mouseDown, mouseUp, etc..  This component listen to the event as soon as event triggers this invoke javascript method. In this case 'load' is the event , while page loads this event triggers and invokes java script method.





Below java script method queues an event to server side. <af:serverListener> component listen to the events and as soon as serverListener receives an event it invokes a method defined in <af:serverListener>




Backing Bean method :
This method invokes as soon as after page Loads from the above <af:serverListener> property


    public void handleDisable(ClientEvent event) {
         // d1 is  top root element in jspx.
         disableControls(JSFUtils.findComponent("d1"), new Object[] { Boolean.TRUE }, Boolean.FALSE);
    }
Below method get the root element of the jspx page, and iterate through each child element and based on certain condition set disable property to 'true' or 'false'




Ref : http://tompeez.wordpress.com/tag/afclientlistener/