Wednesday, April 13, 2016

Best Practice to Iterate on Client-Side by using ADF

- How can we create an iterator in client side inside ADF?
 
we can make iterator on client side inside ADF by using <af:iterator> or <af:forecah>

- Best Practice:-
                        It is better to use the <af:iterator> instead of the <af:forEach> becaues of the following.


  • This will ensure unique IDs for the created childs.
  • <af:foreach> is not working with JSF dataModel.
  • <af:foreach> cannot be bound bound to EL expressions that use component-managed EL variables (such as the "var" variable on an <af:table>.
  • As the forEach tag is a replacement for the JSTL <c:forEach> tag, it is advisable and easier to go for the af:iterator in most of the cases for a safer ADF support.
  • The forEach tag should be used with intent and knowledge. The forEach tag is not used in JSF for iteration, but instead for generating multiple components. If your goal is to iterate over a collection of objects and render HTML for each item, <af:iterator> should be using instead.


References:-

    http://adfdiary.blogspot.com.eg/2014/03/difference-between-afforeach-and.html



Best Regards

Mohamed Fathy

Sunday, February 14, 2016

Access Managed Bean From Another One


Best Practice :-

Managed bean after running will loaded in web container into your application or web server as an object and if any request came to it, application server will get an instance from it and load that instance in memory and give you chance to use all operations inside it.
During our implementation if you need any variable from another managed bean to use it in current bean you cannot create an object from it as it not a best practice to access the managed bean, as best practice say "Only One Object be Loaded and many instances can be taken from it", so ADF and JSF provide a way to access say Session bean with out create an Object from it.
As you only will create a reference to loaded object inside application server and then you can get any data you need, so that we will have one object and many references refer on it.

Source Code:-


      loginOperations ob = (loginOperations)ADFContext.getCurrent().getScope("sessionScope").get("loginOperations");

                
String errorPath = ob.getFromPath(); 



Best Regards

Mohamed Fathy




Saturday, February 13, 2016

What Is Facelets

Facelets is a powerful but lightweight page declaration language that is used to build JavaServer Faces views using HTML style templates and to build component trees. Facelets features include the following:

  • Use of XHTML for creating web pages
  • Support for Facelets tag libraries in addition to JavaServer Faces and JSTL tag libraries
  • Support for the Expression Language (EL)
  • Templating for components and pages

Advantages of Facelets for large-scale development projects include the following:

  • Support for code reuse through templating and composite components
  • Functional extensibility of components and other server-side objects through customization
  • Faster compilation time
  • Compile-time EL validation
  • High-performance rendering

In short, the use of Facelets reduces the time and effort that needs to be spent on development and deployment.

Best Regards

Mohamed Fathy

JSPX VS JSF View Page Extenstion

.jspx page is JSP/XML representation, it is standalone page means it can run without any supporting or base page. Jdeveloper 11g Release1 supports .jspx page but this is not in Jdeveloper 11g Release2, Release2 supports Facelets means .jsf.

.jsf Vs .jspx

1.  jspx is by convention, a JSP/XML representation, whereas .jsf is by convention a facelets representation. Neither is "more compatible," but Facelets is the recommended way forward, as long as you are on 11.1.2 or later.
2.    11.1.2.x uses .jsf as default (for Facelets) where as 11.1.1.x uses .jspx
3.    Usually Facelets is considered to be of better performance because it is tighter integrated with the JSf lifcycle and doesn't need to be compiled before running it
4.    JSPX documents and Facelets are bot supported with JDeveloper 11g R2 and we do support them equallly in functionality (very little differences exist on both sides)

5.    JSPX documents are the only choice in JDeveloper 11g R1

References:-


http://adftoday.blogspot.com/2013/09/adf-ui-jspx-vs-jsf-view-page-extenstion.html

https://community.oracle.com/thread/2325794?tstart=0


Best Regards
Mohamed Fathy


How to add Commit operation on Operations of View Object

javax.faces.el.EvaluationException: java.lang.NullPointerException
at org.apache.myfaces.trinidad.component.MethodExpressionMethodBinding.invoke(MethodExpressionMethodBinding.java:51)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
at org.apache.myfaces.trinidad.component.UIXCommand.broadcast(UIXCommand.java:190)
at org.apache.myfaces.trinidad.component.UIXCollection.broadcast(UIXCollection.java:148)
at org.apache.myfaces.trinidad.component.UIXTable.broadcast(UIXTable.java:279)
at oracle.adf.view.rich.component.UIXTable.broadcast(UIXTable.java:145)
at oracle.adf.view.rich.component.rich.data.RichTable.broadcast(RichTable.java:402)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:475)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:756)
at oracle.adfinternal.view.faces.lifecycle.LifecycleImpl._invokeApplication(LifecycleImpl.java:889)
at oracle.adfinternal.view.faces.lifecycle.LifecycleImpl._executePhase(LifecycleImpl.java:379)
at oracle.adfinternal.view.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:194)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:265)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:300)
at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at oracle.adf.model.servlet.ADFBindingFilter.doFilter(ADFBindingFilter.java:205)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at oracle.adfinternal.view.faces.webapp.rich.RegistrationFilter.doFilter(RegistrationFilter.java:106)
at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl$FilterListChain.doFilter(TrinidadFilterImpl.java:446)
at oracle.adfinternal.view.faces.activedata.AdsFilter.doFilter(AdsFilter.java:60)
at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl$FilterListChain.doFilter(TrinidadFilterImpl.java:446)
at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl._doFilterImpl(TrinidadFilterImpl.java:271)
at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl.doFilter(TrinidadFilterImpl.java:177)
at org.apache.myfaces.trinidad.webapp.TrinidadFilter.doFilter(TrinidadFilter.java:92)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at oracle.security.jps.ee.http.JpsAbsFilter$1.run(JpsAbsFilter.java:119)
at java.security.AccessController.doPrivileged(Native Method)
at oracle.security.jps.util.JpsSubject.doAsPrivileged(JpsSubject.java:315)
at oracle.security.jps.ee.util.JpsPlatformUtil.runJaasMode(JpsPlatformUtil.java:442)
at oracle.security.jps.ee.http.JpsAbsFilter.runJaasMode(JpsAbsFilter.java:103)
at oracle.security.jps.ee.http.JpsAbsFilter.doFilter(JpsAbsFilter.java:171)
at oracle.security.jps.ee.http.JpsFilter.doFilter(JpsFilter.java:71)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at oracle.dms.servlet.DMSServletFilter.doFilter(DMSServletFilter.java:139)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at weblogic.servlet.internal.RequestEventsFilter.doFilter(RequestEventsFilter.java:27)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3715)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3681)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2277)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2183)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1454)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:209)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:178)
Caused By: java.lang.NullPointerException
at beans.EmployeeOperations.delete(EmployeeOperations.java:46)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.sun.el.parser.AstValue.invoke(Unknown Source)
at com.sun.el.MethodExpressionImpl.invoke(Unknown Source)
at org.apache.myfaces.trinidad.component.MethodExpressionMethodBinding.invoke(MethodExpressionMethodBinding.java:46)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
at org.apache.myfaces.trinidad.component.UIXCommand.broadcast(UIXCommand.java:190)
at org.apache.myfaces.trinidad.component.UIXCollection.broadcast(UIXCollection.java:148)
at org.apache.myfaces.trinidad.component.UIXTable.broadcast(UIXTable.java:279)
at oracle.adf.view.rich.component.UIXTable.broadcast(UIXTable.java:145)
at oracle.adf.view.rich.component.rich.data.RichTable.broadcast(RichTable.java:402)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:475)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:756)
at oracle.adfinternal.view.faces.lifecycle.LifecycleImpl._invokeApplication(LifecycleImpl.java:889)
at oracle.adfinternal.view.faces.lifecycle.LifecycleImpl._executePhase(LifecycleImpl.java:379)
at oracle.adfinternal.view.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:194)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:265)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:300)
at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at oracle.adf.model.servlet.ADFBindingFilter.doFilter(ADFBindingFilter.java:205)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at oracle.adfinternal.view.faces.webapp.rich.RegistrationFilter.doFilter(RegistrationFilter.java:106)
at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl$FilterListChain.doFilter(TrinidadFilterImpl.java:446)
at oracle.adfinternal.view.faces.activedata.AdsFilter.doFilter(AdsFilter.java:60)
at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl$FilterListChain.doFilter(TrinidadFilterImpl.java:446)
at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl._doFilterImpl(TrinidadFilterImpl.java:271)
at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl.doFilter(TrinidadFilterImpl.java:177)
at org.apache.myfaces.trinidad.webapp.TrinidadFilter.doFilter(TrinidadFilter.java:92)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at oracle.security.jps.ee.http.JpsAbsFilter$1.run(JpsAbsFilter.java:119)
at java.security.AccessController.doPrivileged(Native Method)
at oracle.security.jps.util.JpsSubject.doAsPrivileged(JpsSubject.java:315)
at oracle.security.jps.ee.util.JpsPlatformUtil.runJaasMode(JpsPlatformUtil.java:442)
at oracle.security.jps.ee.http.JpsAbsFilter.runJaasMode(JpsAbsFilter.java:103)
at oracle.security.jps.ee.http.JpsAbsFilter.doFilter(JpsAbsFilter.java:171)
at oracle.security.jps.ee.http.JpsFilter.doFilter(JpsFilter.java:71)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at oracle.dms.servlet.DMSServletFilter.doFilter(DMSServletFilter.java:139)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at weblogic.servlet.internal.RequestEventsFilter.doFilter(RequestEventsFilter.java:27)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3715)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3681)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2277)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2183)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1454)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:209)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:178)


