package com.mpapana.bean.util; import java.util.Map; import javax.el.ELContext; import javax.el.ExpressionFactory; import javax.el.MethodExpression; import javax.el.ValueExpression; import javax.faces.context.FacesContext; import oracle.adf.model.BindingContext; import oracle.adf.model.DataControlFrame; /** * Provides various utility methods that are handy to * have around when working with ADF. */ public class ADFUtil { /** * When a bounded task flow manages a transaction (marked as requires-transaction,. * requires-new-transaction, or requires-existing-transaction), then the * task flow must issue any commits or rollbacks that are needed. This is * essentially to keep the state of the transaction that the task flow understands * in synch with the state of the transaction in the ADFbc layer. * * Use this method to issue a commit in the middle of a task flow while staying * in the task flow. */ public static void saveAndContinue() { Map sessionMap = FacesContext.getCurrentInstance().getExternalContext().getSessionMap(); BindingContext context = (BindingContext)sessionMap.get(BindingContext.CONTEXT_ID); String currentFrameName = context.getCurrentDataControlFrame(); DataControlFrame dcFrame = context.findDataControlFrame(currentFrameName); dcFrame.commit(); dcFrame.beginTransaction(null); } /** * Programmatic evaluation of EL. * * @param el EL to evaluate * @return Result of the evaluation */ public static Object evaluateEL(String el) { FacesContext facesContext = FacesContext.getCurrentInstance(); ELContext elContext = facesContext.getELContext(); ExpressionFactory expressionFactory = facesContext.getApplication().getExpressionFactory(); ValueExpression exp = expressionFactory.createValueExpression(elContext, el, Object.class); return exp.getValue(elContext); } /** * Programmatic invocation of a method that an EL evaluates to. * The method must not take any parameters. * * @param el EL of the method to invoke * @return Object that the method returns */ public static Object invokeEL(String el) { return invokeEL(el, new Class[0], new Object[0]); } /** * Programmatic invocation of a method that an EL evaluates to. * * @param el EL of the method to invoke * @param paramTypes Array of Class defining the types of the parameters * @param params Array of Object defining the values of the parametrs * @return Object that the method returns */ 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); } /** * Sets a value into an EL object. Provides similar functionality to * the <af:setActionListener> tag, except the from is * not an EL. You can get similar behavior by using the following... * setEL(to, evaluateEL(from)) * * @param el EL object to assign a value * @param val Value to assign */ public static void setEL(String el, Object val) { FacesContext facesContext = FacesContext.getCurrentInstance(); ELContext elContext = facesContext.getELContext(); ExpressionFactory expressionFactory = facesContext.getApplication().getExpressionFactory(); ValueExpression exp = expressionFactory.createValueExpression(elContext, el, Object.class); exp.setValue(elContext, val); } }
Sample uses:
i. To evaluate an EL expression.
import com.mpapana.bean.util.ADFUtil; public class ExampleBean { public void sampleMethod() { String lookupName = (String)ADFUtil.evaluateEL("#{pageFlowScope.lookupName}"); } }
ii. To invoke a AMImpl's method added as a methodAction in pageDef file.
a) Invoking a method that takes no parameters
import com.mpapana.bean.util.ADFUtil; public class ExampleBean { public void sampleMethod(ActionEvent actionEvent) { ADFUtil.invokeEL("#{bindings.methodWithoutParams.execute}"); }
b) Invoking a method that takes parameters
import com.mpapana.bean.util.ADFUtil; public class ExampleBean { public void sampleMethod(ActionEvent actionEvent) { ADFUtil.invokeEL("#{bindings.methodWithParams.execute}", new Class[]{String.class,String.class},new Object[]{"First Param","Second Param"} ); } }
iii. To set value for an object which is in the form of EL expression.
import com.mpapana.bean.util.ADFUtil; public class ExampleBean { public void sampleMethod() { ADFUtil.setEL("#{pageFlowScope.showAttendance}","false"); } }
Thank you very much..........
ReplyDeleteHi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a Java developer learn from Java Training in Chennai. or learn thru Java Online Training in India . Nowadays Java has tons of job opportunities on various vertical industry.
DeleteGreat Article. Thank you for sharing! Really an awesome post for every one.
DeleteIEEE Final Year projects Project Centers in Chennai are consistently sought after. Final Year Students Projects take a shot at them to improve their aptitudes, while specialists like the enjoyment in interfering with innovation. For experts, it's an alternate ball game through and through. Smaller than expected IEEE Final Year project centers ground for all fragments of CSE & IT engineers hoping to assemble. Final Year Project Domains for IT It gives you tips and rules that is progressively critical to consider while choosing any final year project point.
JavaScript Training in Chennai
JavaScript Training in Chennai
Can I use this in an adf mobile app?
ReplyDeleteI like this post. Thanks for sharing.
ReplyDeleteIELTS classes in Kuwait
pandora uk
ReplyDeletevans outlet store
adidas yeezy boost 350
true religion jeans
fake rolex
cheap jordans
michael kors outlet
longchamp handbags
tiffany and co
coach outlet
air jordans
ReplyDeletelongchamp pliage
beats wireless headphones
nike outlet store online
kate spade outlet online
coach outlet online
ralph lauren outlet online
michael kors
polo ralph lauren
hollister clothing
170511yueqin
kenzo clothing
ReplyDeletecheap jordans
curry 7 shoes
yeezy boost
supreme
golden goose
kyrie shoes
steph curry shoes
supreme clothing
jordan 13
kobe byrant shoes
ReplyDeletebape
curry 8
kobe
curry
yeezy 350
kyrie 7 shoes
hermes birkin
nike x off white
lebron 18
u2i97u3x30 d7a92i0o62 k2t08h9k57 s4f44e0a62 u0d51o0v51 f5p16j1j40
ReplyDelete