Queue an action event or invoking the button action in programmatic way in JSF /ADF – Techartifact

Sometimes our requirement is to invoke the button’s action in programmatic way without needing a user to click a button,. For example we want navigation happening automatically without clicking the button by user i.e implementing navigation in programmatic way using Java.We can queue an action event . In this case the developer may drag and drop a button in the page and binds its action property to some static action outcome or to a method that returns a String, and set Visible property for the button to false. At some point the developer can invoke this button’s action by using this code.

 

FacesContext facesContext = FacesContext.getCurrentInstance();
UIViewRoot root = facesContext.getViewRoot();   
//cb1 is the fully qualified name of the button
RichCommandButton button = (RichCommandButton) root.findComponent(“cb1″); // cb1 will be id of invisible button
ActionEvent actionEvent = new ActionEvent(button);
actionEvent.queue();        // we are queuing the all action programmaticly

an another code snippet which will work in this scenario

 

        UIComponent component = null;
        FacesContext facesContext = FacesContext.getCurrentInstance();
        if (facesContext != null) {
          UIComponent root = facesContext.getViewRoot();
          component = findComponent(root, "button_id");  // button_id will be id of invisible button
        }
        
        RichCommandButton button = (RichCommandButton)component;
        ActionEvent actionEvent = new ActionEvent(button);
        actionEvent.queue();   // we are queuing the all action programmaticly

getting Attribute value from View Object column in ADF

Hi All,

When ever we want to have value of some attribute we can use below code .It work fine in managed and backing bean .
Create a java class and import

 
import oracle.adf.model.BindingContext;
import oracle.adf.model.binding.DCBindingContainer;

import oracle.adf.model.binding.DCIteratorBinding;

and using below code get value of any attribute

 
        BindingContext ctx = BindingContext.getCurrent();
        DCBindingContainer bc = (DCBindingContainer)ctx.getCurrentBindingsEntry();
        DCIteratorBinding iterator = bc.findIteratorBinding("ViewObjectIterator");
        Row r = iterator.getCurrentRow();
        String empNameValue = (String)r.getAttribute("EmpName");


prepareSession method in ADF

You can override prepareSession() in your custom Application Module class to do session-specific initializations, such as invoking a stored procedure to initialize the database state for the specific user, store user information, set application-wide configuration parameters based on the user and so on. You may extend the default implementation, as is often nessesary, in order to satisfy various pre-condtions such as user authorization etc. For example, to lock a specific view (E.g. UserView) to only show records with the users own initials (CLB in my case), the following could be done:.The framework invokes prepareSession() when the Application Module is first checked-out from the Application Module pool for a new user session.

Example:

@Override
protected void prepareSession(Session session) {

super.prepareSession(session);

// do session-specific initializations
}

For example we can write the code i.e

 
  public void prepareSession(SessionData sessionData) {
    super.prepareSession(sessionData);
    // Retrieve the J2EE user ID
    String authenticatedUser = getUserPrincipalName();

    if ((authenticatedUser != null) && 
        (authenticatedUser.trim().length() > 0)) {
      DBTransactionImpl dbTransaction = (DBTransactionImpl)getDBTransaction();
      // Parameter for database procedure
      String pApplication = "TUHRA";
      // Transaction statement with procedure call
      CallableStatement callableStmt = 
        dbTransaction.createCallableStatement(("BEGIN " + 
                                               "security_pkg.set_security_context(?, ?); " + 
                                               "END;"), 0);
      try {
        // Register parameters and call procedure
        callableStmt.setString(1, authenticatedUser);
        callableStmt.setString(2, pApplication);
        callableStmt.execute();
      } catch (SQLException sqlExcept) {
        throw new JboException(sqlExcept);
      } finally {
        try {
          if (callableStmt != null) {
            callableStmt.close();
          }
        } catch (SQLException closeExcept) {
          throw new JboException(closeExcept);
        }
      }
    }
  }