Showing posts with label Managed Bean. Show all posts
Showing posts with label Managed Bean. Show all posts
Sunday, 13 April 2014
Friday, 4 April 2014
ADF : af:table or adf form or adf page taking too much time to load
During the development sometimes we come across this problem. In our case we had a table on a page and it was taking too much time to load, even though there were only one row in the database table but then also it was taking more than enough time to load. After the analysing the problem finally we were able to solved the problem.
The main problem was with the List of Values with SingleSelection which was inserted in the table. In a column we had to show the name in place of the id, so the developer created a List of Values in the viewObject and put it in the table on page. At first it was working fine but later as the number of rows grown in the List of values the list started taking time to load.
The main cause was the number of rows in the list of values. Single selection list of values matches the id with the value and shows values, so inorder to map it needs all the rows, so whenever the table was being load the ListOfValues started to fetch all the rows, and as the number of rows was too much so abviously it was taking too much time. So, we had to replace the list of values but we also had to show the name in place of id.
So there are many ways to do that :
1. We can include the name that we have to display in the query of the table itself, because of which we can simply display it in a column.
2. Otherwise we have to use a viewobject with query that returns a less number of rows and better if it returns one row with the id and DisplayName.
Suppose we have to show Department Name in place of department id in Employees Table. The query will be something like this : SELECT DEPARTMENT_NAME FROM DEPARTMENTS WHERE DEPARTMENT_ID = :DeptIdBind
And then we need to show the display name so we created a transient attribute.
Then in the getter of the transient attribute, get the viewObject and pass the bindVariables and execute the query. The query will return a row and then we can fetch the name from the view object and show it by returning it.
There is a disadvantage of using this method, as the query is executed for all the rows fetched in the table. But page load problem will be solved.
This may depend on the use case. For us both worked well.
I will suggest never to use SingleSelection List of Values that contains large number of rows in the page. Not even on the adf form. Because due to that it will take too much time to load.
Thanks for reading. If you have any question, Please feel free to ask.
Labels:
#af:inputDate,
ADF,
adf table,
Af:Table,
BindingContainer,
bindings,
EnitityObject,
javascript,
JDeveloper,
list,
List Of Values,
Load time,
LOV,
Lov Opitmisation,
Managed Bean,
reducing page load time
Thursday, 3 April 2014
ADF : Alternate of Current Row Selection In af:table | Using f:attribute in ADF
Today am about to show how we can get the value of the selected row from a table without using the RowSelection property of the table.
This came to my mind when I was working on an editable table on a PopUp. And the scenario was that when the user clicks on a link or button in the table then an another table on a new popup need to be shown. The other thing was that both the tables contains large number of rows.
The problem was when we were selecting the current row in table the Framework was trying to make the selected row as current, because of which it was refreshing the table.So every time I select a row the whole table was being refreshed to set selected row as current.
So I tried out some other way to to the same.
Here is the sample Application .
I have created a Application with HR Schema with Employee and Department tables. On the page I have dropped two popUps, First for department table and second for employee table.
Drag the Department table on the popup and set rowSelection to none.
This came to my mind when I was working on an editable table on a PopUp. And the scenario was that when the user clicks on a link or button in the table then an another table on a new popup need to be shown. The other thing was that both the tables contains large number of rows.
The problem was when we were selecting the current row in table the Framework was trying to make the selected row as current, because of which it was refreshing the table.So every time I select a row the whole table was being refreshed to set selected row as current.
So I tried out some other way to to the same.
Here is the sample Application .
I have created a Application with HR Schema with Employee and Department tables. On the page I have dropped two popUps, First for department table and second for employee table.
Drag the Department table on the popup and set rowSelection to none.
Put a Command button the department table. And add an f:attribute in the commandButton and give it a name and value as department id.
Here I have used Department Id as it is the key to department table like wise you can use user primary key as key. And then you can find the row from the key.
Then on other popup drag the employee table.
In the employees table create a viewCriteria on DepartmentId.
On click on OpenEmployee button, I have used a method to get the attibute.
I have created a method setDeptIdInEmployee in AMImpl and added it to client and used in the bean. Here is the code of AMImpl.
On running the application the following page opens
Then Click on the Show Departments button
Now click on the button open Employee and the next popUp will show Employee of Selected Department. here when clicked on Sales row
I am attaching a sample application . You can download it here :TableOnPopupApp
Like wise you can use this to perform other operations too as now we have the select row.
public void openEmpACTION(ActionEvent actionEvent) { RichCommandButton ob = (RichCommandButton)actionEvent.getSource(); Integer dept = (Integer)ob.getAttributes().get("DeptId"); System.out.println("Dept id is : "+dept); OperationBinding binding = getBindings().getOperationBinding("setDeptIdInEmployee"); binding.getParamsMap().put("deptId", dept); binding.execute(); showPopup(popEmp, true); // setDeptIdInEmployee } /**Method to get Binding Container*/ public BindingContainer getBindings() { return BindingContext.getCurrent().getCurrentBindingsEntry(); }
I have created a method setDeptIdInEmployee in AMImpl and added it to client and used in the bean. Here is the code of AMImpl.
public void setDeptIdInEmployee(Integer deptId){ ViewObjectImpl employeesView1 = this.getEmployeesView1(); employeesView1.setNamedWhereClauseParam("DepartmentBind", deptId); employeesView1.executeQuery(); }
On running the application the following page opens
Then Click on the Show Departments button
Now click on the button open Employee and the next popUp will show Employee of Selected Department. here when clicked on Sales row
I am attaching a sample application . You can download it here :TableOnPopupApp
Like wise you can use this to perform other operations too as now we have the select row.
Labels:
#af:inputDate,
ADF,
adf table,
BindingContainer,
bindings,
currentRow,
EnitityObject,
f:attribute,
Groovy,
javascript,
JDeveloper,
Managed Bean,
Master Details,
popup,
Refresh,
rowSelection,
ViewObject
Bindings in ADF
Binding provides objects to link components, it is the most innovative part of ADF after Task Flows and provides direct interaction with Appication Module. We can work with bindings in ManagedBean and also in Expression Builder. Bindings are basically used for the interaction on the model and the viewController in an ADF Application.
When we drag any DataControl on page then a binding entry is made in the pageDef of the page for that particular field. Suppose we want to Use CreateInsert operation on a button clik in the page, then we have to create the binding of CreateInsert action in the pageDef on that page and then we can use this action in our ManagedBean to perform the desired operation.
Oracle ADF provides following types of bindings:
When we drag any DataControl on page then a binding entry is made in the pageDef of the page for that particular field. Suppose we want to Use CreateInsert operation on a button clik in the page, then we have to create the binding of CreateInsert action in the pageDef on that page and then we can use this action in our ManagedBean to perform the desired operation.
Oracle ADF provides following types of bindings:
- Action Binding
Action Binding is specifically defined for a button component. Provides access to operations defined by the business object. Such as CreateInsert , Delete.Likewise you can use the above code to call bindings in ManagedBean.//The code below gets the Bindings entry of the binding container and fetches the current bindings entry BindingContainer bindings = BindingContext.getCurrent().getCurrentBindingsEntry(); //Gets the opertaion bindings for the method "CreateInsert" OperationBinding operationBinding = bindings.getOperationBinding("CreateInsert"); //Then execute executes the method of the binding operationBinding.execute();
- Iterator Binding
- When we drag tables on the page in ADF then ADF creates a IteratorBinding in the pageDef of the page. The iterator binding can be used to get the iterator of the table in the ManagedBean.
- Given below is the code that can be used to get the IteratorBinding in the ManagedBean.
BindingContext btx = BindingContext.getCurrent(); DCBindingContainer dcbct = (DCBindingContainer)btx.getCurrentBindingsEntry(); DCIteratorBinding binding = dcbct.findIteratorBinding("StudentIterator"); Row currentRow = binding.getCurrentRow();
Here in the last line I have get the current Row from th iterator.LikeWise you can use it to perform desired action.- ValueBindings
Value Bindings are created in the pageDef for all the attributes that are added on the page from the dataControl.
Tuesday, 11 June 2013
ADF : Running or calling javascript from java bean
In the other post of mine I wrote about the steps to call Java method from a javascript code. Now I am gonna tell you how we can call a Javascript code from Java code. This is the easiest method I found on the internet.
- For calling Javascript you have to use the following method in the java bean :
public static void runJavaScriptCode(String javascriptCode) {
FacesContext facesCtx = FacesContext.getCurrentInstance();
ExtendedRenderKitService service =
Service.getRenderKitService(facesCtx, ExtendedRenderKitService.class);
service.addScript(facesCtx, javascriptCode);
}
You have to import the following packages :
import javax.faces.context.FacesContext;
import org.apache.myfaces.trinidad.render.ExtendedRenderKitService;
import org.apache.myfaces.trinidad.util.Service; - And to call the javsccript from the java code :
runJavaScriptCode("alert(\"My name is Java\");");
ADF : Calling Java code from JavaScript
There are occassions on which we need to call Java code that resides in the bean from the client side script i.e. Javascript. Here are the steps to do so.
- Use the given code to create a inputtext component in ADF page. You need to add a clientListener and a serverListener as given in code snippet.
<af:inputText label="Label 1" id="it1">
<af:clientListener type="keyUp" method="handleBlur"/>
<af:serverListener type="MyCustomServerEvent" method="#{DateBean.handleServerEvent}"/>
</af:inputText>
<af:resource type="javascript">
function handleBlur(evt) {
var inputTextComponent = evt.getSource();
AdfCustomEvent.queue(
inputTextComponent,
"MyCustomServerEvent",{fvalue:inputTextComponent.getSubmittedValue()},
true
);
evt.cancel();
}
</af:resource>- Here the code var
" AdfCustomEvent.queue(inputTextComponent,"MyCustomServerEvent",{fvalue:inputTextComponent.getSubmittedValue()},true); "
is like
AdfCustomEvent.queue(
Source component,
the type defined in servetlistener,
key value pair,
immediate(true or false));
- Here the code var
- Now create a class that will contain the method that is called from the javascript. Here i have named it DateBean.
And create a method as shown.
public void handleServerEvent(ClientEvent ce){
String message = (String) ce.getParameters().get("fvalue");
System.out.println(message);
} - Now run the code. The server side java method is called on onblur event on the input field.
Subscribe to:
Posts (Atom)