Friday, July 29, 2011

ADF page refresh using java code

This post will show the code for a full page refresh. Most of the time Partial page rendering do the work, still we need a full page refresh. For this easy way is to call a java method and refresh the page. This is needed when there is a change in database values and you want to refresh the form and table after operation. 

So use following code for this:
public void refresh() {
      FacesContext facesContext = FacesContext.getCurrentInstance();
      String refreshpage = facesContext.getViewRoot().getViewId();
 ViewHandler  viewHandler =
      UIViewRoot viewroot =  viewHandler.createView( facesContext, refreshpage);

Thursday, July 7, 2011

Generate a XML file for a view object

There is a need of generating a xml file from a view object. This is a very easy process as there is a method of view object class “writeXml” to write the content of view object to a xml format.

  1. First generate Impl class for application module.
  2. Write following code to create an object of view object, and generate xml content. Then write this generated xml to a file using output stream.
public String printXml() {

        Connection conn;
        FileOutputStream out;
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        try {
            AppModuleImpl am = (AppModuleImpl)resolvEl("AppModuleDataControl");
            conn = am.getDBTransaction().createStatement(0).getConnection();
            ViewObject vo = am.findViewObject("EmployeeView");
            ((XMLNode)vo.writeXML(4, XMLInterface.XML_OPT_ALL_ROWS)).print(outputStream);
            out = new FileOutputStream("F://Employee.xml");
            PrintStream p = new PrintStream(out);

        } catch (Exception e) {
        return null;

  public Object resolvEl(String data){
    FacesContext fc = FacesContext.getCurrentInstance();
    Application app = fc.getApplication();
    ExpressionFactory elFactory = app.getExpressionFactory();
    ELContext elContext = fc.getELContext();
    ValueExpression valueExp = elFactory.createValueExpression(elContext, "#{data."+data+".dataProvider}", Object.class);
   return valueExp.getValue(elContext);

Friday, July 1, 2011

Use database table for authentication in adf security

To use sql authenticator in weblogic server security realm, read following blog post:  SQLAuthenticator

Now go to application and apply adf security. You do not need to modify the role mapping in weblogic.xml. The default is perfectly fine:

For each group in your SQLAuthenticator provider in weblogic console, create an equivalent application role in jazn.xml, and recreate those roles in the Enterprise Roles in jazn.xml. In jazn,xml make enterprise role as member of the appropriate application role. There is no need to create user in jazn.xml file. Crating role will do the work.