Please disable your adblock and script blockers to view this page

Search this blog

Showing posts with label Message. Show all posts
Showing posts with label Message. Show all posts

Saturday 16 March 2019

Send WhatsApp messages from Oracle ADF Application

 Hello Everyone

In this post, I am sharing a method to send WhatsApp messages from Oracle ADF Application using the "WhatsApp Click to Chat" feature as WhatsApp doesn't provide any official API.

Though it's an extremely simple way and we need not write a single line of code, We just need to pass some values in an URL to open WhatsApp Click to Chat console.

Created an ADF Application and a page in the view controller with two text fields and a button in it. It looks like this



and both fields are bonded to the managed bean variables

  1. <af:inputText label="Mobile No." id="it1" value="#{viewScope.SendWhatsAppBean.mobileNo}"
  2. autoSubmit="true"/>
  3. <af:inputText label="Message" id="it2" rows="2" value="#{viewScope.SendWhatsAppBean.message}"
  4. autoSubmit="true"/>

and managed bean just contain simple POJO variables

  1. package sendwhatsappadf.view.bean;
  2. public class SendWhatsAppBean {
  3. public SendWhatsAppBean() {
  4. }
  5. private String mobileNo;
  6. private String message;
  7. public void setMobileNo(String mobileNo) {
  8. this.mobileNo = mobileNo;
  9. }
  10. public String getMobileNo() {
  11. return mobileNo;
  12. }
  13. public void setMessage(String message) {
  14. this.message = message;
  15. }
  16. public String getMessage() {
  17. return message;
  18. }
  19. }

Next is to know about the browser-based WhatsApp click to chat feature, It makes use of an API URL

https://api.whatsapp.com/send?phone=&text=

Now on button click, we can pass phone number and text message in this URL to open click to chat console and in ADF we can do this using destination property of af:button.

  1. <af:button text="Send" id="b1" targetFrame="_blank"
  2. destination="https://api.whatsapp.com/send?phone=#{viewScope.SendWhatsAppBean.mobileNo}&amp;text=#{viewScope.SendWhatsAppBean.message}"
  3. partialTriggers="it2 it1"/>

In the above XML source, we can see that both values are passed from managed bean variables.

Now run and check the application. Enter mobile no., text message on the page

On click of the Send button, WhatsApp click to chat console is opened in a new browser window.



and this button will open the WhatsApp QR code scanner window, In that window scan QR code with your phone and start sending messages.



Using this method we can pass values from ADF bindings to WhatsApp URL and send messages from ADF application.

Cheers 🙂 Happy Learning

Tuesday 7 April 2015

Better UI -Show jQuery notification message (for error, warning, info) in Oracle ADF

Hello all,
Another post about using jQuery with ADF Faces , this post is about showing a notification message using jQuery in your ADF Application
Normally we use default FacesMesage to show error, warning and info messages in ADF

here i am using jQuery growl library , you can download files from Growl : jQuery Informative Messages Plugin

Let's see how to integrate this library with ADF Faces, you will get two files from above link
one is JavaScript file (jQuery script) and other one is CSS file (style-sheet for notification UI)



Add both files to viewController project under Web Content

now add reference of both files (JS and CSS) in page and also jQuery library to execute growl script


 <af:resource source="https://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js" type="javascript"/>
            <af:resource source="js/jquery.growl.js" type="javascript"/>
            <af:resource source="style/jquery.growl.css" type="css"/>

Now i have added 3 buttons on page to show different messages on button click and created a managed bean to define action for each button
On button click i have called jQuery script to invoke notification message
see managed bean code-


import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;

import org.apache.myfaces.trinidad.render.ExtendedRenderKitService;
import org.apache.myfaces.trinidad.util.Service;

public class ShowJqNotification {
    public ShowJqNotification() {
    }

    /**Helper method to execute javascript
     * @param script
     */
    public void calljqHelper(String script) {
        FacesContext context = FacesContext.getCurrentInstance();
        ExtendedRenderKitService erks = Service.getService(context.getRenderKit(), ExtendedRenderKitService.class);
        erks.addScript(context, script);
    }
    //Change your message as per requirement 
    /**Method to invoke Error Message
     * @param actionEvent
     */
    public void showErrMessageAction(ActionEvent actionEvent) {
        calljqHelper("$.growl.error({ message: \"Hi this is error message!\" });");

    }

    /**Method to invoke Warnign Message
     * @param actionEvent
     */
    public void showWarningMessageAction(ActionEvent actionEvent) {
        calljqHelper("$.growl.warning({ message: \"Hi this is Warning!\" });");
    }

    /**Method to invoke Info Message
     * @param actionEvent
     */
    public void showNoticeMessageAction(ActionEvent actionEvent) {
        calljqHelper("$.growl.notice({ message: \"Hi this is Notice!\" });");
    }

}

All done, now run application and check - how it looks :)


this is default look of script , you can customize it , just change some parameters in both JS and CSS files
I have changed some parameters in both files and see how it looks now

Cheers, Happy Learning :)
Sample ADF Application- Download

Read more about - Jquery and ADF Working together

Image zoom (power zoomer) effect using Jquery in ADF Faces
Show animated Image Caption using jQuery in ADF Faces
Using JQuery in Oracle ADF

Wednesday 10 September 2014

Dynamic (parameterize) model level validation using message token -Oracle ADF

Hello all
This post falls under ADF Basics category (about a little trick in model layer) but about a common development requirement
How can we create dynamic ADF BC validation ? means it takes a parameter at run time and append it to validation message

