Create a new entry after doing commit in ADF 13422386 1019544571447648 7687716130941590224 o1

Create a new entry after doing commit in ADF

Imagine this situation: in a call center, the phone rings, an operator creates a new entry in our web application, hangs up and the phone rings again and another new entry needs to be created. In such a case, a rapid insert of new records is wanted and it’s cumbersome to have to click the “New entry” button all the time. At the same time, updating an existing record should not create a new record on commit. Sounds familiar? Read on…

The solution to this problem lies in calling the onCreate method in JhsDataAction right after executing the onCommit method. To do so, create a Java class that extends JhsDataAction and enter a method like this:

public void onCommit(DataActionContext daContext) {
  super.onCommit(daContext);
  super.onCreate(daContext);
}

This will create a new entry everytime the commit button is clicked. Unfortunately, this will also mean that a new entry is created when an existing entry is updated. To fix this problem, check for the “createMode” request parameter. If this is set to “true”, a new entry is created and only then a new entry should be created again. This results in this code:

public void onCommit(DataActionContext daContext) {
  super.onCommit(daContext);
  if ("true".equals(daContext.getHttpServletRequest().getParameter("createMode"))) {
    super.onCreate(daContext);
  }
}