Disclaimer

The views expressed on this blog are my own and do not necessarily reflect the views of Oracle.

CafePress Gadget

Friday, December 30, 2011

Redirecting to a URL from a action listener in ADF 11g

Very recently I was working on implementing OaAuth flow a typical standard these days to authenticate against various social media sties like facebook, twitter etc. using my ADF app. Typically, the first step in OaAuth flow is to call to a url passing some sort of consumer or app id which then in turns after authentication invokes a callback url from your application to do the next step.

As a result, I needed a way to invoke the url from adf command button actionListener after constructing the url containing user supplied consumerKey. So, here is how you can invoke the url after that:



    FacesContext fc = FacesContext.getCurrentInstance();
    String callbackUrl = "https://www.facebook.com/dialog/oauth?client_id=" + fbClientId.getValue().toString() + "&redirect_uri=http://mycallbackURL&scope=publish_stream";
    try
    {
      fc.getExternalContext().redirect(callbackUrl);
    }
    catch (IOException e)
    {
      e.printStackTrace();
    }

So this is written in the actionListener and fbClientId is bound to a inputText on UI.


Post a Comment