I start with FacesContext class, with this class you can use to find a JSF Component, change the Locale, get the ELContext, Add a message to your view and get the ExternalContext
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// FacesContext | |
FacesContext facesCtx = FacesContext.getCurrentInstance(); | |
// find UIComponent | |
UIComponent input = facesCtx.getViewRoot().findComponent("f1"); | |
// change the locale | |
facesCtx.getViewRoot().setLocale( Locale.ENGLISH); | |
// el expression | |
Application app = facesCtx.getApplication(); | |
ExpressionFactory elFactory = app.getExpressionFactory(); | |
ELContext elContext = facesCtx.getELContext(); | |
ValueExpression valueExp = elFactory.createValueExpression(elContext, | |
"#{xxxx}", | |
Object.class); | |
Object result = valueExp.getValue(elContext); | |
// add a message | |
FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_WARN, | |
"header", | |
"detail"); | |
facesCtx.addMessage(input.getClientId(facesCtx), msg); | |
// ExternalContext | |
ExternalContext ectx = facesCtx.getExternalContext(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ExternalContext | |
ExternalContext ectx = facesCtx.getExternalContext(); | |
// all the java init parameters | |
Map<String, Object> initParamsVar = ectx.getInitParameterMap(); | |
Map<String, String> requestParamsVar = ectx.getRequestParameterMap(); | |
Map<String, Object> sessionParamsVar = ectx.getSessionMap(); | |
// web application context root | |
String contextPath = ectx.getRequestContextPath(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// AdfFacesContext | |
AdfFacesContext adfFacesCtx = AdfFacesContext.getCurrentInstance(); | |
// PPR | |
adfFacesCtx.addPartialTarget(input); | |
// get the PageFlowScope Params | |
Map<String, Object> scopePageFlowScopeVar= adfFacesCtx.getPageFlowScope(); | |
// get the viewScope Params | |
Map<String, Object> scopeViewScopeVar= adfFacesCtx.getViewScope(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ADFContext | |
ADFContext adfCtx = ADFContext.getCurrent(); | |
// Get the scope variables | |
Map<String, Object> applicationVar2 = adfCtx.getApplicationScope(); | |
Map<String, Object> pageParamsVar2 = adfCtx.getPageFlowScope(); | |
Map<String, String> requestParamsVar2 = adfCtx.getRequestScope(); | |
Map<String, Object> sessionParamsVar2 = adfCtx.getSessionScope(); | |
// el expression | |
ELContext elContext2 = adfCtx.getELContext(); | |
ExpressionFactory elFactory2 = adfCtx.getExpressionFactory(); | |
ValueExpression valueExp2 = elFactory2.createValueExpression(elContext2, | |
"#{xxxx}", | |
Object.class); | |
Object result2 = valueExp2.getValue(elContext2); | |
// Security | |
SecurityContext secCntx = adfCtx.getSecurityContext(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Security | |
SecurityContext secCntx = adfCtx.getSecurityContext(); | |
String user = secCntx.getUserName(); | |
String[] roles = secCntx.getUserRoles(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BindingContext bc = BindingContext.getCurrent(); | |
BindingContainer bcon = bc.getCurrentBindingsEntry(); | |
List<AttributeBinding> attr = bcon.getAttributeBindings(); | |
List<OperationBinding> oper = bcon.getOperationBindings(); | |
List<ControlBinding> ctrl = bcon.getControlBindings(); | |
DCBindingContainer dcbcon = (DCBindingContainer) bc.getCurrentBindingsEntry(); | |
List<AttributeBinding> attr2 = dcbcon.getAttributeBindings(); | |
List<OperationBinding> oper2 = dcbcon.getOperationBindings(); | |
List<ControlBinding> ctrl2 = dcbcon.getControlBindings(); | |
List iters = dcbcon.getIterBindingList(); | |
List exec = dcbcon.getExecutableBindings(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ControllerContext cc = ControllerContext.getInstance(); | |
// get the exception | |
Exception exp = cc.getCurrentViewPort().getExceptionData(); |
Hi Edwin,
ReplyDeleteI am making a method call to a db stored function in ADF and exposing that method as a client interface. I want to store the value returned from the method into ADFContext applicationscope. The value is later shown on all pages of the UI. Should I create a managed bean applicationscope to containing calling method code? Not sure how to achieve this functionality.
Thanks
Jacob
Hi
ReplyDeleteYou can store the method result in a sessionscope variable or in a page flow scope when it only needs to be seen in that task flow
You only need to call this method in a bean and set the result in a session or pageflowscope var.
Thanks
can we store java.util.list in pageFlowScope?
ReplyDeleteHi,
ReplyDeleteNo problem.
thanks
How can we get HttpServletRequest inside the managed bean?
ReplyDeleteHi,
Deleteyou mean this
FacesContext context = FacesContext.getCurrentInstance();
HttpServletRequest request = (HttpServletRequest)context.getExternalContext().getRequest();
thanks
Hi Edwin,
ReplyDeleteUseful post. I got a confusion here. What is the difference between following:
FacesContext.getCurrentInstance().getELContext(); and
ADFContext.getCurrent().getELContext();
AdfFacesContext.getCurrentInstance().getPageFlowScope(); and
ADFContext.getCurrent().getPageFlowScope();
I might be missing something obvious, but will be thankful if u can please make it clear or give any reference.
Thanks
Hi,
DeleteNothing, they do the same, maybe it is handy that you that you don't need to use both and maybe FacesContext can be changed in the future and the Oracle one won't be changed.
thanks
Edwin:
ReplyDeleteGreat post. Thank you.
Krishna
Edwin,
ReplyDeleteOne of useful post
It was nice article it was very useful for me as well as useful forOracle ADF learners. thanks for providing this valuable information.
ReplyDelete