Reason of Exception:-

you try to call specific Operation on View Object and Binding Layer cannot find it belongs to that View Object as the following

Solution:-
  • go to bindings tab in your page as the following
























  • Click add and you will get the following window


 



















  • Select action then click ok then the following window will appear as the following
























  •  Select The appropriate DataControl and Select Commit as Operation.

Best Regards
Mohamed Fathy

Tuesday, February 9, 2016

Introduction to ADF-BC

As far as ADF is concerned the main data source which is also called as the data model in generic terms is based on ADF-BC (Business components)


ADF-BC is the data model layer for ADF.ADF-BC has the following prime components.
  • The Entity objects or EO's
  • The View objects or VO's and 
  • Association's and Viewlink's.
  • The Application modules or AM's
  • The Business Component Tester
The EO/VO is similar to Object relational mapping elements like TopLink.Thanks to Steve Muench for clarifying on where TopLink stands :)

So in essence EO/VO provide a standad way of interacting with database tables and serve as the data model source.Getting into more details we have

The Entity Object

An EO represents a table in simple terms.It defines the tables attributes the data types,validation on the data,the primary keys and what not the entire business logic that needs to be defined for pushing data into the target table.

So the EO serves as the sink for data by validating it and finally storing it in to the tables.
Then we have,

The View Object

