Problem of sorting of table created on transient VO based transient EO in ADF
Hi All,
Recently I have faced this problem like when I was clicking on the sorting icon of each column in a ADF table it was not sorting. In my case table was build based on one transient VO and the transient VO was build based on transient EO.
If the table is based on read only view object and updatable view object, it is working fine. But in case of transient VO based on transient EO it was not working unfortunately.
For those who doesn't know how to create transient EO you can refer the following link:
http://www.code4fusion.com/2013/11/creation-of-transient-entity-object.html
So I have found some work around to overcome this issue. With this approach the sorting is working perfectly.
Write the following method and lines of code in you corresponding VOImpl class and expose that method in client interface as shown below:
public void setSortByProgramatic(String sortBy){
this.setSortBy(sortBy);
this.setQueryMode(ViewObject.QUERY_MODE_SCAN_VIEW_ROWS);
this.executeQuery();
}
The VO shown below is the VO based on Transient EO.
Now drag and drop this VO on your page or fragment as table and override the sortListener property of the table as shown below:
<?xml version='1.0' encoding='UTF-8'?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1"
xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
<af:table value="#{bindings.JobsVO1.collectionModel}" var="row"
rows="#{bindings.JobsVO1.rangeSize}"
emptyText="#{bindings.JobsVO1.viewable ? 'No data to display.' : 'Access Denied.'}"
fetchSize="#{bindings.JobsVO1.rangeSize}" rowBandingInterval="0"
filterModel="#{bindings.JobsVO1Query.queryDescriptor}"
queryListener="#{bindings.JobsVO1Query.processQuery}"
filterVisible="true" varStatus="vs"
selectionListener="#{bindings.JobsVO1.collectionModel.makeCurrent}"
rowSelection="multiple" id="t1"
sortListener="#{backingBeanScope.TestBean.sortMe}"
binding="#{backingBeanScope.TestBean.testDepTable}">
<af:column sortProperty="DepartmentId"
sortable="true"
headerText="#{bindings.JobsVO1.hints.DepartmentId.label}"
id="c4">
<af:outputText value="#{row.DepartmentId}" id="ot3">
<af:convertNumber groupingUsed="false"
pattern="#{bindings.JobsVO1.hints.DepartmentId.format}"/>
</af:outputText>
</af:column>
<af:column sortProperty="EmployeeId"
sortable="true"
headerText="#{bindings.JobsVO1.hints.EmployeeId.label}" id="c3">
<af:outputText value="#{row.EmployeeId}" id="ot1">
<af:convertNumber groupingUsed="false"
pattern="#{bindings.JobsVO1.hints.EmployeeId.format}"/>
</af:outputText>
</af:column>
<af:column sortProperty="FirstName"
sortable="true"
headerText="#{bindings.JobsVO1.hints.FirstName.label}" id="c5">
<af:outputText value="#{row.FirstName}" id="ot5"/>
</af:column>
<af:column sortProperty="JobId"
sortable="true"
headerText="#{bindings.JobsVO1.hints.JobId.label}" id="c2">
<af:outputText value="#{row.JobId}" id="ot2"/>
</af:column>
<af:column sortProperty="ManagerId"
sortable="true"
headerText="#{bindings.JobsVO1.hints.ManagerId.label}" id="c1">
<af:outputText value="#{row.ManagerId}" id="ot4">
<af:convertNumber groupingUsed="false"
pattern="#{bindings.JobsVO1.hints.ManagerId.format}"/>
</af:outputText>
</af:column>
</af:table>
</jsp:root>
In bean write the following lines of the code:
import java.util.List;
import oracle.adf.model.BindingContext;
import oracle.adf.model.binding.DCBindingContainer;
import oracle.adf.view.rich.component.rich.data.RichTable;
import oracle.adf.view.rich.context.AdfFacesContext;
import oracle.binding.OperationBinding;
import org.apache.myfaces.trinidad.event.SortEvent;
import org.apache.myfaces.trinidad.model.SortCriterion;
public class TestBean {
private RichTable testDepTable;
public void sortMe(SortEvent sortEvent) {
List <SortCriterion> sortList = sortEvent.getSortCriteria();
SortCriterion sc = sortList.get(0);
boolean order = sc.isAscending();
System.out.println(sc.getProperty());
System.out.println(order);
if(order){
BindingContext bCtx = BindingContext.getCurrent();
DCBindingContainer DcCon = (DCBindingContainer)bCtx.getCurrentBindingsEntry();
OperationBinding oper = DcCon.getOperationBinding("setSortByProgramatic");
oper.getParamsMap().put("sortBy", sc.getProperty());
oper.execute();
}else{
BindingContext bCtx = BindingContext.getCurrent();
DCBindingContainer DcCon = (DCBindingContainer)bCtx.getCurrentBindingsEntry();
OperationBinding oper = DcCon.getOperationBinding("setSortByProgramatic");
oper.getParamsMap().put("sortBy", sc.getProperty()+" "+"desc");
oper.execute();
}
AdfFacesContext.getCurrentInstance().addPartialTarget(getTestDepTable());
}
public void setTestDepTable(RichTable testDepTable) {
this.testDepTable = testDepTable;
}
public RichTable getTestDepTable() {
return testDepTable;
}
}
Recently I have faced this problem like when I was clicking on the sorting icon of each column in a ADF table it was not sorting. In my case table was build based on one transient VO and the transient VO was build based on transient EO.
If the table is based on read only view object and updatable view object, it is working fine. But in case of transient VO based on transient EO it was not working unfortunately.
For those who doesn't know how to create transient EO you can refer the following link:
http://www.code4fusion.com/2013/11/creation-of-transient-entity-object.html
So I have found some work around to overcome this issue. With this approach the sorting is working perfectly.
Write the following method and lines of code in you corresponding VOImpl class and expose that method in client interface as shown below:
public void setSortByProgramatic(String sortBy){
this.setSortBy(sortBy);
this.setQueryMode(ViewObject.QUERY_MODE_SCAN_VIEW_ROWS);
this.executeQuery();
}
The VO shown below is the VO based on Transient EO.
Now drag and drop this VO on your page or fragment as table and override the sortListener property of the table as shown below:
<?xml version='1.0' encoding='UTF-8'?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1"
xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
<af:table value="#{bindings.JobsVO1.collectionModel}" var="row"
rows="#{bindings.JobsVO1.rangeSize}"
emptyText="#{bindings.JobsVO1.viewable ? 'No data to display.' : 'Access Denied.'}"
fetchSize="#{bindings.JobsVO1.rangeSize}" rowBandingInterval="0"
filterModel="#{bindings.JobsVO1Query.queryDescriptor}"
queryListener="#{bindings.JobsVO1Query.processQuery}"
filterVisible="true" varStatus="vs"
selectionListener="#{bindings.JobsVO1.collectionModel.makeCurrent}"
rowSelection="multiple" id="t1"
sortListener="#{backingBeanScope.TestBean.sortMe}"
binding="#{backingBeanScope.TestBean.testDepTable}">
<af:column sortProperty="DepartmentId"
sortable="true"
headerText="#{bindings.JobsVO1.hints.DepartmentId.label}"
id="c4">
<af:outputText value="#{row.DepartmentId}" id="ot3">
<af:convertNumber groupingUsed="false"
pattern="#{bindings.JobsVO1.hints.DepartmentId.format}"/>
</af:outputText>
</af:column>
<af:column sortProperty="EmployeeId"
sortable="true"
headerText="#{bindings.JobsVO1.hints.EmployeeId.label}" id="c3">
<af:outputText value="#{row.EmployeeId}" id="ot1">
<af:convertNumber groupingUsed="false"
pattern="#{bindings.JobsVO1.hints.EmployeeId.format}"/>
</af:outputText>
</af:column>
<af:column sortProperty="FirstName"
sortable="true"
headerText="#{bindings.JobsVO1.hints.FirstName.label}" id="c5">
<af:outputText value="#{row.FirstName}" id="ot5"/>
</af:column>
<af:column sortProperty="JobId"
sortable="true"
headerText="#{bindings.JobsVO1.hints.JobId.label}" id="c2">
<af:outputText value="#{row.JobId}" id="ot2"/>
</af:column>
<af:column sortProperty="ManagerId"
sortable="true"
headerText="#{bindings.JobsVO1.hints.ManagerId.label}" id="c1">
<af:outputText value="#{row.ManagerId}" id="ot4">
<af:convertNumber groupingUsed="false"
pattern="#{bindings.JobsVO1.hints.ManagerId.format}"/>
</af:outputText>
</af:column>
</af:table>
</jsp:root>
import java.util.List;
import oracle.adf.model.BindingContext;
import oracle.adf.model.binding.DCBindingContainer;
import oracle.adf.view.rich.component.rich.data.RichTable;
import oracle.adf.view.rich.context.AdfFacesContext;
import oracle.binding.OperationBinding;
import org.apache.myfaces.trinidad.event.SortEvent;
import org.apache.myfaces.trinidad.model.SortCriterion;
public class TestBean {
private RichTable testDepTable;
public void sortMe(SortEvent sortEvent) {
List <SortCriterion> sortList = sortEvent.getSortCriteria();
SortCriterion sc = sortList.get(0);
boolean order = sc.isAscending();
System.out.println(sc.getProperty());
System.out.println(order);
if(order){
BindingContext bCtx = BindingContext.getCurrent();
DCBindingContainer DcCon = (DCBindingContainer)bCtx.getCurrentBindingsEntry();
OperationBinding oper = DcCon.getOperationBinding("setSortByProgramatic");
oper.getParamsMap().put("sortBy", sc.getProperty());
oper.execute();
}else{
BindingContext bCtx = BindingContext.getCurrent();
DCBindingContainer DcCon = (DCBindingContainer)bCtx.getCurrentBindingsEntry();
OperationBinding oper = DcCon.getOperationBinding("setSortByProgramatic");
oper.getParamsMap().put("sortBy", sc.getProperty()+" "+"desc");
oper.execute();
}
AdfFacesContext.getCurrentInstance().addPartialTarget(getTestDepTable());
}
public void setTestDepTable(RichTable testDepTable) {
this.testDepTable = testDepTable;
}
public RichTable getTestDepTable() {
return testDepTable;
}
}
Also add the setSortByProgramatic method in pageDef of the corresponding page or fragment.
Now run the page and try to sort the column. You can see that the column is getting sorted properly.
Comments
Post a Comment