Wednesday, February 17, 2016

Hide Newly Created/Uncommitted Rows in ADF table

For a scenario where you want to hide the newly created table rows which are not yet committed to the database:




Suppose we have an input form which lets us add a new employee and there is a table which displays all the employees. When we add a new employee using the input form a new row also gets added into the table. We may not want to display this new row until all the fields have been entered and the new employee data has been committed to database. To avoid displaying this new row in the table:

1. Create a transient attribute in the entity object and use it to identify whether the row is new by checking its entity state


    public String getNewRow() {
        if(this.getEntityState() == Entity.STATUS_NEW){
            return "Y";
        }
        else{
            return "N";
        }
    }


2. In the table bindings check Enable Filter and use the transient attribute as a filter. Use the filter value which corresponds to non new rows



Now only the rows which are fetched from the database and are not new will be displayed on the page



<< A Request >>
  Please contribute in making this world a better place to live in by adopting a pet from your nearest pet shelter (btw cats are my favourite :-) )
<< Thank You >>

Thursday, February 11, 2016

Clear Input Components on Page Refresh - Immediate Setting Issue

It becomes challenging if you want to clear an input form as a result of page refresh, which is  caused by a command component with immediate set to 'true'. For example if you have a page in a task flow which has  an input form and there is a button on that page which again invokes the same task flow but with different parameters. So, as a result of button click you expect  the same input form to appear but do not expect any values to stay on the form fields which were entered previously, basically want it to refresh. As described in Apache Myfaces docs, if the button has immediate set to true, the component tree of the page is not refreshed. One of the ways to clear off previously entered values is to create a new View tree with the following code in the command method action :

public void refresh() {
  FacesContext context = FacesContext.getCurrentInstance();
  Application application = context.getApplication();
  ViewHandler viewHandler = application.getViewHandler();
  UIViewRoot viewRoot = viewHandler.createView(context, context
   .getViewRoot().getViewId());
  context.setViewRoot(viewRoot);
  context.renderResponse(); //Optional
}

Please refer to Apache Myfaces docs for all other ways to achieve the same .