ADF for beginners

Saturday, 24 September 2016

Refresh the parent node on value change of the child node in adf tree table

In this post i would be providing the sample code for refreshing the parent node based on the child node.

Scenario:
In cases like when we change the values in the child node it would do some calculations and the corresponding parent row needs to get refreshed. For this we need to do ppr for the adf tree table, with out providing ppr for the entire tree table we can just refresh the parent row alone.

Below is the code for it

    public void refresh_parentrow(){
        JUCtrlHierNodeBinding parentNode = (JUCtrlHierNodeBinding)ADFUtils.evaluateEL("#{row.parent}");
        if (parentNode != null) {
            List parentKey = parentNode.getKeyPath();
            if (parentKey != null) {
                FacesContext facesContext = FacesContext.getCurrentInstance();
                RichTreeTable richTreeTable = this.getTreeTable();
                String clientRowKey = richTreeTable.getClientRowKeyManager().getClientRowKey(facesContext,
                                                                           richTreeTable,
                                                                           parentKey);
                if(clientRowKey != null) {
                String currentClientRowKey = richTreeTable.getClientRowKey();
                    try {
                        richTreeTable.setClientRowKey(clientRowKey);
                        RichInputText netWeightComp = this.getNetWeightComp();
                        AdfFacesContext afContext = AdfFacesContext.getCurrentInstance();
                        afContext.addPartialTarget(attrComp);
//attrComp - Binding of the attribute which  needs to be refreshed.
                    } finally {
                        richTreeTable.setClientRowKey(currentClientRowKey);
                    }
                }
            }
        }
    }

Soon, i will explain you in detail with sample examples and codes in the upcoming post.

Refresh the parent node on value change of the child node in adf tree table

In this post i would be providing the sample code for refreshing the parent node based on the child node.

Scenario:
In cases like when we change the values in the child node it would do some calculations and the corresponding parent row needs to get refreshed. For this we need to do ppr for the adf tree table, with out providing ppr for the entire tree table we can just refresh the parent row alone.

Below is the code for it

    public void refresh_parentrow(){
        JUCtrlHierNodeBinding parentNode = (JUCtrlHierNodeBinding)ADFUtils.evaluateEL("#{row.parent}");
        if (parentNode != null) {
            List parentKey = parentNode.getKeyPath();
            if (parentKey != null) {
                FacesContext facesContext = FacesContext.getCurrentInstance();
                RichTreeTable richTreeTable = this.getTreeTable();
                String clientRowKey = richTreeTable.getClientRowKeyManager().getClientRowKey(facesContext,
                                                                           richTreeTable,
                                                                           parentKey);
                if(clientRowKey != null) {
                String currentClientRowKey = richTreeTable.getClientRowKey();
                    try {
                        richTreeTable.setClientRowKey(clientRowKey);
                        RichInputText netWeightComp = this.getNetWeightComp();
                        AdfFacesContext afContext = AdfFacesContext.getCurrentInstance();
                        afContext.addPartialTarget(attrComp);
//attrComp - Binding of the attribute which  needs to be refreshed.
                    } finally {
                        richTreeTable.setClientRowKey(currentClientRowKey);
                    }
                }
            }
        }
    }

Soon, i will explain you in detail with sample examples and codes in the upcoming post.

Friday, 20 March 2015

Send an Email using Oracle ADF (JavaMail API)

This is a simple post to send an email in Oracle ADF.
I have used jdeveloper 11.1.1.7.0 and also used Gmail Gateway properties.
Below is the sample jsf page.


In the send button action i have coded the below method.

import java.util.Properties;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

public class SendEmail {
    private String toemail;
    private String subj;
    private String txt;
    public SendEmail() {
    }

    public String sent_action() {
        sentEmailGmail();
        return null;
    }
   
    public void sentEmailGmail() {
        // Recipient's email ID needs to be mentioned.
        String to = this.getToemail(); //change accordingly
        // Sender's email ID needs to be mentioned
        String from = "asadrina@gmail.com"; //change accordingly
        final String username = "asadrina"; //change accordingly
        final String password = "@sadrina89"; //change accordingly
        // Assuming you are sending email through relay.jangosmtp.net
        String host = "smtp.gmail.com";
        Properties props = new Properties();
        props.put("mail.smtp.auth", "true");
        props.put("mail.smtp.starttls.enable", "true");
        props.put("mail.smtp.host", host);
        props.put("mail.smtp.port", "587");
        // Get the Session object.
        Session session = Session.getInstance(props, new javax.mail.Authenticator() {
                protected PasswordAuthentication getPasswordAuthentication() {
                    return new PasswordAuthentication(username, password);
                }
            });
        try {
            // Create a default MimeMessage object.
            Message message = new MimeMessage(session);
            // Set From: header field of the header.
            message.setFrom(new InternetAddress(from));
            // Set To: header field of the header.
            message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to));
            // Set Subject: header field
            message.setSubject(this.getSubj());
            // Now set the actual message
            message.setText(this.getTxt());
            // Send message
            Transport.send(message);
            System.out.println("Sent message successfully....");
        } catch (MessagingException e) {
            throw new RuntimeException(e);
        }
    }

    public void setToemail(String toemail) {
        this.toemail = toemail;
    }

    public String getToemail() {
        return toemail;
    }

    public void setSubj(String subj) {
        this.subj = subj;
    }

    public String getSubj() {
        return subj;
    }

    public void setTxt(String txt) {
        this.txt = txt;
    }

    public String getTxt() {
        return txt;
    }
}