The view object in simple terms is the data source.It provides data for interacting with it.A VO can be based on EO's which in case are similar to SQL queries used to extract data,or it can be programatically populated or it can be populated with a static list.

How ever VO's based on EO's are mostly used.The view object is used to query data and serve as the data source,The EO serves as the sink.While a few validation can be done even on the VO level its better to have business logic on the EO's for reasons entitled below:

EO cache is the same for all VO's
    • When a two VO's are based on an EO both of them share the same entity cache.At run time when a VO executes a query the resultant data is split into its respective entity object records and stored in the entity cache.This helps multiple VO's to refer same set of data there by reducing memory map and also multiple validation rules for all EO's.This is similar to normalization.
For example let's say we have two EO's, a department EO and employee EO and their respective VO's are department VO which queries department information and employee VO which joins department and employee information together based on department ID.

At run time when the data is queries for an employee record lets say we queried[empname,empid,deptid,deptname] (assuming employeename and empid and deptname and deptid's are the only columns in respective tables).

Now ADF splits the employee vo record into its constituent records as [empname,empid]and [deptname,deptid] and pushes each record in to respective entity cache.This reduces memory foot print because department VO need not bring more data into memory.More over id deptname is updated then one instantly sees the same value in employee info instantly.

Thus having validation at EO level will help in providing a central point for all VO's dependent on them.It's not just data that is shared across VO's there are many more which one comes to know in future blogs.
Association and Viewlink

They define the join or the link among EO's and VO's.Association defines link between EO's.They can be considered as PrimaryKey/ForeignKey relationship between tables.
The Viewlink is for a VO.It defines the Join conditions.A viewlink can be based on an association or based on attributes,Basing viewlinks on associations have the same advantage of entity cache and few more which are unveiled later.

The Application Module

The application module packages the VO's and serves as the data control.It creates and manages the database transaction.For ADF Model layer its only Application Module which exposes the data needed by the client.So for an end user the interaction and transactional capabilities are provided by the application module.How ever there are many advanced features which i will explain as we progress.

The Business Component Tester

The mostly used component of the model layer is the tester, which is used to run and check the data model that is implemented.This serves as the first line of defense to see if data is exposed as we need it and to test the data model with out a need to create a UI.

This ends a brief introduction to ADF-BC and i will deal the rest of the topics with examples.

Best Regards
Mohamed Fathy

References:-

https://blogs.oracle.com/workingwithadf/entry/introduction_to_adf_model_layer

https://blogs.oracle.com/ArdaEralp/entry/adf_business_components

Monday, February 8, 2016

ADF View Object Collection Behavior

In ADF Application if we create browse page for VO and another page or popup for editing and create a form of the same VO, and in case redirect from browse page to edit page and we select a record it will be displayed in form?












let me say that table that will be displayed in your page is a collection of specific VO and every record inside it is object from the same specific object, in ADF that collection has it's built in iterator that used to load specific object in case we select that object so by default the iterator will display first record if we make row selection with none, and in this case the iterator will loop only one time to display all values inside the collection and then will refer to first record, so if you make redirect to any form of the same specific VO in this case it always display the first record.let me say also that in case you make row selection property with single that means the iterator will be used in many times in each time you select a record iterator will load to load it and change the reference of VO and make it refer to new object in collection


Finally I can say that ADF let it's built-in tools to manage all action with out heavy coding from developers, so it is a great framework.


Best Regards,
Mohamed Fathy