Add a method named onDeleteItem that calls the ADFUtil.invokeEL() helper method to execute the EL expression that you pass in as a parameter. In this case, it will execute a Delete and a Commit. Note that the Delete and Commit methods must be in the Page Definition Bindings for any page that uses them.
public void onDeleteItem(ActionEvent actionEvent) {
ADFUtil.invokeEL("#{bindings.Delete.execute}");
ADFUtil.invokeEL("#{bindings.Commit.execute}");
System.out.println("Deleted");
}
Register the bean as managed bean in adfc-config.xml pageflow file.In the UI, add a button from the Component Palette. Modify the text as Delete and set the ActionListener as
#{FODCommitDeleteBean.onDeleteItem}
You can also click on 'Edit' to modify the same.
Code snippet of invokeEL method in ADFUtil class
public class ADFUtil {
public static Object invokeEL(String el) {
return invokeEL(el, new Class[0], new Object[0]);
}
public static Object invokeEL(String el, Class[] paramTypes, Object[] params) {
FacesContext facesContext = FacesContext.getCurrentInstance();
ELContext elContext = facesContext.getELContext();
ExpressionFactory expressionFactory = facesContext.getApplication().getExpressionFactory();
MethodExpression exp = expressionFactory.createMethodExpression(elContext, el, Object.class, paramTypes);
return exp.invoke(elContext, params);
}
}
- FacesContext is a class that contains all of the per-request state information related to the processing of a single JSF request, and the rendering of the corresponding response. It is passed to, and potentially modified by, each phase of the request processing life cycle.
- ELContext is a class that is used to evaluate an expression.
- ExpressionFactory is a class that parses a String into a value expression or a method expression for later evaluation.
No comments:
Post a Comment