Now just run the page and enjoy sending the mail. No other configuration are required.

Friday, 24 October 2014

Set,List and Map in java

 In java Set, List and Map are three important interface of Java collection framework and also there are many interview questions around these.
In this post i will provide a simple difference between Set,List and Map.

List : 

It is an ordered collections and allows duplicate values.

Set

It is an unordered collections and does not allows duplicate values.

Map 

Store the datas in the form of values and keys. Each value will have the unique key.

I have provided a simple example how list,set and map works in java.


import java.util.*;
public class HelloWorld{

     public static void main(String []args){
         //Implementation of lists        
         List l = new ArrayList();
         l.add ("trivi");
         l.add ("trivi");
         Iterator it = l.iterator();
         while (it.hasNext()){
             Object o = it.next();
             System.out.println ("Iterating the list items :"+o);
         }
         System.out.println ();
        
         //Implementation of set
         Set s = new HashSet();
         s.add("triviset");
         s.add("triviset");
         s.add("triviset1");
         Iterator its = s.iterator();
         while (its.hasNext()){
             Object os = its.next();
             System.out.println ("Iterating the set items :"+os);
         }
         System.out.println ();
        
         //Implementation of Map
         Map m1= new HashMap();
         m1.put("1","trivim");
         m1.put("3","trivim");
         m1.put("3","trivim1");
         m1.put("4","trivim");
         System.out.println ("Map items are :"+m1);
         Set ms = m1.keySet();
         Iterator itm = ms.iterator();
         while (itm.hasNext()){
             Object om = itm.next();
             System.out.println ("Iterating the map :"+om);
         }
     }
}




Output obtained is :


Iterating the list items :trivi
Iterating the list items :trivi

Iterating the set items :triviset
Iterating the set items :triviset1

Map items are :{3=trivim1, 1=trivim, 4=trivim}
Iterating the map :3
Iterating the map :1
Iterating the map :4

Note :
Map cannot be iterated though it can iterated through the keyset.

Hope this might be useful. For any querries revert back to asadrina@gmail.com

Monday, 1 September 2014

Parent action activity in a task flow - Oracle ADF

The parent action activity allows an ADF bounded task flow to generate outcomes that are passed to its parent. The outcomes are used to navigate the ADF task flow containing the enclosing view'rather than navigating the ADF task flow of the ADF region.
  • Parent outcome: Specifies a value passed to the parent viewport to navigate t he enclosing view's task flow rather than navigating the region's task flow where the parent action activity is defined.

    In this post am going to show how the parent activity used to navigate from the enclosed parent view to different regions.

    STEP 1:
    I have created a task-flow-defintion-parent.xml a bounded task flow. I have dragged and dropped a view activity as parent.jsff, From parent.jsff it navigates to the taskFlowCallLocations.xml a bounded task flow and locaReadOnly.jsff. 








    STEP 2:
    Now am creating task-flow-defintion-child.xml a bounded task flow which has countries.jsff with 2 parent action activity as parentaction and parentaction1. Countries has the outcome callParent and callp

     
    STEP 3:
    Now drag and drop countries table to the countries.jsff with 2 command buttons Location ReadOnly and Location.

     
    In the parent action property set the outcome as child

     

    In the parent action1 propert set the parent outcome as child1.








     

    STEP 4:

    Now drag and drop the task-flow-defintion-child.xml to parent.jsff.

    <af:panelBox text="ParentJSFF" id="pb1">
        <f:facet name="toolbar"/>
        <af:region value="#{bindings.taskflowdefinitionchild1.regionModel}"
                   id="r1"/>
      </af:panelBox>

    STEP 5:

    Create a taskFlowCalllocations.xml with Locations.jsff and taskFlowReturn.

     
    In the locations.jsff drag and drop as locations vo as af:table with countrie as af:button so that it navigates to parent.jsff 

     
     STEP 6:

    In the LocaReadOnly.jsff which is in task-flow-definition-parent.xml bounded taskflow drag and drop Locations VO from data control as af:readonly table.

    Back af:button will be  back to parent.jsff view activity.

    STEP 7:
    Now drag and drop the task-flow-defintion-parent.jsff to the Main.jspx and run the jspx page

    Initial Page View

    Now click the location ReadOnly it will navigates to LocaReadOnly.jsff

    Click the back button to navigate the mail page now press location button it navigates to the Location.jsff page.

    Hope this post might be usefull
    Kindly revert me back if have any questions.