Friday, 26 June 2015

ADF- Send email using Java Mail API

We will be looking in this article as how we can send mail from ADF Application. Very often we require to send mail notification in our application.

So lets see how we can do this

1.     Add this two jars in your application
·         javax.mail-1.5.0
·         commons-email-1.4

2.     Configure Mail Session on your Weblogic server


              Note: JNDI Name is required to read the properties.
              Add below properties in JavaMail Properties:
                        mail.smtp.password=yourpassword
                        mail.smtp.port=465
                        mail.smtp.user=yourmailid
                        mail.smtp.host=smtp.googlemail.com

3.     Then Add below code in your “Send Email” buttons action   

          InitialContext ic = new InitialContext();
        Session session = (Session) ic.lookup("mail/IOTMailSession");
        Properties props = session.getProperties();
        System.out.println(" PROPERTIES LIST: ");
        props.list(System.out);
        String mailhost = props.getProperty("mail.smtp.host");
        System.out.println(" mailhost = " + mailhost);
        String user = props.getProperty("mail.smtp.user");
        System.out.println(" user = " + user);
        String password = props.getProperty("mail.smtp.password");
        System.out.println(" password = " + password);
      
        Email email = new SimpleEmail();
        email.setHostName(mailhost);
        email.setSmtpPort(465);
        email.setAuthenticator(new DefaultAuthenticator(user, password));
        email.setSSLOnConnect(true);
        email.setFrom(user);
        email.setSubject("TestMail");
        email.setMsg("This is a test mail ... :-)");
        email.addTo("abc@gmail.com");

        email.send();


Hope This willbe useful
Ravi

Thursday, 18 June 2015

ADF - Total Sum of a Column in a Table

We will be looking in this article as how we can add Total of a column in a table. Very often we require to have total of a column in a table. For example , we might need total sum of Salary column in the table.
We will be leveraging power of Groovy in accomplishing this task.

So lets see how we can do this.

Use Case :- Add a Total Salary Attribute below Salary column in Employees Table.


Model Project

Considering that we have EmployeesView VO object which is based on Employees EO, go to attributes of VO and click add new attribute. Select "Add new Attribute". It will by default be transient. Give this attribute  name as TotalSal.



Now go to View Accessors tab and click on green + sign to create new View Accessor.

Select EmployeesView from the first window and shuttle it so that you can see like below.




Do ok and it should be like below screenshot.


Now go to attributes tab and select the new transient attribute (TotalSal).
Give its Default value as Expression and give Groovy expression as EmployeesView1.sum("Salary") .



View Project
Create a new page. Drag and Drop EmployeesVO from data control and create a new read only table "without" TotalSal Attribute.

Now go to Salary Column in Structure and do a right click and select footer from facet as shown below.





Now from EmployeesView1 in DataControl, drag and drop TotalSal column in this new footer facet.





Now go to bindings and create a new binding for this variable.




 And change the value of footer output text with this binding.



Save all and run this page.




Hope this was useful.

Happy Learning !!

Ravi Dolas