Read previous post on model level validation-
Conditional Execution of Model (EO) level Validation- Oracle ADF
ViewObject Validation rules for transient attributes (Model level validation in ADF)

In this post I am using Departments table of oracle HR Schema



  • First step is same , prepare model (EO,VO and AM) using Departments table



  • Creating a business rule that DepartmentName can not be duplicate, for this created a alternate key in EntityObject 



  • Nnow creating unique key business rule for this alternate key and message that appears on validation failure (this is how we apply EO level validations)




  • Run AM and check in BC4J tester, create a new row and on entering duplicate DepartmentName this validation message appears -"Duplicate Department Name"


  • now my requirement is this message should be like - Duplicate Department Name <Administration> , so for this i have to pass parameter in message that shows entered DepartmentName on run-time. ADF provides built in feature to pass tokens in message and on run time it is replace with groovy expression value

  •  On running see desired output



  • to pass more than one parameter just add another token and set groovy for it, see the screens
 Output-


Thanks - Happy Learning :)

Sunday 7 September 2014

Show message (Invoke FacesMessage) using JavaScript in ADF Faces

Hello all
This post is about use of JavaScript in ADF Faces to show a simple message notification , it may be error/warning/information/critical error message
so this is simple, as we have to just invoke default FacesMessage using JavaScript

So for this i have used an af:inputText on page and use case is that this field should only take characters


How to validate characters (alphabet) only  using javascript ?





So for this i have taken a simple regular expression that check that entered value is alphabetic or not
see this JavaScript function that is added to page, here it1 is the id of inputText for that FacesMessage is invoked, i am using Jspx page so i use actual id of component, if you try this in region,dynamic region or inside pageTemplate then check and change the id of component .
It will be something like r1:0:it1 or pt1:0:it1, because that is nested page structure.
you can get this id using componentBinding.getClientId();


 <af:resource type="javascript">
              function validateStringOnKeyPress(event) {
                  //Regular Expression to validate String
                  var letters = /^[A-Za-z]+$/;
                  //Get value of input text
                  var charCode = event.getSource().getSubmittedValue();

                  if (charCode != '') {
                      if (charCode.match(letters)) {
                          // IF matches then no problem
                      }
                      else {
                          //Invoke FacesMessage
                          AdfPage.PAGE.addMessage('it1', new AdfFacesMessage(AdfFacesMessage.TYPE_ERROR, "Invalid Value", "Enter Characters Only"));
                          AdfPage.PAGE.showMessages('it1');
                          event.cancel();
                      }
                  }
              }
            </af:resource>


Added a clientListener to inputText that executes this JavaScript function on keyPress event





Run page and see how it works-
Here you see that 2 is not a character so it showing error message as FacesMessage is defined for TYPE_ERROR




So it's done but now problem is - when user input a wrong value a error message is displayed and after this validation alert if user keeps entering wrong values then every time a new FacesMessage is created and added to page, It appears on page like this (duplicate messages - really weird)


To remove additional messages , i have added one more line in JavaScript to clear previous validation message

JavaScript to clear validation message-


 // Clear all validation message 
              AdfPage.PAGE.clearAllMessages();

now JavaScript function is like this


function validateStringOnKeyPress(event) {
                  //Regular Expression to validate String
                  var letters = /^[A-Za-z]+$/;
                  //Get value of input text
                  var charCode = event.getSource().getSubmittedValue();
                  // Clear all validation message 
                  AdfPage.PAGE.clearAllMessages();
                  if (charCode != '') {
                      if (charCode.match(letters)) {
                          // IF matches then no problme
                      }
                      else {
                          //Invoke FacesMessage
                          AdfPage.PAGE.addMessage('it1', new AdfFacesMessage(AdfFacesMessage.TYPE_ERROR, "Invalid Value", "Enter Characters Only"));
                          AdfPage.PAGE.showMessages('it1');
                          event.cancel();
                      }
                  }
              }

and yes you can change type of message, use TYPE_ERROR, TYPE_INFO, TYPE_WARNING, TYPE_FATAL to change message type

see different output-
Warning Message (TYPE_WARNING)-

Informational Message (TYPE_INFO)-

Fatal Error Message (TYPE_FATAL)-


Thanks Happy Learning :)

Monday 15 October 2012

ADF Basics: Show inline Message in Oracle ADF




When we use any technology sometimes we need to show an alert message or warning or confirmation.
In Oracle ADF we use Faces Message same as JSF.
In this tutorial I am showing you that how to implement inline FacesMessage .

Those who are familiar with Oracle ADF can create basic architecture of MVC.
So follow these steps

  • Create a Fusion Web Application in Jdeveloper(IDE)
  • Now in ViewController create new Page.
  • Simply drag a CommandButton from Component Palette to page
  • and Write this code on button




public void showMessageButton(ActionEvent actionEvent) {
 FacesMessage msg=new FacesMessage("This is an inline FacesMessage");
 msg.setSeverity(FacesMessage.SEVERITY_FATAL);
 FacesContext fctx=FacesContext.getCurrentInstance();
 fctx.addMessage(null, msg);
 }
  • It will work as FacesMessage
  • Now drag a af:messages component in page from Component Palette

    select af:message from component pallette

  • Select af:messages and go to property inspector and set Inline-true

    Set inline true for af:message

  • Now run your page and click on button , it will look like this

    Inline Error Message Oracle ADF

  • This is how we show inline alert in Oracle ADF