Please disable your adblock and script blockers to view this page

Search this blog

Monday, 17 September 2018

Set current date in af:inputDate on double click using javascript in ADF

This post is about a question that is asked on the OTN forum. In this post, I'll show you how we can set the current date in af:inputDate component with a double click of the mouse. For this, we need to use a simple javascript function.



Here we have an inputDate component on the page and added javascript function as a resource in the page. See page XML source

  1. <?xml version='1.0' encoding='UTF-8'?>
  2. <jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1" xmlns:f="http://java.sun.com/jsf/core"
  3. xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
  4. <jsp:directive.page contentType="text/html;charset=UTF-8"/>
  5. <f:view>
  6. <af:document title="SetCurrentDate.jspx" id="d1">
  7. <af:resource type="javascript">
  8. function setDate(evt) {
  9. var comp = evt.getSource()
  10. comp.setValue(new Date());
  11. }
  12. </af:resource>
  13. <af:form id="f1">
  14. <af:inputDate label="Label 1" id="id1">
  15. <af:clientListener method="setDate" type="dblClick"/>
  16. </af:inputDate>
  17. </af:form>
  18. </af:document>
  19. </f:view>
  20. </jsp:root>

All done, as you can see that the javascript function is called using clientListener on double click event of input date component.


Cheers ðŸ™‚ Happy Learning

R Matrices – Create , Access, Transpose, Combine Matrices in R


A Matrix is a collection of data values in 2 dimensions of the same basic data type, R creates a matrix of values using a matrix() function. 

It is similar to a vector and has one additional dimension attribute. We can check the R Matrices class using the class() function and ensure that the variable is a matrix or not.


Creating a Matrix in R

See the basic syntax for creating a matrix in R using the matrix() function.

matrix(vector,nrow,ncol,byrow)

vector- a variable of vector datatype

nrow- the number of rows in a matrix

ncol- the number of column in a matrix

byrow- a boolean value, if it is true then input vector values will be arranged by row

See this example of creating a matrix

  1. #Create a matrix using Vector
  2. test_matrix<-matrix(c(1,2,3,4,5,6), nrow=2, ncol=2,byrow= TRUE)
  3. #Print matrix on console
  4. print(test_matrix)

and output is

  1. [,1] [,2]
  2. [1,] 1 2
  3. [2,] 3 4

Accessing values of a Matrix

We can access an entire row, column or any specific value using row and column index of the matrix. See this example here to get an idea about it

  1. #Create a matrix using Vector
  2. test_matrix<-matrix(c(1,2,3,4,5,6), nrow=2, ncol=2,byrow= TRUE)
  3. #Print 1st row on console
  4. print(test_matrix[1,])
  5. #Print 2nd column on console
  6. print(test_matrix[,2])
  7. #Print 1st column of 2nd row on console
  8. print(test_matrix[2,1])

and output is like this


Performing Arithmetic Operations on R Matrices

We can perform addition, subtraction, multiplication and division on the matrices that have the same dimension. 

See this example.

  1. #Create two matrix using Vector
  2. first_matrix<-matrix(c(1,2,3,4,5,6), nrow=2, ncol=2,byrow= TRUE)
  3. sec_matrix<-matrix(c(7,8,9,10,11,12), nrow=2, ncol=2,byrow= TRUE)
  4. #First Matrix
  5. print(first_matrix)
  6. #Second Matrix
  7. print(sec_matrix)
  8. #Addition
  9. print(first_matrix + sec_matrix)
  10. #Subtraction
  11. print(first_matrix - sec_matrix)
  12. #Multiplication
  13. print(first_matrix * sec_matrix)
  14. #Division
  15. print(first_matrix / sec_matrix)

and see the output on the R console


Add a new row or column in the existing Matrix

We can add a new row using rbind() and a column using cbind() function in an existing matrix. 

See this example

  1. #Create a matrix using Vector
  2. first_matrix<-matrix(c(1,2,3,4,5,6), nrow=2, ncol=2,byrow= TRUE)
  3. #First Matrix
  4. print(first_matrix)
  5. #Adding new row in matrix
  6. v <- c(89,90,91)
  7. first_matrix <- rbind(first_matrix,v)
  8. print(first_matrix)
  9. #Adding new column in matrix
  10. v <- c(92,93,94)
  11. first_matrix <- cbind(first_matrix,v)
  12. print(first_matrix)

and output is


Combining Matrices in R

We can combine the column of two matrices that have the same number of rows using cbind() function.

  1. #Create two matrix using Vector
  2. first_matrix<-matrix(c(1,2,3,4,5,6), nrow=2, ncol=2,byrow= TRUE)
  3. sec_matrix<-matrix(c(7,8,9,10,11,12), nrow=2, ncol=2,byrow= TRUE)
  4. #First Matrix
  5. print(first_matrix)
  6. #Second Matrix
  7. print(sec_matrix)
  8. #Combining two matrices
  9. print(cbind(first_matrix,sec_matrix))

the output on R Console is


Transpose Matrix

We can create the transpose matrix of a matrix using t() function.

  1. #Create a matrix using Vector
  2. first_matrix<-matrix(c(1,2,3,4,5,6), nrow=2, ncol=2,byrow= TRUE)
  3. #First Matrix
  4. print(first_matrix)
  5. #Transpose matrix
  6. print(t(first_matrix))

The output on R Console is


Cheers ðŸ™‚ Happy Learning