tag:blogger.com,1999:blog-83894686087152527642024-03-19T01:48:20.141-07:00Oracle ADF - Tips and TechniquesMurali Papanahttp://www.blogger.com/profile/06991064825453310705noreply@blogger.comBlogger58125tag:blogger.com,1999:blog-8389468608715252764.post-77476612666787350952012-07-27T12:40:00.000-07:002012-07-27T12:48:18.857-07:00ADF Model: Generating and using 'in' clause in VO sql statement<div dir="ltr" style="text-align: left;" trbidi="on">
We know <a href="http://www.adftips.com/2010/10/adf-model-programmatically-executing.html">how to create view criteria declartively, execute it programatically</a> and use the query results as needed. But, creating a view criteria that uses 'in' clause is not possible declaratively. So, here we'll see how to form a query criteria that uses 'in' clause and also meets the performance standards.<br />
<br />
Here, we'll see how to to form a query statement to use list of values using SQL 'in' clause.<br />
<br />
<b>Requirement:</b> For example, we have a list of employee nos and we need to form an SQL like '<i>select * from emp where empno in (empno1, empno2, empno3, and so on)</i>'. Here, we should be able to form a query that can accept 'n' (where 'n' can be dynamic) no. of employee nos and use bind variables instead of hard coded the query.<br />
<br />
<b>Solution: </b>We don't have declarative way of forming query using 'in' clause. So, we have to do it programatically.<br />
<br />
For e.g., if the Empno list has 4 employee ids, we have to form the query like<br />
<br />
<div id="iframeDivf311cdf5-4ab1-4483-9766-cf550b2c6677" style="display: none; margin: 0px;">
<iframe frameborder="0" id="iframef311cdf5-4ab1-4483-9766-cf550b2c6677" src="http://www.blogtrog.com/code.aspx?id=f311cdf5-4ab1-4483-9766-cf550b2c6677" style="border: 1px solid #e0e0e0; height: 70px; margin: 0px; width: 400px;"></iframe></div>
<div id="noIframeDivf311cdf5-4ab1-4483-9766-cf550b2c6677" style="display: block; margin: 0px;">
<pre><div>
<span style="color: blue;">select</span><span style="color: black;"> </span><span style="color: grey;">*</span><span style="color: black;"> </span><span style="color: blue;">from</span><span style="color: black;"> emp </span><span style="color: blue;">where</span><span style="color: black;"> empno </span><span style="color: grey;">in</span><span style="color: black;"> (:empno1,:empno2,:empno3,:empno4)</span></div>
</pre>
</div>
<script language="javascript" src="http://www.blogtrog.com/scripts/bt_code.js" type="text/javascript">
</script><script language="javascript" type="text/javascript">
bt_code_init('f311cdf5-4ab1-4483-9766-cf550b2c6677');
</script>
OR
<br />
<div id="iframeDived3bcf56-bbf2-49e7-96ae-5d6c1c4ce9b4" style="display: none; margin: 0px;">
<iframe frameborder="0" id="iframeed3bcf56-bbf2-49e7-96ae-5d6c1c4ce9b4" src="http://www.blogtrog.com/code.aspx?id=ed3bcf56-bbf2-49e7-96ae-5d6c1c4ce9b4" style="border: 1px solid #e0e0e0; height: 60px; margin: 0px; width: 400px;"></iframe></div>
<div id="noIframeDived3bcf56-bbf2-49e7-96ae-5d6c1c4ce9b4" style="display: block; margin: 0px;">
<pre><div>
<span style="color: blue;">select</span><span style="color: black;"> </span><span style="color: grey;">*</span><span style="color: black;"> </span><span style="color: blue;">from</span><span style="color: black;"> emp </span><span style="color: blue;">where</span><span style="color: black;"> empno </span><span style="color: grey;">in</span><span style="color: black;"> (:</span><span style="color: maroon; font-weight: bold;">1</span><span style="color: black;">,:</span><span style="color: maroon; font-weight: bold;">2</span><span style="color: black;">,:</span><span style="color: maroon; font-weight: bold;">3</span><span style="color: black;">,:</span><span style="color: maroon; font-weight: bold;">4</span><span style="color: black;">)</span></div>
</pre>
</div>
<script language="javascript" src="http://www.blogtrog.com/scripts/bt_code.js" type="text/javascript">
</script><script language="javascript" type="text/javascript">
bt_code_init('ed3bcf56-bbf2-49e7-96ae-5d6c1c4ce9b4');
</script>
<br />
In the above SQL stmts, the first one uses the named bind parameters while the second one uses positional parameters.<br />
<br />
To achieve the above requirement, generate the 'in' clause programatically using the following methods.<br />
<br />
Forming 'in' clause with named bind parameters:<br />
<div id="iframeDivfc3bdeb6-0931-425d-8b4c-2ccc558c0286" style="display: none; margin: 0px;">
<iframe frameborder="0" id="iframefc3bdeb6-0931-425d-8b4c-2ccc558c0286" src="http://www.blogtrog.com/code.aspx?id=fc3bdeb6-0931-425d-8b4c-2ccc558c0286" style="border: 1px solid #e0e0e0; height: 200px; margin: 0px; width: 400px;"></iframe></div>
<div id="noIframeDivfc3bdeb6-0931-425d-8b4c-2ccc558c0286" style="display: block; margin: 0px;">
<pre><div>
<span style="color: black;"> </span><span style="color: blue;">private</span><span style="color: black;"> String getInClauseWithParamNames(List ids) {
</span><span style="color: green;">//</span><span style="color: green;">logic to form the in clause with multiple bind variables</span><span style="color: green;">
</span><span style="color: black;"> StringBuffer inClause </span><span style="color: black;">=</span><span style="color: black;"> </span><span style="color: blue;">new</span><span style="color: black;"> StringBuffer();
</span><span style="color: blue;">for</span><span style="color: black;"> (</span><span style="color: blue;">int</span><span style="color: black;"> i </span><span style="color: black;">=</span><span style="color: black;"> </span><span style="color: black;">1</span><span style="color: black;">; i </span><span style="color: black;"><</span><span style="color: black;"> ids.size() </span><span style="color: black;">+</span><span style="color: black;"> </span><span style="color: black;">1</span><span style="color: black;">; i</span><span style="color: black;">++</span><span style="color: black;">) {
inClause.append(</span><span style="color: black;">"</span><span style="color: black;">:empno</span><span style="color: black;">"</span><span style="color: black;"> </span><span style="color: black;">+</span><span style="color: black;"> (i));
</span><span style="color: blue;">if</span><span style="color: black;"> (i </span><span style="color: black;"><</span><span style="color: black;"> ids.size()) {
inClause.append(</span><span style="color: black;">"</span><span style="color: black;">,</span><span style="color: black;">"</span><span style="color: black;">);
}
}
</span><span style="color: blue;">return</span><span style="color: black;"> inClause.toString();
}</span></div>
</pre>
</div>
<script language="javascript" src="http://www.blogtrog.com/scripts/bt_code.js" type="text/javascript">
</script><script language="javascript" type="text/javascript">
bt_code_init('fc3bdeb6-0931-425d-8b4c-2ccc558c0286');
</script>
<br />
Forming 'in' clause with positional bind parameters:
<br />
<div id="iframeDivee9d9836-7e69-4e94-8b3e-01127f4d0c20" style="display: none; margin: 0px;">
<iframe frameborder="0" id="iframeee9d9836-7e69-4e94-8b3e-01127f4d0c20" src="http://www.blogtrog.com/code.aspx?id=ee9d9836-7e69-4e94-8b3e-01127f4d0c20" style="border: 1px solid #e0e0e0; height: 200px; margin: 0px; width: 400px;"></iframe></div>
<div id="noIframeDivee9d9836-7e69-4e94-8b3e-01127f4d0c20" style="display: block; margin: 0px;">
<pre><div>
<span style="color: black;"> </span><span style="color: blue;">private</span><span style="color: black;"> String getInClause(List ids) {
</span><span style="color: green;">//</span><span style="color: green;">logic to form the in clause with multiple bind variables</span><span style="color: green;">
</span><span style="color: black;"> StringBuffer inClause </span><span style="color: black;">=</span><span style="color: black;"> </span><span style="color: blue;">new</span><span style="color: black;"> StringBuffer();
</span><span style="color: blue;">for</span><span style="color: black;"> (</span><span style="color: blue;">int</span><span style="color: black;"> i </span><span style="color: black;">=</span><span style="color: black;"> </span><span style="color: black;">1</span><span style="color: black;">; i </span><span style="color: black;"><</span><span style="color: black;"> ids.size() </span><span style="color: black;">+</span><span style="color: black;"> </span><span style="color: black;">1</span><span style="color: black;">; i</span><span style="color: black;">++</span><span style="color: black;">) {
inClause.append(</span><span style="color: black;">"</span><span style="color: black;">:</span><span style="color: black;">"</span><span style="color: black;"> </span><span style="color: black;">+</span><span style="color: black;"> (i));
</span><span style="color: blue;">if</span><span style="color: black;"> (i </span><span style="color: black;"><</span><span style="color: black;"> ids.size()) {
inClause.append(</span><span style="color: black;">"</span><span style="color: black;">,</span><span style="color: black;">"</span><span style="color: black;">);
}
}
</span><span style="color: blue;">return</span><span style="color: black;"> inClause.toString();
}</span></div>
</pre>
</div>
<script language="javascript" src="http://www.blogtrog.com/scripts/bt_code.js" type="text/javascript">
</script><script language="javascript" type="text/javascript">
bt_code_init('ee9d9836-7e69-4e94-8b3e-01127f4d0c20');
</script>
<br />
Use the generated 'in' clause with dynamic bind variables in the SQL stment and set the where clause programatically with vo.setWhereClause() method. Now, pass values for the bind variables progamatically and execute the query. <span style="background-color: white;">Sample code is given below:</span><br />
<br />
Using 'in' clause <span style="background-color: white;">with named bind parameters:</span><br />
<div id="iframeDivd97b0c0e-12e6-4352-b9fa-933695fca5ec" style="display: none; margin: 0px;">
<iframe frameborder="0" id="iframed97b0c0e-12e6-4352-b9fa-933695fca5ec" src="http://www.blogtrog.com/code.aspx?id=d97b0c0e-12e6-4352-b9fa-933695fca5ec" style="border: 1px solid #e0e0e0; height: 200px; margin: 0px; width: 400px;"></iframe></div>
<div id="noIframeDivd97b0c0e-12e6-4352-b9fa-933695fca5ec" style="display: block; margin: 0px;">
<pre><div>
<span style="color: black;"> </span><span style="color: blue;">public</span><span style="color: black;"> Row[] getEmployees1(List empIds) {
ViewObjectImpl empVO </span><span style="color: black;">=</span><span style="color: black;"> </span><span style="color: blue;">this</span><span style="color: black;">.getEmpVO();
String inClause </span><span style="color: black;">=</span><span style="color: black;"> getInClauseWithParamNames(empIds);
</span><span style="color: green;">//</span><span style="color: green;">setting the where cluase to use the generated in clause</span><span style="color: green;">
</span><span style="color: black;"> empVO.setWhereClause(</span><span style="color: black;">"</span><span style="color: black;">EmpEO.EMPNO in (</span><span style="color: black;">"</span><span style="color: black;"> </span><span style="color: black;">+</span><span style="color: black;"> inClause </span><span style="color: black;">+</span><span style="color: black;"> </span><span style="color: black;">"</span><span style="color: black;">)</span><span style="color: black;">"</span><span style="color: black;">);
</span><span style="color: green;">//</span><span style="color: green;">clearing all existing where clause params if any</span><span style="color: green;">
</span><span style="color: black;"> empVO.setWhereClauseParams(</span><span style="color: blue;">null</span><span style="color: black;">);
</span><span style="color: green;">//</span><span style="color: green;">setting values for all bind variables one by one in the in clause</span><span style="color: green;">
</span><span style="color: black;"> </span><span style="color: blue;">for</span><span style="color: black;"> (</span><span style="color: blue;">int</span><span style="color: black;"> i </span><span style="color: black;">=</span><span style="color: black;"> </span><span style="color: black;">0</span><span style="color: black;">; i </span><span style="color: black;"><</span><span style="color: black;"> empIds.size(); i</span><span style="color: black;">++</span><span style="color: black;">) {
</span><span style="color: green;">//</span><span style="color: green;">defining the named bind variables programatically</span><span style="color: green;">
</span><span style="color: black;"> empVO.defineNamedWhereClauseParam(</span><span style="color: black;">"</span><span style="color: black;">empno</span><span style="color: black;">"</span><span style="color: black;"> </span><span style="color: black;">+</span><span style="color: black;"> (i </span><span style="color: black;">+</span><span style="color: black;"> </span><span style="color: black;">1</span><span style="color: black;">), </span><span style="color: blue;">null</span><span style="color: black;">, </span><span style="color: blue;">null</span><span style="color: black;">);
</span><span style="color: green;">//</span><span style="color: green;">setting the value for each named bind variable</span><span style="color: green;">
</span><span style="color: black;"> empVO.setNamedWhereClauseParam(</span><span style="color: black;">"</span><span style="color: black;">empno</span><span style="color: black;">"</span><span style="color: black;"> </span><span style="color: black;">+</span><span style="color: black;"> (i </span><span style="color: black;">+</span><span style="color: black;"> </span><span style="color: black;">1</span><span style="color: black;">), empIds.get(i));
}
empVO.setRangeSize(</span><span style="color: black;">-</span><span style="color: black;">1</span><span style="color: black;">);
</span><span style="color: green;">//</span><span style="color: green;">executing the query</span><span style="color: green;">
</span><span style="color: black;"> empVO.executeQuery();
</span><span style="color: green;">//</span><span style="color: green;">returning the rows from query result</span><span style="color: green;">
</span><span style="color: black;"> </span><span style="color: blue;">return</span><span style="color: black;"> empVO.getAllRowsInRange();
}</span></div>
</pre>
</div>
<script language="javascript" src="http://www.blogtrog.com/scripts/bt_code.js" type="text/javascript">
</script><script language="javascript" type="text/javascript">
bt_code_init('d97b0c0e-12e6-4352-b9fa-933695fca5ec');
</script>
<br />
Using 'in' clause with positional bind parameters:<br />
<div id="iframeDiv60e3c085-30ed-4bbc-907e-8d103d3e00fe" style="display: none; margin: 0px;">
<iframe frameborder="0" id="iframe60e3c085-30ed-4bbc-907e-8d103d3e00fe" src="http://www.blogtrog.com/code.aspx?id=60e3c085-30ed-4bbc-907e-8d103d3e00fe" style="border: 1px solid #e0e0e0; height: 200px; margin: 0px; width: 400px;"></iframe></div>
<div id="noIframeDiv60e3c085-30ed-4bbc-907e-8d103d3e00fe" style="display: block; margin: 0px;">
<pre><div>
<span style="color: black;"> </span><span style="color: blue;">public</span><span style="color: black;"> Row[] getEmployees(List empIds) {
ViewObjectImpl empVO </span><span style="color: black;">=</span><span style="color: black;"> </span><span style="color: blue;">this</span><span style="color: black;">.getEmpVO();
String inClause </span><span style="color: black;">=</span><span style="color: black;"> getInClause(empIds);
</span><span style="color: green;">//</span><span style="color: green;">setting the where cluase to use the generated in clause</span><span style="color: green;">
</span><span style="color: black;"> empVO.setWhereClause(</span><span style="color: black;">"</span><span style="color: black;">EmpEO.EMPNO in (</span><span style="color: black;">"</span><span style="color: black;"> </span><span style="color: black;">+</span><span style="color: black;"> inClause </span><span style="color: black;">+</span><span style="color: black;"> </span><span style="color: black;">"</span><span style="color: black;">)</span><span style="color: black;">"</span><span style="color: black;">);
</span><span style="color: green;">//</span><span style="color: green;">clearing all existing where clause params if any</span><span style="color: green;">
</span><span style="color: black;"> empVO.setWhereClauseParams(</span><span style="color: blue;">null</span><span style="color: black;">);
</span><span style="color: green;">//</span><span style="color: green;">setting values for all bind variables one by one in the in clause</span><span style="color: green;">
</span><span style="color: black;"> </span><span style="color: blue;">for</span><span style="color: black;"> (</span><span style="color: blue;">int</span><span style="color: black;"> i </span><span style="color: black;">=</span><span style="color: black;"> </span><span style="color: black;">0</span><span style="color: black;">; i </span><span style="color: black;"><</span><span style="color: black;"> empIds.size(); i</span><span style="color: black;">++</span><span style="color: black;">) {
</span><span style="color: green;">//</span><span style="color: green;">setting the value for each positional bind variable</span><span style="color: green;">
</span><span style="color: black;"> empVO.setWhereClauseParam(i, empIds.get(i));
}
empVO.setRangeSize(</span><span style="color: black;">-</span><span style="color: black;">1</span><span style="color: black;">);
</span><span style="color: green;">//</span><span style="color: green;">executing the query</span><span style="color: green;">
</span><span style="color: black;"> empVO.executeQuery();
</span><span style="color: green;">//</span><span style="color: green;">returning the resultant rows</span><span style="color: green;">
</span><span style="color: black;"> </span><span style="color: blue;">return</span><span style="color: black;"> empVO.getAllRowsInRange();
}</span></div>
</pre>
</div>
<script language="javascript" src="http://www.blogtrog.com/scripts/bt_code.js" type="text/javascript">
</script><script language="javascript" type="text/javascript">
bt_code_init('60e3c085-30ed-4bbc-907e-8d103d3e00fe');
</script>
<br />
Sample method that forms list of empnos, calls the above methods, gets the required results and prints the results:<br />
<div id="iframeDivb1fd9f01-cee1-4d0f-bb81-1f1b4caca275" style="display: none; margin: 0px;">
<iframe frameborder="0" id="iframeb1fd9f01-cee1-4d0f-bb81-1f1b4caca275" src="http://www.blogtrog.com/code.aspx?id=b1fd9f01-cee1-4d0f-bb81-1f1b4caca275" style="border: 1px solid #e0e0e0; height: 200px; margin: 0px; width: 400px;"></iframe></div>
<div id="noIframeDivb1fd9f01-cee1-4d0f-bb81-1f1b4caca275" style="display: block; margin: 0px;">
<pre><div>
<span style="color: black;"> </span><span style="color: blue;">public</span><span style="color: black;"> </span><span style="color: blue;">void</span><span style="color: black;"> sampleMethod() {
</span><span style="color: green;">//</span><span style="color: green;">Forming a list of employee ids</span><span style="color: green;">
</span><span style="color: black;"> List</span><span style="color: black;"><</span><span style="color: black;">Long</span><span style="color: black;">></span><span style="color: black;"> empIds </span><span style="color: black;">=</span><span style="color: black;"> </span><span style="color: blue;">new</span><span style="color: black;"> ArrayList</span><span style="color: black;"><</span><span style="color: black;">Long</span><span style="color: black;">></span><span style="color: black;">();
empIds.add(</span><span style="color: blue;">new</span><span style="color: black;"> Long(</span><span style="color: black;">7499</span><span style="color: black;">));
empIds.add(</span><span style="color: blue;">new</span><span style="color: black;"> Long(</span><span style="color: black;">7521</span><span style="color: black;">));
empIds.add(</span><span style="color: blue;">new</span><span style="color: black;"> Long(</span><span style="color: black;">7566</span><span style="color: black;">));
empIds.add(</span><span style="color: blue;">new</span><span style="color: black;"> Long(</span><span style="color: black;">7654</span><span style="color: black;">));
empIds.add(</span><span style="color: blue;">new</span><span style="color: black;"> Long(</span><span style="color: black;">7698</span><span style="color: black;">));
empIds.add(</span><span style="color: blue;">new</span><span style="color: black;"> Long(</span><span style="color: black;">7788</span><span style="color: black;">));
</span><span style="color: green;">//</span><span style="color: green;">Get employee rows from list of empIds
</span><span style="color: green;">//</span><span style="color: green;">1. Using positional parameters
</span><span style="color: green;">//</span><span style="color: green;">Row[] empRows = getEmployees(empIds);
</span><span style="color: green;">//</span><span style="color: green;">2. Using named bind parameters</span><span style="color: green;">
</span><span style="color: black;"> Row[] empRows </span><span style="color: black;">=</span><span style="color: black;"> getEmployees1(empIds);
</span><span style="color: green;">//</span><span style="color: green;">iterating through the employee rows and printing the emp name</span><span style="color: green;">
</span><span style="color: black;"> </span><span style="color: blue;">for</span><span style="color: black;"> (</span><span style="color: blue;">int</span><span style="color: black;"> i </span><span style="color: black;">=</span><span style="color: black;"> </span><span style="color: black;">0</span><span style="color: black;">; i </span><span style="color: black;"><</span><span style="color: black;"> empRows.length; i</span><span style="color: black;">++</span><span style="color: black;">) {
Row empRow </span><span style="color: black;">=</span><span style="color: black;"> empRows[i];
System.out.println(</span><span style="color: black;">"</span><span style="color: black;">Emp Name </span><span style="color: black;">"</span><span style="color: black;"> </span><span style="color: black;">+</span><span style="color: black;"> (i </span><span style="color: black;">+</span><span style="color: black;"> </span><span style="color: black;">1</span><span style="color: black;">) </span><span style="color: black;">+</span><span style="color: black;"> </span><span style="color: black;">"</span><span style="color: black;">: </span><span style="color: black;">"</span><span style="color: black;"> </span><span style="color: black;">+</span><span style="color: black;">
empRow.getAttribute(</span><span style="color: black;">"</span><span style="color: black;">Ename</span><span style="color: black;">"</span><span style="color: black;">));
}
}</span></div>
</pre>
</div>
<script language="javascript" src="http://www.blogtrog.com/scripts/bt_code.js" type="text/javascript">
</script><script language="javascript" type="text/javascript">
bt_code_init('b1fd9f01-cee1-4d0f-bb81-1f1b4caca275');
</script>
<br />
The above code is self-explanatory. <a href="http://adftips.googlecode.com/files/DyanamicInClause.zip">You can download the sample application from here</a>. Once downloaded, run/debug the DemoAM and execute the sampleMethod. You'll get the following result:<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://4.bp.blogspot.com/-mnqLvPh8PcM/UBLk-feRfsI/AAAAAAAAAZY/4XkPMvGKOSI/s1600/Snap2.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://4.bp.blogspot.com/-mnqLvPh8PcM/UBLk-feRfsI/AAAAAAAAAZY/4XkPMvGKOSI/s1600/Snap2.jpg" /></a></div>
<br />
If you look at the log window, you can see the SQL query statements generated as below at runtime.<br />
<br />
<span style="background-color: white;">Generated SQL stmt with named bind variables:</span><br />
<a href="http://3.bp.blogspot.com/-ymjyEaNuwvs/UBLlAoNzITI/AAAAAAAAAZg/r1wO2JeqIno/s1600/Snap3.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em; text-align: center;"><img border="0" src="http://3.bp.blogspot.com/-ymjyEaNuwvs/UBLlAoNzITI/AAAAAAAAAZg/r1wO2JeqIno/s1600/Snap3.jpg" /></a><br />
<br />
Generated SQL stmt with positional bind variables:
<br />
<div>
<a href="http://3.bp.blogspot.com/--_EM3mXW-js/UBLk9fV7wEI/AAAAAAAAAZQ/SgUWhyXDFD4/s1600/Snap1.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em; text-align: center;"><img border="0" src="http://3.bp.blogspot.com/--_EM3mXW-js/UBLk9fV7wEI/AAAAAAAAAZQ/SgUWhyXDFD4/s1600/Snap1.jpg" /></a></div>
<br />
<span style="background-color: white;">This query statement uses bind variables instead of hard coded the statement and results in a prepared statement at runtime. Hence, the stmt will be compiled only once and the same will be reused for multiple calls. So, this is the most performant way of generating and executing the SQL programatically.</span></div>Murali Papanahttp://www.blogger.com/profile/06991064825453310705noreply@blogger.com127tag:blogger.com,1999:blog-8389468608715252764.post-70505556618173926512011-01-02T10:48:00.000-08:002011-01-27T09:08:07.256-08:00ADF Model: Different Date Effective Delete Modes and behavior with Examples<div dir="ltr" style="text-align: left;" trbidi="on">After learning about <a href="http://www.adftips.com/2011/01/adf-model-different-date-effective.html">different Date-Effective update modes available in ADF 11g and their behavior</a>, now let us move to date-effective delete modes. Understanding and using different DE delete modes also little tricky. Please go through below explanation of different DE delete modes along with examples.<br />
<br />
All the date-effective delete modes are defined as constants in <a href="http://download.oracle.com/docs/cd/E15523_01/apirefs.1111/e10653/oracle/jbo/Row.html">oracle.job.Row</a> class as any kind of effective dated operation is performed on a row itself. Before going into details, let us take an example to explain the concepts. For example, we'll take the same example of 'Job' date-effective object and explain different date-effective delete modes available. <a href="http://adftips.googlecode.com/files/DateEffective_Delete_Modes.zip">Sample application having the required code to perform the DE delete operations can be downloaded from here</a>.<br />
<br />
<b>The following DE delete modes available in Jdeveloper 11g:</b><br />
<b>1.EFFDT_DELETE_NEXT_CHANGE_MODE:</b> When an effective dated row is deleted in "delete next change" mode, the end date of the row is set to the end date of adjoining row and the adjoining row is deleted.<br />
For example, if the Job with JobId <span class="Apple-style-span" style="color: #333333; font-family: Georgia,serif; font-size: 13px; line-height: 20px;">100000020529001</span> has the following date-effective rows,<br />
<a href="http://2.bp.blogspot.com/_ex9GjJ9fvbk/TSCunVw5MxI/AAAAAAAAAXA/49iVagf2n9c/s1600/1.JPG" imageanchor="1" style="clear: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="108" src="http://2.bp.blogspot.com/_ex9GjJ9fvbk/TSCunVw5MxI/AAAAAAAAAXA/49iVagf2n9c/s640/1.JPG" style="cursor: move;" width="640" /></a><br />
And, if the current row is [<span class="Apple-style-span" style="color: #333333; font-family: Georgia,serif; font-size: 13px; line-height: 20px;">100000020529001,01-Jan-2011,31-Dec-2012</span>] (or if the current effective date falls in the range of <span class="Apple-style-span" style="color: #333333; font-family: Georgia,serif; font-size: 13px; line-height: 20px;">01-Jan-1900 and 31-Dec-2012</span>) and if we want to delete the next date-effective row i.e., [<span class="Apple-style-span" style="color: #333333; font-family: Georgia,serif; font-size: 13px; line-height: 20px;">100000020529001,01-Jan-2013,31-Dec-4712</span>], we'll use EFFDT_DELETE_NEXT_CHANGE_MODE.<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://2.bp.blogspot.com/_ex9GjJ9fvbk/TSCzF5Iak7I/AAAAAAAAAXI/0T-Sr1wGFhs/s1600/3.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="238" src="http://2.bp.blogspot.com/_ex9GjJ9fvbk/TSCzF5Iak7I/AAAAAAAAAXI/0T-Sr1wGFhs/s320/3.JPG" width="320" /></a></div>After deleting the row in EFFDT_DELETE_NEXT_CHANGE_MODE, the resultant rows will be:<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://1.bp.blogspot.com/_ex9GjJ9fvbk/TSCuodfx_LI/AAAAAAAAAXE/019WEsDVUNQ/s1600/2.JPG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="88" src="http://1.bp.blogspot.com/_ex9GjJ9fvbk/TSCuodfx_LI/AAAAAAAAAXE/019WEsDVUNQ/s640/2.JPG" width="640" /></a></div><br />
<b>2. EFFDT_DELETE_THIS_CHANGE_MODE:</b> When an effective dated row is deleted in "delete this change" mode, the current row is removed.<br />
For example, let us continue with the same above 3 rows and if we want to delete the Job Row [<span class="Apple-style-span" style="color: #333333; font-family: Georgia,serif; font-size: 13px; line-height: 20px;">100000020529001,01-Jan-1950,31-Dec-2010</span>], we need to make this row as current row (i.e., the effective date will be between <span class="Apple-style-span" style="color: #333333; font-family: Georgia,serif; font-size: 13px; line-height: 20px;">1-Jan-1950 and 31-Dec-2010) and delete the row in </span>EFFDT_DELETE_THIS_CHANGE_MODE<b>.</b><br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://4.bp.blogspot.com/_ex9GjJ9fvbk/TSC1RNC1RAI/AAAAAAAAAXM/lKRxcHAOLSQ/s1600/4.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="240" src="http://4.bp.blogspot.com/_ex9GjJ9fvbk/TSC1RNC1RAI/AAAAAAAAAXM/lKRxcHAOLSQ/s320/4.JPG" width="320" /></a></div> After deleting the current row in EFFDT_DELETE_THIS_CHANGE_MODE, the resultant rows will be:<br />
<a href="http://3.bp.blogspot.com/_ex9GjJ9fvbk/TSC1R-wTqAI/AAAAAAAAAXQ/yV0SNv2HtJ4/s1600/5.JPG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="66" src="http://3.bp.blogspot.com/_ex9GjJ9fvbk/TSC1R-wTqAI/AAAAAAAAAXQ/yV0SNv2HtJ4/s640/5.JPG" width="640" /></a><br />
<br />
<b>3.EFFDT_DELETE_MODE:</b> When an effective dated row is deleted in "delete" mode, the end date of the row is set to the row's effective date and all the future rows for the same key values are deleted.<br />
For example, let us assume that we have the following 4 date effective rows for the job with JobId <span class="Apple-style-span" style="color: #333333; font-family: Georgia,serif; font-size: 13px; line-height: 20px;">100000020529001</span><br />
<a href="http://3.bp.blogspot.com/_ex9GjJ9fvbk/TSC4KE-mg_I/AAAAAAAAAXU/AKz9GLsIGtQ/s1600/6.JPG" imageanchor="1" style="clear: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="110" src="http://3.bp.blogspot.com/_ex9GjJ9fvbk/TSC4KE-mg_I/AAAAAAAAAXU/AKz9GLsIGtQ/s640/6.JPG" style="cursor: move;" width="640" /></a><br />
<span class="Apple-style-span" style="color: #333333; font-family: Georgia,serif; font-size: 13px; line-height: 20px;"></span>And, if we want to end date the 2nd row i.e., [<span class="Apple-style-span" style="color: #333333; font-family: Georgia,serif; font-size: 13px; line-height: 20px;">100000020529001,01-Jan-1950,31-Dec-1974</span>] at 01-Jan-1960 and want to delete all the future rows, we'll pass the effective date 01-Jan-1960 and use the mode EFFDT_DELETE_MODE.<br />
<a href="http://3.bp.blogspot.com/_ex9GjJ9fvbk/TSC4K5BHJhI/AAAAAAAAAXY/FnbNY7bsRGw/s1600/7.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="239" src="http://3.bp.blogspot.com/_ex9GjJ9fvbk/TSC4K5BHJhI/AAAAAAAAAXY/FnbNY7bsRGw/s320/7.JPG" width="320" /></a><br />
After deleting the rows in <b>EFFDT_DELETE_MODE mode, the resultant rows will be:</b><br />
<a href="http://3.bp.blogspot.com/_ex9GjJ9fvbk/TSC4LxFEE2I/AAAAAAAAAXc/JkjB5yAJmSk/s1600/8.JPG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="64" src="http://3.bp.blogspot.com/_ex9GjJ9fvbk/TSC4LxFEE2I/AAAAAAAAAXc/JkjB5yAJmSk/s640/8.JPG" width="640" /></a><b><span class="Apple-style-span" style="font-weight: normal;"></span></b><br />
<b>4.EFFDT_DELETE_FUTURE_CHANGE_MODE:</b> When an effective dated row is deleted in "delete future change" mode, the end date of the row is set to the end of time and all the future rows for the same key values are deleted.<br />
For example, let us assume that we have the following 4 date effective rows for the job with JobId <span class="Apple-style-span" style="color: #333333; font-family: Georgia,serif; font-size: 13px; line-height: 20px;">100000020529001</span><br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://1.bp.blogspot.com/_ex9GjJ9fvbk/TSC88sosTLI/AAAAAAAAAXg/VNv8p0i0uOE/s1600/9.JPG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="96" src="http://1.bp.blogspot.com/_ex9GjJ9fvbk/TSC88sosTLI/AAAAAAAAAXg/VNv8p0i0uOE/s640/9.JPG" width="640" /></a></div>And, if we want to delete all future date-effective rows starting from 01-Jan-1975, then, we need to make the row [<span class="Apple-style-span" style="color: #333333; font-family: Georgia,serif; font-size: 13px; line-height: 20px;">100000020529001,</span><span class="Apple-style-span" style="color: #333333; font-family: Georgia,serif; font-size: 13px; line-height: 20px;">01-Jan-1950</span><span class="Apple-style-span" style="color: #333333; font-family: Georgia,serif; font-size: 13px; line-height: 20px;">,31-Dec-1974</span>] as current row (or make effective date between <span class="Apple-style-span" style="color: #333333; font-family: Georgia,serif; font-size: 13px; line-height: 20px;">01-Jan-1950 and </span><span class="Apple-style-span" style="color: #333333; font-family: Georgia,serif; font-size: 13px; line-height: 20px;">31-Dec-1974</span>) and delete the rows in EFFDT_DELETE_FUTURE_CHANGE_MODE. This will delete all remaining future rows and end date the current row i.e., [<span class="Apple-style-span" style="color: #333333; font-family: Georgia,serif; font-size: 13px; line-height: 20px;">100000020529001,</span><span class="Apple-style-span" style="color: #333333; font-family: Georgia,serif; font-size: 13px; line-height: 20px;">01-Jan-1950</span><span class="Apple-style-span" style="color: #333333; font-family: Georgia,serif; font-size: 13px; line-height: 20px;">,31-Dec-1974</span>] till EOT(31-12-4712).<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://1.bp.blogspot.com/_ex9GjJ9fvbk/TSDAYOfK_WI/AAAAAAAAAXk/HwDp5cvxEkA/s1600/10.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="240" src="http://1.bp.blogspot.com/_ex9GjJ9fvbk/TSDAYOfK_WI/AAAAAAAAAXk/HwDp5cvxEkA/s320/10.JPG" width="320" /></a></div> The resultant rows after deleting the rows in EFFDT_DELETE_FUTURE_CHANGE_MODE will be:<br />
<a href="http://4.bp.blogspot.com/_ex9GjJ9fvbk/TSDAY8sqTaI/AAAAAAAAAXo/2b9qvC1S_kg/s1600/11.JPG" imageanchor="1" style="clear: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="62" src="http://4.bp.blogspot.com/_ex9GjJ9fvbk/TSDAY8sqTaI/AAAAAAAAAXo/2b9qvC1S_kg/s640/11.JPG" style="cursor: move;" width="640" /></a><br />
<br />
<b>5.EFFDT_DELETE_ZAP_MODE:</b> When an effective dated row is deleted in "zap" mode, all the effective dated rows with the same key values are deleted.<br />
For example, let us assume that we have the following 4 date effective rows for the job with JobId <span class="Apple-style-span" style="color: #333333; font-family: Georgia,serif; font-size: 13px; line-height: 20px;">100000020529001</span><br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://4.bp.blogspot.com/_ex9GjJ9fvbk/TSDCEcD7mkI/AAAAAAAAAXs/f58LUUEf7Gs/s1600/12.JPG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="98" src="http://4.bp.blogspot.com/_ex9GjJ9fvbk/TSDCEcD7mkI/AAAAAAAAAXs/f58LUUEf7Gs/s640/12.JPG" width="640" /></a></div><span class="Apple-style-span" style="color: #333333; font-family: Georgia,serif; font-size: 13px; line-height: 20px;">And, if we want to delete all date-effective records of this job, we need to use </span>EFFDT_DELETE_ZAP_MODE. Effective Date won't make any difference in this mode as it'll delete all existing date-effective records.<br />
<span class="Apple-style-span" style="color: #333333; font-family: Georgia,serif; font-size: 13px; line-height: 20px;"><span class="Apple-style-span" style="color: black; font-family: 'Times New Roman'; font-size: small; line-height: normal;"><a href="http://3.bp.blogspot.com/_ex9GjJ9fvbk/TSDCFSA4-uI/AAAAAAAAAXw/R1j58EaA7Po/s1600/13.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="239" src="http://3.bp.blogspot.com/_ex9GjJ9fvbk/TSDCFSA4-uI/AAAAAAAAAXw/R1j58EaA7Po/s320/13.JPG" width="320" /></a></span></span><br />
<span class="Apple-style-span" style="color: #333333; font-family: Georgia,serif; font-size: 13px; line-height: 20px;">After deleting the rows in Zap mode, all the date-effective rows got deleted:</span><br />
<span class="Apple-style-span" style="color: #333333; font-family: Georgia,serif; font-size: 13px; line-height: 20px;"><span class="Apple-style-span" style="color: black; font-family: 'Times New Roman'; font-size: small; line-height: normal;"><a href="http://4.bp.blogspot.com/_ex9GjJ9fvbk/TSDCGdWdjPI/AAAAAAAAAX0/x7UqTk1JsJY/s1600/14.JPG" imageanchor="1" style="clear: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="66" src="http://4.bp.blogspot.com/_ex9GjJ9fvbk/TSDCGdWdjPI/AAAAAAAAAX0/x7UqTk1JsJY/s640/14.JPG" width="640" /></a></span></span><br />
<br />
Here is the method that I wrote to accomplish all of these DE delete operations with different DE delete modes (download the sample application for to find the method references used in the below code).<br />
<div id="iframeDivbc564467-18a9-4aae-87b7-309432193729" style="display: none; margin: 0px;"><iframe frameborder="0" id="iframebc564467-18a9-4aae-87b7-309432193729" src="http://www.blogtrog.com/code.aspx?id=bc564467-18a9-4aae-87b7-309432193729" style="border: 1px solid rgb(224, 224, 224); height: 400px; margin: 0px; width: 400px;"></iframe></div><div id="noIframeDivbc564467-18a9-4aae-87b7-309432193729" style="display: block; margin: 0px;"><pre><div><span style="color: black;"> </span><span style="color: blue;">public</span><span style="color: black;"> </span><span style="color: blue;">void</span><span style="color: black;"> deleteJobRow(Long jobId, Date effectiveDate) {
</span><span style="color: blue;">if</span><span style="color: black;"> (effectiveDate </span><span style="color: black;">==</span><span style="color: black;"> </span><span style="color: blue;">null</span><span style="color: black;">) {
</span><span style="color: blue;">throw</span><span style="color: black;"> </span><span style="color: blue;">new</span><span style="color: black;"> JboException(</span><span style="color: black;">"</span><span style="color: black;">Effective Date cannot be null</span><span style="color: black;">"</span><span style="color: black;">);
}
</span><span style="color: blue;">if</span><span style="color: black;"> (effectiveDate.compareTo(DateUtils.convertTosqlDate(MIN_START_DATE)) </span><span style="color: black;"><=</span><span style="color: black;">
</span><span style="color: black;">0</span><span style="color: black;"> </span><span style="color: black;">||</span><span style="color: black;">
effectiveDate.compareTo(DateUtils.convertTosqlDate(MAX_END_DATE)) </span><span style="color: black;">>=</span><span style="color: black;">
</span><span style="color: black;">0</span><span style="color: black;">) {
</span><span style="color: blue;">throw</span><span style="color: black;"> </span><span style="color: blue;">new</span><span style="color: black;"> JboException(</span><span style="color: black;">"</span><span style="color: black;">EffectiveDate cannot be before SOT and cannot be later than EOT</span><span style="color: black;">"</span><span style="color: black;">);
}
</span><span style="color: green;">//</span><span style="color: green;">getting the Job row effective as of the given effectiveDate</span><span style="color: green;">
</span><span style="color: black;"> Row jobRow </span><span style="color: black;">=</span><span style="color: black;"> getRowAsOfDate(jobId, effectiveDate);
</span><span style="color: blue;">if</span><span style="color: black;"> (jobRow </span><span style="color: black;">!=</span><span style="color: black;"> </span><span style="color: blue;">null</span><span style="color: black;">) {
</span><span style="color: blue;">try</span><span style="color: black;"> {
</span><span style="color: green;">//</span><span style="color: green;">Set the required date-effective delete mode. Here I'm setting it to EFFDT_DELETE_THIS_CHANGE_MODE</span><span style="color: green;">
</span><span style="color: black;"> jobRow.setEffectiveDateMode(Row.EFFDT_DELETE_THIS_CHANGE_MODE );
jobRow.remove();
} </span><span style="color: blue;">catch</span><span style="color: black;"> (Exception e) {
e.printStackTrace();
}
</span><span style="color: blue;">this</span><span style="color: black;">.getDBTransaction().commit();
}
}</span></div></pre></div><script language="javascript" src="http://www.blogtrog.com/scripts/bt_code.js" type="text/javascript">
</script><script language="javascript" type="text/javascript">
bt_code_init('bc564467-18a9-4aae-87b7-309432193729');
</script><br />
In the above method, we're actually getting the Job row effective as of the passed effective date(this will make that effective-dated row as current row) and then performing date-effective delete operations basing on that row.<br />
<br />
<b>Instructions to run the <a href="http://adftips.googlecode.com/files/DateEffective_Delete_Modes.zip">sample application</a>:</b><br />
1. Create the required tables for illustrating date-effective operations executing the <a href="http://adftips.googlecode.com/files/de_sql.sql">sql script downloading from here</a>.<br />
<div style="margin: 0px;">2. Unzip the sample application and, run the DemoAM. Input JobId, effective date and click 'Execute'.</div><div style="margin: 0px;">3. Change the date-effective delete mode in method 'deleteJobRow' each time you want to change the delete mode(right now it's hard coded to EFFDT_DELETE_THIS_CHANGE_MODE), rebuild and continue. You can find the screen shots above how to provide input in AM Tester.</div><div style="margin: 0px;">4. Query the DB to find the resultant rows after the delete operation.</div><div id="iframeDivc55a9fb0-6439-440c-89ae-f7b636c1959d" style="display: none; margin: 0px;"><iframe frameborder="0" id="iframec55a9fb0-6439-440c-89ae-f7b636c1959d" src="http://www.blogtrog.com/code.aspx?id=c55a9fb0-6439-440c-89ae-f7b636c1959d" style="border: 1px solid rgb(224, 224, 224); height: 200px; margin: 0px; width: 400px;"></iframe></div><div id="noIframeDivc55a9fb0-6439-440c-89ae-f7b636c1959d" style="display: block; margin: 0px;"><pre><div><span style="color: blue;">SELECT</span><span style="color: black;"> Job_ID,
TO_CHAR(effective_start_date,</span><span style="color: red;">'</span><span style="color: red;">dd-Mon-yyyy</span><span style="color: red;">'</span><span style="color: black;">) </span><span style="color: blue;">AS</span><span style="color: black;"> ESD,
TO_CHAR(effective_end_date,</span><span style="color: red;">'</span><span style="color: red;">dd-Mon-yyyy</span><span style="color: red;">'</span><span style="color: black;">) </span><span style="color: blue;">AS</span><span style="color: black;"> EED,
JOB_NAME,
MIN_SAL,
MAX_SAL,
STATUS,
JOB_LEVEL,
MED_CHECK_REQ </span><span style="color: blue;">AS</span><span style="color: black;"> MED_CHECK
</span><span style="color: blue;">FROM</span><span style="color: black;"> de_jobs
</span><span style="color: blue;">WHERE</span><span style="color: black;"> job_id</span><span style="color: grey;">=</span><span style="color: maroon; font-weight: bold;">100000020529001</span><span style="color: black;">
</span><span style="color: blue;">ORDER</span><span style="color: black;"> </span><span style="color: blue;">BY</span><span style="color: black;"> effective_start_date;</span></div></pre></div><script language="javascript" src="http://www.blogtrog.com/scripts/bt_code.js" type="text/javascript">
</script><script language="javascript" type="text/javascript">
bt_code_init('c55a9fb0-6439-440c-89ae-f7b636c1959d');
</script><br />
Enjoy!!!</div>Murali Papanahttp://www.blogger.com/profile/06991064825453310705noreply@blogger.com15tag:blogger.com,1999:blog-8389468608715252764.post-89074848983081916592011-01-01T12:11:00.000-08:002011-01-27T09:09:24.382-08:00ADF Model: Different Date Effective Update Modes and behavior with ExamplesWhen it comes to date-effectivity, the tricky part is date-effective updates to the rows. It's not as simple as updating non date-effective rows. You need to know the <a href="http://www.adftips.com/2010/12/learning-basics-of-date-effectivity-in.html">basics of date-effectivity</a> like what is an effective date and how it impacts <a href="http://www.adftips.com/2010/12/adf-ui-implementing-date-effective.html">search</a>, create and update operations on date-effective records. Here, we're going to discuss different date-effective update modes available in ADF 11g and their behavior.<br />
<br />
All the date-effective update modes are defined as constants in <a href="http://download.oracle.com/docs/cd/E15523_01/apirefs.1111/e10653/oracle/jbo/Row.html">oracle.job.Row</a> class as any kind of effective dated operation is performed on a row itself. Before going into details, let us take an example to explain the concepts. For example, we'll take the same example of 'Job' date-effective object and explain different date-effective update modes available. <a href="http://adftips.googlecode.com/files/DateEffective_Update_Modes.zip">Sample application having the required code to perform the DE update operations can be downloaded from here</a>.<br />
<br />
<b>The following DE update modes available in Jdeveloper 11g:</b><br />
<br />
<b>1. EFFDT_UPDATE_CHANGE_INSERT_MODE:</b> When an effective dated row is updated in "change insert" mode, the modified row is end dated on the effective date and a new row is inserted that fits between the effective date and the start date of the next row in the effective date time line.<br />
<br />
For example, if the Job with JobId 100000020529001 has the following effective-dated row<br />
<div class="separator" style="clear: both; text-align: center;"></div><div class="separator" style="clear: both; text-align: center;"></div><div class="separator" style="clear: both; text-align: center;"><a href="http://1.bp.blogspot.com/_ex9GjJ9fvbk/TR93R0T9UFI/AAAAAAAAAWI/MOWtsV6JTjY/s1600/1.JPG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="44" src="http://1.bp.blogspot.com/_ex9GjJ9fvbk/TR93R0T9UFI/AAAAAAAAAWI/MOWtsV6JTjY/s640/1.JPG" width="640" /></a></div><br />
<br />
<div class="separator" style="clear: both; text-align: center;"></div>From the above data, you can see that the details of the job 'Apps Engineer' from 01-Jan-1990 to 31-Dec-4712. And, for example if we want to increase the salary ranges of this job to MinSal=25000 and MaxSal=35000 from 01-Jan-2011 onwards. To achieve this, we need to end date the existing row at 31-Dec-2010 and create a new record for the job from 01-Jan-2011 to 31-12-4712. For such cases, we use this EFFDT_UPDATE_CHANGE_INSERT_MODE.<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://2.bp.blogspot.com/_ex9GjJ9fvbk/TR95MIFvuHI/AAAAAAAAAWU/YEx9Dos96pU/s1600/2.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="241" src="http://2.bp.blogspot.com/_ex9GjJ9fvbk/TR95MIFvuHI/AAAAAAAAAWU/YEx9Dos96pU/s320/2.JPG" width="320" /></a></div>After updating the above job record with effective date 01-Jan-2011, the resultant rows will be as below:<br />
<div class="separator" style="clear: both; text-align: center;"></div><div class="separator" style="clear: both; text-align: center;"><a href="http://4.bp.blogspot.com/_ex9GjJ9fvbk/TR938NasZTI/AAAAAAAAAWQ/a7VrAUlvKtQ/s1600/3.JPG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="68" src="http://4.bp.blogspot.com/_ex9GjJ9fvbk/TR938NasZTI/AAAAAAAAAWQ/a7VrAUlvKtQ/s640/3.JPG" width="640" /></a></div><br />
Again, if we want to update the MedicalCheckRequired attribute to 'Y' effective 01-Jan-1950 (till 31-Dec-2010), we need to update again with effective date 01-Jan-1950.<br />
<div class="separator" style="clear: both; text-align: center;"></div><div class="separator" style="clear: both; text-align: center;"><a href="http://4.bp.blogspot.com/_ex9GjJ9fvbk/TR95dcXA9EI/AAAAAAAAAWc/LJaJo424n-w/s1600/4.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="239" src="http://4.bp.blogspot.com/_ex9GjJ9fvbk/TR95dcXA9EI/AAAAAAAAAWc/LJaJo424n-w/s320/4.JPG" width="320" /></a></div> After updating, the resultant rows will be:<br />
<a href="http://3.bp.blogspot.com/_ex9GjJ9fvbk/TR95QsmLymI/AAAAAAAAAWY/TH-p4IdxNRs/s1600/5.JPG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="90" src="http://3.bp.blogspot.com/_ex9GjJ9fvbk/TR95QsmLymI/AAAAAAAAAWY/TH-p4IdxNRs/s640/5.JPG" style="cursor: move;" width="640" /></a><br />
<b><br />
</b><br />
<br />
<b><br />
</b><br />
<b>2. EFFDT_UPDATE_CORRECTION:</b> When an effective dated row is updated in "correction" mode, the effective start date and effective end date is left unchanged. We generally use this correction mode to correct the existing data of a single date-effective record (Correction mode won't create a new row, it'll just correct/modify the existing date-effective record data).<br />
<br />
For example, let us take the same above 3 date-effective job records and if I want to correct the JobLevel of the Job record [100000020529001,01-Jan-1900,31-Dec-1949] to 1 from existing value 2, we need to correct the record in EFFDT_UPDATE_CORRECTION mode. For correction, we can use any date between EffectiveStartDate and EffectiveEndDate as the effective date.<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://1.bp.blogspot.com/_ex9GjJ9fvbk/TR97dLm_c4I/AAAAAAAAAWk/IPRWT1Zn-iQ/s1600/6.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="240" src="http://1.bp.blogspot.com/_ex9GjJ9fvbk/TR97dLm_c4I/AAAAAAAAAWk/IPRWT1Zn-iQ/s320/6.JPG" width="320" /></a></div> After correction, the result will be as follows:<br />
<a href="http://2.bp.blogspot.com/_ex9GjJ9fvbk/TR97cGRUfEI/AAAAAAAAAWg/ROP_voKJr3M/s1600/7.JPG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="82" src="http://2.bp.blogspot.com/_ex9GjJ9fvbk/TR97cGRUfEI/AAAAAAAAAWg/ROP_voKJr3M/s640/7.JPG" width="640" /></a><br />
<br />
<br />
<br />
<br />
<br />
<b><span class="Apple-style-span" style="font-weight: normal;"><b>3. EFFDT_UPDATE_MODE:</b></span><span class="Apple-style-span" style="font-weight: normal;"> </span><span class="Apple-style-span" style="font-weight: normal;">When an effective dated row is updated in "update" mode, the modified row is end dated on the effective date and a new row is created with the changed values.</span></b><br />
<br />
For example, let us continue with the same above 3 rows and I want to update the JobName to 'Apps Specialist' from 'Apps Engineer' effective 01-Jan-2015, we can use EFFDT_UPDATE_MODE.<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://4.bp.blogspot.com/_ex9GjJ9fvbk/TR9_irlSrXI/AAAAAAAAAWs/8B3w092Y60Y/s1600/8.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="241" src="http://4.bp.blogspot.com/_ex9GjJ9fvbk/TR9_irlSrXI/AAAAAAAAAWs/8B3w092Y60Y/s320/8.JPG" width="320" /></a></div>After updating in UPDATE mode, the resultant rows will be:<br />
<a href="http://1.bp.blogspot.com/_ex9GjJ9fvbk/TR9_hrxvMcI/AAAAAAAAAWo/ciBF_k1UhAE/s1600/9.JPG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="100" src="http://1.bp.blogspot.com/_ex9GjJ9fvbk/TR9_hrxvMcI/AAAAAAAAAWo/ciBF_k1UhAE/s640/9.JPG" width="640" /></a><br />
Here, one thing that we need to keep is that <span class="Apple-style-span">EFFDT_UPDATE_MODE</span> works only for the last date-effective row. The reason is that this mode will always create the modified new record till EOT(31-12-4712) starting from the given effective date. i.e., if we try to update the row [100000020529001,01-Jan-1900,31-Dec-1949] with effective date 01-Jan-1925 in UPDATE_MODE mode, it'll try to create the new record [100000020529001,01-Jan-1920,31-Dec-4712] which will result in overlap with the existing record [100000020529001,01-Jan-1950,31-Dec-2010] and throws exception saying 'the date effective operation will result in gaps or overlaps'.<br />
<br />
<b>4. EFFDT_UPDATE_OVERRIDE_MODE:</b> When an effective dated row is updated in "override" mode, the modified row is end dated on the effective date and the start date of the next row in the effective date time line is set to effective date + 1 day.<br />
<br />
For example, let us continue with the above 4 date-effective rows, and if we want to move the EffectiveStartDate of the Job row [100000020529001,01-Jan-2015,31-Dec-4712] to 01-Jan-2013. i.e., we want to make the 'Apps Specialist' job title applicable from 01-Jan-2013 onwards instead of 01-Jan-2015. And, you can also set/change the other attributes for the resultant updated row [100000020529001,01-Jan-2013,31-Dec-4712] (for e.g., I'm setting the JobLevel from 2 to 3).<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://3.bp.blogspot.com/_ex9GjJ9fvbk/TR-DBOiTcFI/AAAAAAAAAW8/5axdSOU3C88/s1600/10.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="240" src="http://3.bp.blogspot.com/_ex9GjJ9fvbk/TR-DBOiTcFI/AAAAAAAAAW8/5axdSOU3C88/s320/10.JPG" width="320" /></a></div>After updating the above rows with effective date 01-Jan-2013 in EFFDT_UPDATE_OVERRIDE_MODE will result in the following rows:<br />
<a href="http://2.bp.blogspot.com/_ex9GjJ9fvbk/TR-DAYt3RgI/AAAAAAAAAW4/WmWL-S20bgU/s1600/11.JPG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="108" src="http://2.bp.blogspot.com/_ex9GjJ9fvbk/TR-DAYt3RgI/AAAAAAAAAW4/WmWL-S20bgU/s640/11.JPG" width="640" /></a> <br />
From the above table, you can observe that EFFDT_UPDATE_OVERRIDE_MODE didn't create any new rows. It just moved the existing ESD to the passed effective date.<br />
<br />
<b>5. EFFDT_UPDATE_NEW_EARLIEST_CHANGE_MODE:</b> Updating in "new earliest change" mode is supported only in Multiple Changes Per Day (MCPD). MCPD entities are the entities that support multiple date-effective updates on a single day. We're not covering this mode in this post as it would be out of scope of this post.<br />
<br />
Here is the method that I wrote to accomplish all of these DE update operations with different DE update modes (download the <a href="http://adftips.googlecode.com/files/DateEffective_Update_Modes.zip">sample application</a> for to find the method references used in the below code).<br />
<div id="iframeDiv162ed4a1-a0d1-4689-9ea7-ec0d5f28ee35" style="display: none; margin: 0px;"><iframe frameborder="0" id="iframe162ed4a1-a0d1-4689-9ea7-ec0d5f28ee35" src="http://www.blogtrog.com/code.aspx?id=162ed4a1-a0d1-4689-9ea7-ec0d5f28ee35" style="border: 1px solid rgb(224, 224, 224); height: 500px; margin: 0px; width: 400px;"></iframe></div><div id="noIframeDiv162ed4a1-a0d1-4689-9ea7-ec0d5f28ee35" style="display: block; margin: 0px;"><pre><div><span style="color: black;"> </span><span style="color: blue;">public</span><span style="color: black;"> </span><span style="color: blue;">void</span><span style="color: black;"> updateJobRow(Long jobId, Date effectiveDate, String jobName,
String status, Long minSal, Long maxSal,
String medCheckReq, Integer jobLevel) {
</span><span style="color: blue;">if</span><span style="color: black;"> (effectiveDate </span><span style="color: black;">==</span><span style="color: black;"> </span><span style="color: blue;">null</span><span style="color: black;">) {
</span><span style="color: blue;">throw</span><span style="color: black;"> </span><span style="color: blue;">new</span><span style="color: black;"> JboException(</span><span style="color: black;">"</span><span style="color: black;">Effective Date cannot be null</span><span style="color: black;">"</span><span style="color: black;">);
}
</span><span style="color: blue;">if</span><span style="color: black;"> (effectiveDate.compareTo(DateUtils.convertTosqlDate(MIN_START_DATE)) </span><span style="color: black;"><=</span><span style="color: black;">
</span><span style="color: black;">0</span><span style="color: black;"> </span><span style="color: black;">||</span><span style="color: black;">
effectiveDate.compareTo(DateUtils.convertTosqlDate(MAX_END_DATE)) </span><span style="color: black;">>=</span><span style="color: black;">
</span><span style="color: black;">0</span><span style="color: black;">) {
</span><span style="color: blue;">throw</span><span style="color: black;"> </span><span style="color: blue;">new</span><span style="color: black;"> JboException(</span><span style="color: black;">"</span><span style="color: black;">UpdateDate cannot be before SOT and cannot be later than EOT</span><span style="color: black;">"</span><span style="color: black;">);
}
</span><span style="color: green;">//</span><span style="color: green;">getting the Job row effective as of the given effectiveDate</span><span style="color: green;">
</span><span style="color: black;"> Row jobRow </span><span style="color: black;">=</span><span style="color: black;"> getRowAsOfDate(jobId, effectiveDate);
</span><span style="color: blue;">if</span><span style="color: black;"> (jobRow </span><span style="color: black;">!=</span><span style="color: black;"> </span><span style="color: blue;">null</span><span style="color: black;">) {
</span><span style="color: blue;">try</span><span style="color: black;"> {
</span><span style="color: green;">//</span><span style="color: green;">Set the required date-effective mode. Here I'm setting it to EFFDT_UPDATE_CHANGE_INSERT_MODE</span><span style="color: green;">
</span><span style="color: black;"> jobRow.setEffectiveDateMode(Row.EFFDT_UPDATE_CHANGE_INSERT_MODE);
</span><span style="color: green;">//</span><span style="color: green;">Setting the passed attributes to the updated row</span><span style="color: green;">
</span><span style="color: black;"> </span><span style="color: blue;">if</span><span style="color: black;"> (jobName </span><span style="color: black;">!=</span><span style="color: black;"> </span><span style="color: blue;">null</span><span style="color: black;"> </span><span style="color: black;">&&</span><span style="color: black;"> </span><span style="color: black;">!</span><span style="color: black;">""</span><span style="color: black;">.equals(jobName))
jobRow.setAttribute(</span><span style="color: black;">"</span><span style="color: black;">JobName</span><span style="color: black;">"</span><span style="color: black;">, jobName);
</span><span style="color: blue;">if</span><span style="color: black;"> (status </span><span style="color: black;">!=</span><span style="color: black;"> </span><span style="color: blue;">null</span><span style="color: black;"> </span><span style="color: black;">&&</span><span style="color: black;"> </span><span style="color: black;">!</span><span style="color: black;">""</span><span style="color: black;">.equals(status))
jobRow.setAttribute(</span><span style="color: black;">"</span><span style="color: black;">Status</span><span style="color: black;">"</span><span style="color: black;">, status);
</span><span style="color: blue;">if</span><span style="color: black;"> (minSal </span><span style="color: black;">!=</span><span style="color: black;"> </span><span style="color: blue;">null</span><span style="color: black;"> </span><span style="color: black;">&&</span><span style="color: black;"> </span><span style="color: black;">!</span><span style="color: black;">""</span><span style="color: black;">.equals(minSal))
jobRow.setAttribute(</span><span style="color: black;">"</span><span style="color: black;">MinSal</span><span style="color: black;">"</span><span style="color: black;">, minSal);
</span><span style="color: blue;">if</span><span style="color: black;"> (maxSal </span><span style="color: black;">!=</span><span style="color: black;"> </span><span style="color: blue;">null</span><span style="color: black;"> </span><span style="color: black;">&&</span><span style="color: black;"> </span><span style="color: black;">!</span><span style="color: black;">""</span><span style="color: black;">.equals(maxSal))
jobRow.setAttribute(</span><span style="color: black;">"</span><span style="color: black;">MaxSal</span><span style="color: black;">"</span><span style="color: black;">, maxSal);
</span><span style="color: blue;">if</span><span style="color: black;"> (jobLevel </span><span style="color: black;">!=</span><span style="color: black;"> </span><span style="color: blue;">null</span><span style="color: black;"> </span><span style="color: black;">&&</span><span style="color: black;"> </span><span style="color: black;">!</span><span style="color: black;">""</span><span style="color: black;">.equals(jobLevel))
jobRow.setAttribute(</span><span style="color: black;">"</span><span style="color: black;">JobLevel</span><span style="color: black;">"</span><span style="color: black;">, jobLevel);
</span><span style="color: blue;">if</span><span style="color: black;"> (medCheckReq </span><span style="color: black;">!=</span><span style="color: black;"> </span><span style="color: blue;">null</span><span style="color: black;"> </span><span style="color: black;">&&</span><span style="color: black;"> </span><span style="color: black;">!</span><span style="color: black;">""</span><span style="color: black;">.equals(medCheckReq))
jobRow.setAttribute(</span><span style="color: black;">"</span><span style="color: black;">MedCheckReq</span><span style="color: black;">"</span><span style="color: black;">, medCheckReq);
} </span><span style="color: blue;">catch</span><span style="color: black;"> (Exception e) {
e.printStackTrace();
}
</span><span style="color: blue;">this</span><span style="color: black;">.getDBTransaction().commit();
}
}</span></div></pre></div><script language="javascript" src="http://www.blogtrog.com/scripts/bt_code.js" type="text/javascript">
</script><script language="javascript" type="text/javascript">
bt_code_init('162ed4a1-a0d1-4689-9ea7-ec0d5f28ee35');
</script><br />
In the above method, we're actually getting the Job row effective as of the passed effective date(this will make that effective-dated row as current row) and then performing date-effective update operations basing on that row.<br />
<br />
<b>Instructions to run the <a href="http://adftips.googlecode.com/files/DateEffective_Update_Modes.zip">sample application</a>:</b><br />
1. Create the required tables for illustrating date-effective operations executing the <a href="http://adftips.googlecode.com/files/de_sql.sql">sql script downloading from here</a>.<br />
2. Unzip the sample application and, run the DemoAM. Input JobId, effective date and other attributes you want to update and click 'Execute'.<br />
3. Change the date-effective update mode in method 'updateJobRow' each time you want to change the update mode(right now it's hard coded to EFFDT_UPDATE_CHANGE_INSERT_MODE), rebuild and continue. You can find the screen shots above how to provide input in AM Tester.<br />
4. Query the DB to find the updated rows.<br />
<div id='iframeDivc55a9fb0-6439-440c-89ae-f7b636c1959d' style='display:none;margin:0px;'><iframe id='iframec55a9fb0-6439-440c-89ae-f7b636c1959d' src='http://www.blogtrog.com/code.aspx?id=c55a9fb0-6439-440c-89ae-f7b636c1959d' style='width: 400px; height: 200px; border: 1px solid #e0e0e0;margin:0px;' frameborder='0'></iframe></div><div id='noIframeDivc55a9fb0-6439-440c-89ae-f7b636c1959d' style='display:block;margin:0px;'><pre><div><!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
--><span style="color: #0000FF;">SELECT</span><span style="color: #000000;"> Job_ID,
TO_CHAR(effective_start_date,</span><span style="color: #FF0000;">'</span><span style="color: #FF0000;">dd-Mon-yyyy</span><span style="color: #FF0000;">'</span><span style="color: #000000;">) </span><span style="color: #0000FF;">AS</span><span style="color: #000000;"> ESD,
TO_CHAR(effective_end_date,</span><span style="color: #FF0000;">'</span><span style="color: #FF0000;">dd-Mon-yyyy</span><span style="color: #FF0000;">'</span><span style="color: #000000;">) </span><span style="color: #0000FF;">AS</span><span style="color: #000000;"> EED,
JOB_NAME,
MIN_SAL,
MAX_SAL,
STATUS,
JOB_LEVEL,
MED_CHECK_REQ </span><span style="color: #0000FF;">AS</span><span style="color: #000000;"> MED_CHECK
</span><span style="color: #0000FF;">FROM</span><span style="color: #000000;"> de_jobs
</span><span style="color: #0000FF;">WHERE</span><span style="color: #000000;"> job_id</span><span style="color: #808080;">=</span><span style="color: #800000; font-weight: bold;">100000020529001</span><span style="color: #000000;">
</span><span style="color: #0000FF;">ORDER</span><span style="color: #000000;"> </span><span style="color: #0000FF;">BY</span><span style="color: #000000;"> effective_start_date;</span></div></pre></div><script language='javascript' src='http://www.blogtrog.com/scripts/bt_code.js' type='text/javascript'></script><script language='javascript' type='text/javascript'>bt_code_init('c55a9fb0-6439-440c-89ae-f7b636c1959d');</script><br />
Enjoy!!!Murali Papanahttp://www.blogger.com/profile/06991064825453310705noreply@blogger.com7tag:blogger.com,1999:blog-8389468608715252764.post-34026707739763019122010-12-28T10:56:00.000-08:002011-01-27T09:09:26.764-08:00ADF UI - Implementing Date Effective Search with ExampleAfter learning how to create date-effective objects (i.e., <a href="http://www.adftips.com/2010/12/adf-model-creating-date-effective-eo.html">Creating Date-Effective EO</a>, <a href="http://www.adftips.com/2010/12/adf-model-creating-date-effective.html">Creating Date-Effective Associations and VOs</a>), now we'll see how to implement date-effective search.<br />
<br />
<b>Sample Use Case:</b><br />
Please go through <a href="http://www.adftips.com/2010/12/learning-basics-of-date-effectivity-in.html">my previous post</a> to see the sample example use cases of performing date-effective operations on 'Job' object. So, here the requirement is to search for a job effective as of the given date. <a href="http://adftips.googlecode.com/files/DateEffective_Search.zip">Sample application illustrating this example can be downloaded from here</a>. Before running the example, you need to create the required tables in DB. <a href="http://adftips.googlecode.com/files/de_sql.sql">The sql script for these table can be downloaded from here</a>.<br />
<br />
<b>Implementation Steps:</b><br />
1. Create the date-effective EO (JobEO) and date-effective VO (JobVO). Marking the JobVO will create a new transient attribute called <b>SysEffectiveDate </b>in the VO attributes.<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://1.bp.blogspot.com/_ex9GjJ9fvbk/TReR1TERjKI/AAAAAAAAAVY/xHMgG1NCsWk/s1600/1.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="213" src="http://1.bp.blogspot.com/_ex9GjJ9fvbk/TReR1TERjKI/AAAAAAAAAVY/xHMgG1NCsWk/s320/1.JPG" width="320" /></a></div><br />
2. Create a view criteria 'JobSearch' and add the required attributes as query criteria items on which you want to perform the search. As a best practice, use bind variables for all the view criteria items(attributes).<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://2.bp.blogspot.com/_ex9GjJ9fvbk/TReR4yEDyzI/AAAAAAAAAVc/beGkOueZLyw/s1600/2.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="http://2.bp.blogspot.com/_ex9GjJ9fvbk/TReR4yEDyzI/AAAAAAAAAVc/beGkOueZLyw/s320/2.JPG" width="318" /></a></div><br />
3. In addition to those attributes, add SysEffectiveDate in the query attributes and bind it to the bind variable <b>SysEffectiveDateBindVar</b> of type <b>Date</b>(if this bind variable is not already exist, create a new bind variable <b>with same name</b> and associate it to SysEffectiveDate). Here, the bind variable name that binds SysEffectiveDate <b>should be</b> <b>SysEffectiveDateBindVar </b>as this is the bind variable name generated at runtime by ADF for SysEffectiveDate<b>. </b>Otherwise, it'll throw run time exception.<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://2.bp.blogspot.com/_ex9GjJ9fvbk/TReR6VzZgdI/AAAAAAAAAVg/P7Np7D39NPM/s1600/3.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="http://2.bp.blogspot.com/_ex9GjJ9fvbk/TReR6VzZgdI/AAAAAAAAAVg/P7Np7D39NPM/s320/3.JPG" width="320" /></a></div><br />
4. Now, you're done with model part of defining view criteria with SysEffectiveDate. Now, implement search and search results in a jsff with this view criteria.<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://3.bp.blogspot.com/_ex9GjJ9fvbk/TReR7cuIeNI/AAAAAAAAAVk/ZEWnTmpB_QA/s1600/4.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="214" src="http://3.bp.blogspot.com/_ex9GjJ9fvbk/TReR7cuIeNI/AAAAAAAAAVk/ZEWnTmpB_QA/s320/4.JPG" style="cursor: move;" width="320" /></a></div><br />
5. To test the functionality, create multiple job records with different date-effective updates and try to search for a required job records specifying the Effective Date in the search criteria. You'll get the job records which match the query criteria as of the given effective date. Here are the sample screen shots.<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://2.bp.blogspot.com/_ex9GjJ9fvbk/TRowu0RViUI/AAAAAAAAAVo/MvlwqIyw0cQ/s1600/8.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="105" src="http://2.bp.blogspot.com/_ex9GjJ9fvbk/TRowu0RViUI/AAAAAAAAAVo/MvlwqIyw0cQ/s320/8.JPG" width="320" /></a></div><br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://2.bp.blogspot.com/_ex9GjJ9fvbk/TRowwVninvI/AAAAAAAAAVs/7WnnSXAmWXw/s1600/5.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="96" src="http://2.bp.blogspot.com/_ex9GjJ9fvbk/TRowwVninvI/AAAAAAAAAVs/7WnnSXAmWXw/s320/5.JPG" width="320" /></a></div><br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://4.bp.blogspot.com/_ex9GjJ9fvbk/TRowy4JsAvI/AAAAAAAAAV0/gDNuOnqPi_k/s1600/7.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="102" src="http://4.bp.blogspot.com/_ex9GjJ9fvbk/TRowy4JsAvI/AAAAAAAAAV0/gDNuOnqPi_k/s320/7.JPG" width="320" /></a></div><br />
6. If the effective date (SysEffectiveDate) is not provided, it'll return the rows effective as of today (i.e.,the system date on which search is made). Screen shot below.<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://2.bp.blogspot.com/_ex9GjJ9fvbk/TRowxrgftdI/AAAAAAAAAVw/ds7oZor6sSE/s1600/6.JPG" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="103" src="http://2.bp.blogspot.com/_ex9GjJ9fvbk/TRowxrgftdI/AAAAAAAAAVw/ds7oZor6sSE/s320/6.JPG" width="320" /></a></div><br />
Enjoy!!!Murali Papanahttp://www.blogger.com/profile/06991064825453310705noreply@blogger.com9tag:blogger.com,1999:blog-8389468608715252764.post-53597660972400984762010-12-26T09:06:00.000-08:002010-12-27T08:15:19.113-08:00ADF Model: Creating Date Effective Association and Date Effective VO<b><span class="Apple-style-span" style="font-weight: normal;">To learn the basics of date-effectivity in ADF, please go through my post</span><span class="Apple-style-span" style="font-weight: normal;"> </span><span class="Apple-style-span" style="font-weight: normal;"><a href="http://www.adftips.com/2010/12/learning-basics-of-date-effectivity-in.html">Learning basics of Date Effectivity in ADF</a>. To learn how to create date-effective EO, please go through my post <a href="http://www.adftips.com/2010/12/adf-model-creating-date-effective-eo.html">Creating Date Effective EO</a>.</span></b><br />
<br />
<b>Creating Date Effective Association:</b><br />
To have the basic idea of association between EOs, please go through my post <span class="Apple-style-span" style="color: #666666; font-family: Georgia, serif; font-size: 13px; line-height: 19px;"><a href="http://www.adftips.com/2010/09/adf-model-creating-entity-association.html" style="color: #5588aa; text-decoration: none;">ADF Model: Creating Entity Association</a></span>. But, by default the association created is not date-effective. But, if you're creating association between two EOs in which at least on of them is effective-dated, then you should mark the association as 'Effective Dated'. To make the association date-effective,<br />
<br />
1. Open Association -> Goto 'Relationship' tab -> Behavior -> Check 'Effective Dated Association' checkbox.<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://3.bp.blogspot.com/_ex9GjJ9fvbk/TRZE5m9KH4I/AAAAAAAAAVM/XwuqYf-iOPc/s1600/3.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="235" src="http://3.bp.blogspot.com/_ex9GjJ9fvbk/TRZE5m9KH4I/AAAAAAAAAVM/XwuqYf-iOPc/s320/3.JPG" width="320" /></a></div><div class="separator" style="clear: both; text-align: center;"></div>Marking the association 'Effective Dated Association' will take effective date into consideration while searching, inserting and updating the records.<br />
<br />
<b>Creating Date Effective VO:</b><br />
Creating date effective VO is same as creating <a href="http://www.adftips.com/2010/09/adf-model-creating-view-object-vo.html">normal VO</a>. In addition, we need to<br />
<br />
1. Mark the VO as date-effective by setting EffectiveDated='true' for the VO. You can find this property in 'General' tab property inspector.<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://2.bp.blogspot.com/_ex9GjJ9fvbk/TRZEMQG1lII/AAAAAAAAAU8/62sqUmm2D0Q/s1600/1.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="229" src="http://2.bp.blogspot.com/_ex9GjJ9fvbk/TRZEMQG1lII/AAAAAAAAAU8/62sqUmm2D0Q/s320/1.jpg" width="320" /></a></div><br />
Specifying the above property for the VO will generate a new transient attribute called <b>SysEffectiveDate</b> in the VO.<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://2.bp.blogspot.com/_ex9GjJ9fvbk/TRZENs0_FeI/AAAAAAAAAVA/rd96keDUj7g/s1600/2.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="251" src="http://2.bp.blogspot.com/_ex9GjJ9fvbk/TRZENs0_FeI/AAAAAAAAAVA/rd96keDUj7g/s320/2.JPG" width="320" /></a></div><br />
2.Optional: Change the data type of SysEffectiveDate attribute to 'java.sql.Date' from 'oracle.jbo.domain.Number'. We'll often find it easier with native Java sql data types instead of using Oracle's jbo datatypes. It is recommended to use java native sql type(java.sql.Date) for all date type attributes in the EO.<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://3.bp.blogspot.com/_ex9GjJ9fvbk/TRZEtlotn6I/AAAAAAAAAVI/oQ3RjhAPPPI/s1600/4.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="167" src="http://3.bp.blogspot.com/_ex9GjJ9fvbk/TRZEtlotn6I/AAAAAAAAAVI/oQ3RjhAPPPI/s320/4.JPG" width="320" /></a></div><br />
Marking the VO effective dated, will support date-effective updates for a single record.Murali Papanahttp://www.blogger.com/profile/06991064825453310705noreply@blogger.com33tag:blogger.com,1999:blog-8389468608715252764.post-61198755972856811352010-12-26T08:47:00.001-08:002011-01-01T12:46:57.311-08:00Learning basics of Date Effectivity in ADF<div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">This post explains the basics of date-effectivity which include mainly the basic date-effective operations like Date 'Effective Search', 'Date Effective Create', 'Date Effective Update' and 'Date Effective Delete'. But, it'll be easier to explain the concepts with examples.</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><br />
</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">So, here for example, I'm taking the simple example of HR admin, who can search/create/update/correct jobs. Let us assume, each job has a name, code and other attributes like job level, if the job requires medical checkup required, minimum salary, maximum salary, etc. What makes the job is date effective is that the attributes of job may change over the time, but still we need to be able to search the jobs based on the attributes that were applicable previously or that will be applicable in future.</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><br />
</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">For instance, let us take a job with Name 'Java Associate' which was created on 01-01-2000. When the job was created, the minimum salary for the job (minSal) was 10000 and maximum salary (maxSal) was 15000. But, on 01-01-2005, the job was revised and the management decided to move their technology to ADF and changed the job name to 'ADF Associate'.On 01-01-2010, the same job was revised and salary ranges were updated to minSal 25000 and maxSal 40000. Again, the management decided to change all Associate jobs to Developer Jobs from 01-01-2012 onwards (i.e., the job name will be changed from 'ADF Associate' to 'ADF Developer') etc.,</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><br />
</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">Here, the requirement is that if the user knows the name of the job applicable in 2000, he should be able to search the job as of that date. Similarly, if the user wants to search as of the current date or future dates, he should be able to search as well. That means we shouldn't simply update the existing values of the attributes as it will update the existing values and the previous values would be lost! We need to keep different versions of the attributes for the same job. So, how will it be possible as to have the multiple records with same JobId? Here comes EffectiveStartDate and EffectiveEndDate. Actually, we need to have a composite key based on JobId, EffectiveStartDate and EffectiveEndDate(i.e., the combination of these 3 attributes should be unique).</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><br />
</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"></div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">So, the data in the above requirement can be shown in table as follows. Changed attributes for each date-effective update are highlighted in <span class="Apple-style-span" style="background-color: yellow;">yellow.</span><br />
<span class="Apple-style-span" style="background-color: yellow;"><br />
</span></div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><div class="separator" style="clear: both; text-align: center;"><a href="http://1.bp.blogspot.com/_ex9GjJ9fvbk/TRdz3qf2-dI/AAAAAAAAAVU/xmsznJxz42Q/s1600/1.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="116" src="http://1.bp.blogspot.com/_ex9GjJ9fvbk/TRdz3qf2-dI/AAAAAAAAAVU/xmsznJxz42Q/s320/1.JPG" width="320" /></a></div><b><br />
</b></div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">If you see the above table, you'll notice that for any change in the Job attribute, we have new row with the corresponding EffectiveStartDate and EffectiveEndDate and there are no gaps in between. i.e., for any given date, only one record is applicable among multiple date-effective rows of a single Job record.</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><br />
</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">Now we'll see what date effectivity means in ADF for different operations on the records.</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><b>Date Effective Search:</b></div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">For example, if we want to find the jobs whose name starts with 'ADF%' as of date 01-01-2006. Or, we want to find out the jobs which will be applicable after 01-01-2012. Or, we want to find the minSal and maxSal for a given job as of 01-01-2007. Here, the results would change changing the Effective Dates as each job would have different values for the same attribute for different effective dates. Date-effective search will make all these possible. <a href="http://www.adftips.com/2010/12/adf-ui-implementing-date-effective.html">Date-effective search is explained with an example here</a>.</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><br />
</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><b>Date Effective Create:</b></div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">For example, we want to create a job that will be applicable in future say from 01-01-2013. Or, I want to create record which should be applicable from the past say 12-12-1900. Or, I want to create a new job which should be effective from today. Date-effective create makes all of these possible.</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><br />
</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><b>Date Effective Update:</b></div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">For example, we want to insert a new date-effective record for the job to represent a change in one of the attributes of the job. Say, I want to update the maxSal of the job with jobId 1001 to 20000 from 01-01-2008. This will insert a new record for the same job with EffectiveStartDate 01-01-2008 with maxSal 20000. <a href="http://www.adftips.com/2011/01/adf-model-different-date-effective.html">Different date-effective update modes and the corresponding behavior has been explained here</a>.</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><br />
</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><b>Date Effective Correct:</b></div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">For example, I want to correct or change one or more of the attributes of one of the date-effective rows of a single job record. Date Effective Correct operation just corrects the existing data. It won't insert any new date-effective rows. <a href="http://www.adftips.com/2011/01/adf-model-different-date-effective.html">You can find the example of DE correction mode here</a>.</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><br />
</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><b>Date Effective Delete:</b></div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">For example, we want to delete a single date-effective record out of multiple date-effective records of a job. For instance, we want to delete the job record [1001, 01-01-2005, 31-12-2009]. If the record is non-date effective, then deleting the row means deleting the entire record as there won't be multiple rows. But, in case of date-effective objects, if you want to delete entire record, you need to delete all date-effective rows of that record if any.</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"><br />
</div><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">Now, you understand the basics of date-effectivity in ADF. If you need any clarification, please leave a comment.</div>Murali Papanahttp://www.blogger.com/profile/06991064825453310705noreply@blogger.com32tag:blogger.com,1999:blog-8389468608715252764.post-1752598069109015932010-12-23T11:40:00.000-08:002010-12-26T20:03:40.681-08:00ADF Model: Creating Date Effective EODate-effectivity is an excellent feature available in Jdeveloper 11g. To learn the basics of date-effectivity in ADF, please go through my post <a href="http://www.adftips.com/2010/12/learning-basics-of-date-effectivity-in.html">Learning basic of Date Effectivity in ADF</a>. With Jdev 11g, we can create date-effective objects and do date-effective operations using simple API calls. Before going into all those details, the first requirement would be creating Date-Effective EO.<br />
<br />
The first requirement to create a DE-EO based on a table, the table should have two date columns to represent <b>Effective Start Date(ESD)</b> and<b> Effecitve End Date(EED)</b> of the record and these columns should be marked as primary keys along with id column. In other words, we need to define a composite key based on the id column and ESD and EED columns.<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://2.bp.blogspot.com/_ex9GjJ9fvbk/TROkvqPG1vI/AAAAAAAAAUY/ia6ev8r83eg/s1600/0.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="104" src="http://2.bp.blogspot.com/_ex9GjJ9fvbk/TROkvqPG1vI/AAAAAAAAAUY/ia6ev8r83eg/s320/0.JPG" style="cursor: move;" width="320" /></a></div><br />
Creating Date Effective EO is same as creating <a href="http://adftips.blogspot.com/2010/09/adf-model-creating-entity-object-eo.html">normal EO</a>. In addition, we need to do the following steps to make it date-effective.<br />
1. Mark the EO as Date Effective by specifying the attribute <b>Effective Date Type = 'EffectiveDated'</b>. You can find this property in 'General' tab property inspector.<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://1.bp.blogspot.com/_ex9GjJ9fvbk/TROkwlO2n4I/AAAAAAAAAUc/CM8bFqMML5A/s1600/1.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="224" src="http://1.bp.blogspot.com/_ex9GjJ9fvbk/TROkwlO2n4I/AAAAAAAAAUc/CM8bFqMML5A/s320/1.JPG" width="320" /></a></div><br />
This will generate a new transient attributte called '<b>SysEffectiveDate</b>' in the EO. Please find the screenshot below:<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://4.bp.blogspot.com/_ex9GjJ9fvbk/TROk0J_jLoI/AAAAAAAAAUo/L9GckDD4TmU/s1600/4.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="255" src="http://4.bp.blogspot.com/_ex9GjJ9fvbk/TROk0J_jLoI/AAAAAAAAAUo/L9GckDD4TmU/s320/4.JPG" width="320" /></a></div><br />
2. We need to specify which columns represent effective-date columns by checking the Check 'Effective Date' check box and selecting 'Start' and 'End' radio buttons for the effective-date columns which represent Effective Start Date and Effective End Date. Find the screen shots below:<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://4.bp.blogspot.com/_ex9GjJ9fvbk/TROkxwMLyoI/AAAAAAAAAUg/Xy4a6ahtQzQ/s1600/2.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="201" src="http://4.bp.blogspot.com/_ex9GjJ9fvbk/TROkxwMLyoI/AAAAAAAAAUg/Xy4a6ahtQzQ/s320/2.JPG" width="320" /></a></div><br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://1.bp.blogspot.com/_ex9GjJ9fvbk/TROky452FiI/AAAAAAAAAUk/JWq1W0ZY5zw/s1600/3.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="200" src="http://1.bp.blogspot.com/_ex9GjJ9fvbk/TROky452FiI/AAAAAAAAAUk/JWq1W0ZY5zw/s320/3.JPG" width="320" /></a></div><br />
3. Optional: Change the data type of SysEffectiveDate attribute to 'java.sql.Date' from 'oracle.jbo.domain.Number'. We'll often find it easier with native Java sql data types instead of using Oracle's jbo datatypes. It is recommended to use java native sql type(java.sql.Date) for all date type attributes in the EO.<br />
<br />
That's it. Now, your EO is date-effective and supports date-effective operations on it's rows.Murali Papanahttp://www.blogger.com/profile/06991064825453310705noreply@blogger.com25tag:blogger.com,1999:blog-8389468608715252764.post-10339594625247237502010-12-22T11:57:00.000-08:002010-12-24T10:57:47.426-08:00ADF Model: Getting attribute values from parent VO to child VO and vice versa using view link accessorsIn this post, let us see how to access parent VO attributes from child VO and child VO attributes from parent VO using view link. To have the basic idea about view links and how to create them, you can go through my blog post '<a href="http://www.adftips.com/2010/10/adf-model-creating-view-link.html">ADF Model: Creating View Link</a>'.<br />
<br />
<b>Example Use Case:</b><br />
For example we have two VOs DeptVO and EmpVO and both are linked via foreign key 'DeptId' using the view link EmpVOToDeptVO. Here, this relationship depicts the parent-child relationship using the foreign key DeptId. In other words, for a given current EmpVO(child) row, I need to know the DeptName from DeptVO(parent). Similarly, for a given current DeptVO(parent) row, I need to know all the empVO(child) rows. Sample application demonstrating this example can be downloaded from <a href="http://adftips.googlecode.com/files/ViewLinkAccessorExample.zip">here</a>.<br />
<br />
<b> Implementation Steps</b>:<br />
1. Create EmpVO and DeptVO and generate RowImpl classes for both of these two VOs.<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://4.bp.blogspot.com/_ex9GjJ9fvbk/TRJXX4hI3OI/AAAAAAAAATw/kqywWzXHSsQ/s1600/1.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://4.bp.blogspot.com/_ex9GjJ9fvbk/TRJXX4hI3OI/AAAAAAAAATw/kqywWzXHSsQ/s1600/1.JPG" /></a></div><br />
2. Now, create a new view link say DeptVOToEmpVO between these two VOs via foreign key DeptId.<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://2.bp.blogspot.com/_ex9GjJ9fvbk/TRJXYoxjdCI/AAAAAAAAAT0/5qcJMb7Si78/s1600/2.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="115" src="http://2.bp.blogspot.com/_ex9GjJ9fvbk/TRJXYoxjdCI/AAAAAAAAAT0/5qcJMb7Si78/s320/2.JPG" width="320" /></a></div><br />
3. In the view link definition, select options to generate accessors in both source and destination VOs. i.e., in DeptVO and EmpVO.<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://2.bp.blogspot.com/_ex9GjJ9fvbk/TRJXZnG4YLI/AAAAAAAAAT4/2sVH0PkxOso/s1600/3.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="196" src="http://2.bp.blogspot.com/_ex9GjJ9fvbk/TRJXZnG4YLI/AAAAAAAAAT4/2sVH0PkxOso/s320/3.JPG" width="320" /></a></div><br />
4. Checking the above options will generate accessor methods in EmpVORowImpl and DeptVORowImpl. The accessor's return type in each VO is based on the type of relationship between the VOs. In other words, as the relationship between Dept and Emp is 1-to-many, the accessor in DeptVORowImpl will return multiple Emp rows(i.e, the return type of the accessor will be RowIterator). And, the accessor in EmpVORowImpl will return a single row (as an employee can be in only one dept).<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://3.bp.blogspot.com/_ex9GjJ9fvbk/TRJXcWWXOpI/AAAAAAAAAUE/p7fOvomoybE/s1600/6.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="103" src="http://3.bp.blogspot.com/_ex9GjJ9fvbk/TRJXcWWXOpI/AAAAAAAAAUE/p7fOvomoybE/s320/6.JPG" width="320" /></a></div><br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://4.bp.blogspot.com/_ex9GjJ9fvbk/TRJXdo7bOiI/AAAAAAAAAUI/rGuJGDZm5nk/s1600/7.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="100" src="http://4.bp.blogspot.com/_ex9GjJ9fvbk/TRJXdo7bOiI/AAAAAAAAAUI/rGuJGDZm5nk/s320/7.JPG" width="320" /></a></div><br />
If you observe the source of EmpVO and DeptVO, you can also see that a tag is added in each of these VOs for the viewLinkAccessor.<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://3.bp.blogspot.com/_ex9GjJ9fvbk/TRJXarQ5W9I/AAAAAAAAAT8/bT46_qcJnAo/s1600/4.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="139" src="http://3.bp.blogspot.com/_ex9GjJ9fvbk/TRJXarQ5W9I/AAAAAAAAAT8/bT46_qcJnAo/s320/4.JPG" width="320" /></a></div><br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://2.bp.blogspot.com/_ex9GjJ9fvbk/TRJXbSImCJI/AAAAAAAAAUA/d1QpWOicKzs/s1600/5.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="162" src="http://2.bp.blogspot.com/_ex9GjJ9fvbk/TRJXbSImCJI/AAAAAAAAAUA/d1QpWOicKzs/s320/5.JPG" width="320" /></a></div><br />
5. Now, you can use these accessors to get reference EmpVO from DeptVO and vice versa. You can also get attribute values from the same. Sample codes below:<br />
<br />
Sample method in EmpVORowImpl to get the dept name.<br />
<div id="iframeDiv8d5b81fe-2c3e-4641-9970-ab6e14789b42" style="display: none; margin: 0px;"><iframe frameborder="0" id="iframe8d5b81fe-2c3e-4641-9970-ab6e14789b42" src="http://www.blogtrog.com/code.aspx?id=8d5b81fe-2c3e-4641-9970-ab6e14789b42" style="border: 1px solid #e0e0e0; height: 140px; margin: 0px; width: 400px;"></iframe></div><div id="noIframeDiv8d5b81fe-2c3e-4641-9970-ab6e14789b42" style="display: block; margin: 0px;"><pre><div><span style="color: black;"> </span><span style="color: blue;">public</span><span style="color: black;"> String getDeptNameViaViewLink() {
</span><span style="color: green;">//</span><span style="color: green;">Getting reference to deptVO row using the view link accessor getDeptVO1()</span><span style="color: green;">
</span><span style="color: black;"> Row deptRow </span><span style="color: black;">=</span><span style="color: black;"> </span><span style="color: blue;">this</span><span style="color: black;">.getDeptVO1();
</span><span style="color: green;">//</span><span style="color: green;">Getting the attribute 'Dname' value from the deptRow.</span><span style="color: green;">
</span><span style="color: black;"> </span><span style="color: blue;">return</span><span style="color: black;"> (String)deptRow.getAttribute(</span><span style="color: black;">"</span><span style="color: black;">Dname</span><span style="color: black;">"</span><span style="color: black;">);
}</span></div></pre></div><script language="javascript" src="http://www.blogtrog.com/scripts/bt_code.js" type="text/javascript">
</script><script language="javascript" type="text/javascript">
bt_code_init('8d5b81fe-2c3e-4641-9970-ab6e14789b42');
</script><br />
Sample method in DeptVORowImpl to get the list of employees in the dept.<br />
<div id="iframeDiv5144aa49-1c8c-4aef-a853-81ac089b90f7" style="display: none; margin: 0px;"><iframe frameborder="0" id="iframe5144aa49-1c8c-4aef-a853-81ac089b90f7" src="http://www.blogtrog.com/code.aspx?id=5144aa49-1c8c-4aef-a853-81ac089b90f7" style="border: 1px solid #e0e0e0; height: 280px; margin: 0px; width: 400px;"></iframe></div><div id="noIframeDiv5144aa49-1c8c-4aef-a853-81ac089b90f7" style="display: block; margin: 0px;"><pre><div><span style="color: black;"> </span><span style="color: blue;">public</span><span style="color: black;"> List getEmpNamesViaViewLink() {
</span><span style="color: green;">//</span><span style="color: green;">Getting reference to empVO row using the view link accessor getEmpVO()</span><span style="color: green;">
</span><span style="color: black;"> RowIterator empRowIterator </span><span style="color: black;">=</span><span style="color: black;"> </span><span style="color: blue;">this</span><span style="color: black;">.getEmpVO();
</span><span style="color: green;">//</span><span style="color: green;">Creating an empty List to store all emp names</span><span style="color: green;">
</span><span style="color: black;"> List empNames </span><span style="color: black;">=</span><span style="color: black;"> </span><span style="color: blue;">new</span><span style="color: black;"> ArrayList();
</span><span style="color: green;">//</span><span style="color: green;">iterating through all employee rows</span><span style="color: green;">
</span><span style="color: black;"> </span><span style="color: blue;">while</span><span style="color: black;">(empRowIterator.hasNext()){
</span><span style="color: green;">//</span><span style="color: green;">getting emp row one by one from the iterator</span><span style="color: green;">
</span><span style="color: black;"> Row empRow </span><span style="color: black;">=</span><span style="color: black;"> empRowIterator.next();
</span><span style="color: green;">//</span><span style="color: green;">adding emp name to the empNames list</span><span style="color: green;">
</span><span style="color: black;"> empNames.add(empRow.getAttribute(</span><span style="color: black;">"</span><span style="color: black;">Ename</span><span style="color: black;">"</span><span style="color: black;">));
}
</span><span style="color: green;">//</span><span style="color: green;">returning all empNames corresponding to the current dept</span><span style="color: green;">
</span><span style="color: black;"> </span><span style="color: blue;">return</span><span style="color: black;"> empNames;
}</span></div></pre></div><script language="javascript" src="http://www.blogtrog.com/scripts/bt_code.js" type="text/javascript">
</script><script language="javascript" type="text/javascript">
bt_code_init('5144aa49-1c8c-4aef-a853-81ac089b90f7');
</script><br />
<b>How to call/use these view link accessor methods in AMImpl methods?</b><br />
This should be now pretty straightforward. Here is the sample AMImpl method which prints emp names in each dept. The code is self-explanatory.<br />
<div id="iframeDiv9b64ed39-8a77-41f4-96ed-df2808af683f" style="display: none; margin: 0px;"><iframe frameborder="0" id="iframe9b64ed39-8a77-41f4-96ed-df2808af683f" src="http://www.blogtrog.com/code.aspx?id=9b64ed39-8a77-41f4-96ed-df2808af683f" style="border: 1px solid #e0e0e0; height: 300px; margin: 0px; width: 400px;"></iframe></div><div id="noIframeDiv9b64ed39-8a77-41f4-96ed-df2808af683f" style="display: block; margin: 0px;"><pre><div><span style="color: black;"> </span><span style="color: blue;">public</span><span style="color: black;"> </span><span style="color: blue;">void</span><span style="color: black;"> sampleMethod() {
</span><span style="color: green;">//</span><span style="color: green;">getting reference to deptVO</span><span style="color: green;">
</span><span style="color: black;"> ViewObjectImpl deptVO </span><span style="color: black;">=</span><span style="color: black;"> </span><span style="color: blue;">this</span><span style="color: black;">.getDeptVO();
</span><span style="color: green;">//</span><span style="color: green;">setting range size to -1 to get all dept rows</span><span style="color: green;">
</span><span style="color: black;"> deptVO.setRangeSize(</span><span style="color: black;">-</span><span style="color: black;">1</span><span style="color: black;">);
</span><span style="color: green;">//</span><span style="color: green;">getting all dept rows</span><span style="color: green;">
</span><span style="color: black;"> Row[] deptRows </span><span style="color: black;">=</span><span style="color: black;"> deptVO.getAllRowsInRange();
</span><span style="color: green;">//</span><span style="color: green;">iterating through all dept rows</span><span style="color: green;">
</span><span style="color: black;"> </span><span style="color: blue;">for</span><span style="color: black;"> (</span><span style="color: blue;">int</span><span style="color: black;"> i </span><span style="color: black;">=</span><span style="color: black;"> </span><span style="color: black;">0</span><span style="color: black;">; i </span><span style="color: black;"><</span><span style="color: black;"> deptRows.length; i</span><span style="color: black;">++</span><span style="color: black;">) {
</span><span style="color: green;">//</span><span style="color: green;">getting reference to each dept row. Note that we're type casting the VO reference type to DeptVORowImpl.</span><span style="color: green;">
</span><span style="color: black;"> DeptVORowImpl deptRow </span><span style="color: black;">=</span><span style="color: black;"> (DeptVORowImpl)deptRows[i];
</span><span style="color: green;">//</span><span style="color: green;">printing dept name</span><span style="color: green;">
</span><span style="color: black;"> System.out.println(</span><span style="color: black;">"</span><span style="color: black;">Employees in dept: </span><span style="color: black;">"</span><span style="color: black;"> </span><span style="color: black;">+</span><span style="color: black;">
deptRow.getAttribute(</span><span style="color: black;">"</span><span style="color: black;">Dname</span><span style="color: black;">"</span><span style="color: black;">));
</span><span style="color: green;">//</span><span style="color: green;">For each dept row, getting reference to empVO which contains all employees corresponding to current dept</span><span style="color: green;">
</span><span style="color: black;"> RowIterator empRows </span><span style="color: black;">=</span><span style="color: black;"> deptRow.getEmpVO();
</span><span style="color: green;">//</span><span style="color: green;">iterating each emp row</span><span style="color: green;">
</span><span style="color: black;"> </span><span style="color: blue;">while</span><span style="color: black;"> (empRows.hasNext()) {
Row empRow </span><span style="color: black;">=</span><span style="color: black;"> empRows.next();
</span><span style="color: green;">//</span><span style="color: green;">printing emp name from each row</span><span style="color: green;">
</span><span style="color: black;"> System.out.println(empRow.getAttribute(</span><span style="color: black;">"</span><span style="color: black;">Ename</span><span style="color: black;">"</span><span style="color: black;">));
}
}
}</span></div></pre></div><script language="javascript" src="http://www.blogtrog.com/scripts/bt_code.js" type="text/javascript">
</script><script language="javascript" type="text/javascript">
bt_code_init('9b64ed39-8a77-41f4-96ed-df2808af683f');
</script><br />
Here is the sample output in console on running the above AMImpl method.<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://4.bp.blogspot.com/_ex9GjJ9fvbk/TRJXeaHd5QI/AAAAAAAAAUM/IxokluGrkoc/s1600/8.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://4.bp.blogspot.com/_ex9GjJ9fvbk/TRJXeaHd5QI/AAAAAAAAAUM/IxokluGrkoc/s1600/8.JPG" /></a></div><br />
<br />
That's it. Now, you got the idea how to use view link accessors to get the values of child attributes from parent and vice versa. Enjoy!Murali Papanahttp://www.blogger.com/profile/06991064825453310705noreply@blogger.com17tag:blogger.com,1999:blog-8389468608715252764.post-61989815099766353602010-11-25T06:35:00.000-08:002010-11-26T04:52:18.218-08:00ADF Model: Executing view accessor programaticallyIn this post, I'll show how to execute a VO(or it's view criteria) added as a view accessor in another VO. <br />
<br />
<b>Sample Use case:</b><br />
For example we have two VOs DeptVO(based on only DeptEO) and EmpDeptVO(based on empEO and DeptEO) and the DeptVO is added a view accessor in EmpDeptVO and we need to programmatically execute this view accessor to get the Deptno for the passed Dname (assuming it DeptVO has a view criteria that takes Dname as a parameter or bind variable) and set the DetpNo for the newly created row in EmpDeptVO. You can download the sample application from <a href="http://adftips.googlecode.com/files/ExecutingViewAccessor.zip">here</a>.<br />
<br />
<b>Implementation Steps:</b><br />
1. Create DeptVO based on DeptEO and create a view criteria "findByDeptName" that queries based on the bind variable 'Bind_Dname'.<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://1.bp.blogspot.com/_ex9GjJ9fvbk/TO5zfIraL2I/AAAAAAAAAR4/DSbTSOI64Cc/s1600/1.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="247" src="http://1.bp.blogspot.com/_ex9GjJ9fvbk/TO5zfIraL2I/AAAAAAAAAR4/DSbTSOI64Cc/s320/1.JPG" width="320" /></a></div><br />
2. Create EmpDeptVO and add the DeptVO as view accessor (DeptVA) and select the view criteria "findByDeptName" in the VA definition.<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://1.bp.blogspot.com/_ex9GjJ9fvbk/TO5zgTIsD3I/AAAAAAAAAR8/qi9F5Dmu1K8/s1600/2.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="277" src="http://1.bp.blogspot.com/_ex9GjJ9fvbk/TO5zgTIsD3I/AAAAAAAAAR8/qi9F5Dmu1K8/s320/2.JPG" width="320" /></a></div><br />
3. Generate RowImpl class for EmpDeptVO. The generated class name will be EmpDeptVORowImpl.<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://4.bp.blogspot.com/_ex9GjJ9fvbk/TO5zgw75szI/AAAAAAAAASA/MwvVFU7Rl60/s1600/3.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://4.bp.blogspot.com/_ex9GjJ9fvbk/TO5zgw75szI/AAAAAAAAASA/MwvVFU7Rl60/s1600/3.JPG" /></a></div><br />
4. Now, write a method say "getDeptIdFromViewAccessor" in EmpDeptVORowImpl that takes 'Dname' as parameter that executes the view accessor DeptVA and returns the DeptId for the passed 'Dname'. Code below:<br />
<div id="iframeDiv58984e33-c3cc-4189-87f3-b069009d6c53" style="display: none; margin: 0px;"><iframe frameborder="0" id="iframe58984e33-c3cc-4189-87f3-b069009d6c53" src="http://www.blogtrog.com/code.aspx?id=58984e33-c3cc-4189-87f3-b069009d6c53" style="border: 1px solid rgb(224, 224, 224); height: 270px; margin: 0px; width: 400px;"></iframe></div><div id="noIframeDiv58984e33-c3cc-4189-87f3-b069009d6c53" style="display: block; margin: 0px;"><pre><div><span style="color: black;"> </span><span style="color: blue;">public</span><span style="color: black;"> Object getDeptIdFromViewAccessor(String deptName) {
</span><span style="color: green;">//</span><span style="color: green;">here getDeptVA is the getter for the view accessor 'DeptVA' in EmpDeptVO</span><span style="color: green;">
</span><span style="color: black;"> RowSet rowSet </span><span style="color: black;">=</span><span style="color: black;"> </span><span style="color: blue;">this</span><span style="color: black;">.getDeptVA();
</span><span style="color: green;">//</span><span style="color: green;">setting the range size to -1 to get all the rows</span><span style="color: green;">
</span><span style="color: black;"> rowSet.setRangeSize(</span><span style="color: black;">-</span><span style="color: black;">1</span><span style="color: black;">);
</span><span style="color: green;">//</span><span style="color: green;">passing the value for bind parameter for the view accessor</span><span style="color: green;">
</span><span style="color: black;"> rowSet.setNamedWhereClauseParam(</span><span style="color: black;">"</span><span style="color: black;">Bind_Dname</span><span style="color: black;">"</span><span style="color: black;">, deptName);
</span><span style="color: green;">//</span><span style="color: green;">executing the view accessor</span><span style="color: green;">
</span><span style="color: black;"> rowSet.executeQuery();
</span><span style="color: green;">//</span><span style="color: green;">storing the first row in the row set in deptRow (there can be multiple rows in the row set based on the criteria)</span><span style="color: green;">
</span><span style="color: black;"> Row deptRow </span><span style="color: black;">=</span><span style="color: black;"> rowSet.first();
</span><span style="color: green;">//</span><span style="color: green;">if the dpetRow is not null, returning the Deptno</span><span style="color: green;">
</span><span style="color: black;"> </span><span style="color: blue;">return</span><span style="color: black;"> (deptRow </span><span style="color: black;">!=</span><span style="color: black;"> </span><span style="color: blue;">null</span><span style="color: black;">) </span><span style="color: black;">?</span><span style="color: black;"> deptRow.getAttribute(</span><span style="color: black;">"</span><span style="color: black;">Deptno</span><span style="color: black;">"</span><span style="color: black;">) : </span><span style="color: blue;">null</span><span style="color: black;">;
}</span></div></pre></div><script language="javascript" src="http://www.blogtrog.com/scripts/bt_code.js" type="text/javascript">
</script><script language="javascript" type="text/javascript">
bt_code_init('58984e33-c3cc-4189-87f3-b069009d6c53');
</script><br />
<br />
5. Call the above EmpDeptVORowImpl method in AmImpl's method say "testExecuteViewAccessor" passing the Dname for which the DeptId is required. Now, set this deptId to the newly created EmpDeptVO row in AMImpl method. Code below:<br />
<div id="iframeDiv17bfd20b-a986-4911-adf0-f282427d1260" style="display: none; margin: 0px;"><iframe frameborder="0" id="iframe17bfd20b-a986-4911-adf0-f282427d1260" src="http://www.blogtrog.com/code.aspx?id=17bfd20b-a986-4911-adf0-f282427d1260" style="border: 1px solid rgb(224, 224, 224); height: 220px; margin: 0px; width: 400px;"></iframe></div><div id="noIframeDiv17bfd20b-a986-4911-adf0-f282427d1260" style="display: block; margin: 0px;"><pre><div><span style="color: black;"> </span><span style="color: blue;">public</span><span style="color: black;"> </span><span style="color: blue;">void</span><span style="color: black;"> testExecuteViewAccessor(){
ViewObjectImpl empDeptVO </span><span style="color: black;">=</span><span style="color: black;"> </span><span style="color: blue;">this</span><span style="color: black;">.getEmpDeptVO();
Row row </span><span style="color: black;">=</span><span style="color: black;"> empDeptVO.createRow();
empDeptVO.insertRow(row);
EmpDeptVORowImpl empDeptRow </span><span style="color: black;">=</span><span style="color: black;"> (EmpDeptVORowImpl)empDeptVO.getCurrentRow();
</span><span style="color: green;">//</span><span style="color: green;">calling the EmpDeptVORowImpl method to get the deptId for the deptName 'accounting'</span><span style="color: green;">
</span><span style="color: black;"> Object deptId </span><span style="color: black;">=</span><span style="color: black;"> empDeptRow.getDeptIdFromViewAccessor(</span><span style="color: black;">"</span><span style="color: black;">accounting</span><span style="color: black;">"</span><span style="color: black;">);
System.out.println(</span><span style="color: black;">"</span><span style="color: black;">DeptId from view accessor: </span><span style="color: black;">"</span><span style="color: black;">+</span><span style="color: black;">deptId);
</span><span style="color: green;">//</span><span style="color: green;">setting the deptId to the current row's 'Deptno' attribute.</span><span style="color: green;">
</span><span style="color: black;"> empDeptRow.setDeptno((Number)deptId);
}</span></div></pre></div><script language="javascript" src="http://www.blogtrog.com/scripts/bt_code.js" type="text/javascript">
</script><script language="javascript" type="text/javascript">
bt_code_init('17bfd20b-a986-4911-adf0-f282427d1260');
</script><br />
<br />
Here is the sample output on running this method using AM tester.<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://4.bp.blogspot.com/_ex9GjJ9fvbk/TO51_BeWavI/AAAAAAAAASE/vv6_9-wPHG8/s1600/4.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="82" src="http://4.bp.blogspot.com/_ex9GjJ9fvbk/TO51_BeWavI/AAAAAAAAASE/vv6_9-wPHG8/s320/4.JPG" width="320" /></a></div><br />
That's it. Now you know how to execute the view accessor(VA) programatically, how to pass the parameters for the view criteria selected in VA definition, how to get and use the results in AMImpl methods.<br />
<br />
PS: DeptId and Deptno are used interchangeably in this post.Murali Papanahttp://www.blogger.com/profile/06991064825453310705noreply@blogger.com9tag:blogger.com,1999:blog-8389468608715252764.post-4496432091033953692010-11-11T20:10:00.000-08:002010-11-11T20:18:53.170-08:00ADF UI - selectionListener example for single-select af:tableThere are situations when we require to perform some action on selecting a row in a single-select table. For such cases, we need to remove the default selectionListener and specify our own selectionListener method from the backing bean and write our logic within the method.<br />
<br />
The generated default selectionListener for the table would be like <b>selectionListener="#{bindings.EmpDeptVO.collectionModel.makeCurrent}"</b>. This will actually make the selected row as current row. As we're removing the default selectionListener, we need to call the same default selection listener method in the custom selectionListener method. Then only we can get handle to the selected row.<br />
<br />
<b>Sample Use Case:</b><br />
Suppose I have employees table and when I select a row in the table, immediately I need to show a popup with the selected employee name. Sample application can be downloaded from <a href="http://adftips.googlecode.com/files/SelectionListenerExample.zip">here</a>.<br />
<br />
<b>Implementation Steps:</b><br />
1. Drop the VO as a table in the jsf page. Remove the default selectionListener and specify your own backing bean method for the selectionListener.<br />
<div id="iframeDivd6423e58-57e4-4e8b-b628-c85e893625b4" style="display: none; margin: 0px;"><iframe frameborder="0" id="iframed6423e58-57e4-4e8b-b628-c85e893625b4" src="http://www.blogtrog.com/code.aspx?id=d6423e58-57e4-4e8b-b628-c85e893625b4" style="border: 1px solid #e0e0e0; height: 250px; margin: 0px; width: 400px;"></iframe></div><div id="noIframeDivd6423e58-57e4-4e8b-b628-c85e893625b4" style="display: block; margin: 0px;"><pre><div><span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">af:table </span><span style="color: red;">value</span><span style="color: blue;">="#{bindings.EmpDeptVO.collectionModel}"</span><span style="color: red;"> var</span><span style="color: blue;">="row"</span><span style="color: red;">
rows</span><span style="color: blue;">="#{bindings.EmpDeptVO.rangeSize}"</span><span style="color: red;">
emptyText</span><span style="color: blue;">="#{bindings.EmpDeptVO.viewable ? 'No data to display.' : 'Access Denied.'}"</span><span style="color: red;">
fetchSize</span><span style="color: blue;">="#{bindings.EmpDeptVO.rangeSize}"</span><span style="color: red;">
rowBandingInterval</span><span style="color: blue;">="0"</span><span style="color: red;">
rowSelection</span><span style="color: blue;">="single"</span><span style="color: red;"> id</span><span style="color: blue;">="t1"</span><span style="color: red;">
partialTriggers</span><span style="color: blue;">=":::qryId1 ::ctb1 ::commandToolbarButton1"</span><span style="color: red;">
columnStretching</span><span style="color: blue;">="column:c1"</span><span style="color: red;">
styleClass</span><span style="color: blue;">="AFStretchWidth"</span><span style="color: red;"> columnSelection</span><span style="color: blue;">="multiple"</span><span style="color: red;">
first</span><span style="color: blue;">="0"</span><span style="color: red;"> contentDelivery</span><span style="color: blue;">="immediate"</span><span style="color: red;"> autoHeightRows</span><span style="color: blue;">="10"</span><span style="color: red;">
binding</span><span style="color: blue;">="#{pageFlowScope.ExampleBean.searchResultsTable}"</span><span style="color: red;">
selectionListener</span><span style="color: blue;">="#{pageFlowScope.ExampleBean.rowSelected}"</span><span style="color: blue;">></span></div></pre></div><script language="javascript" src="http://www.blogtrog.com/scripts/bt_code.js" type="text/javascript">
</script><script language="javascript" type="text/javascript">
bt_code_init('d6423e58-57e4-4e8b-b628-c85e893625b4');
</script><br />
2. In the custom selectionListener method, call the default selectionListener method which will set the selected row as the current row. We can use ADFUtil.invokeEL() to invoke the same default EL expression method and the selectionEvent as the parameter. Sample code below.<br />
<div id="iframeDiv9f0c0bd5-80e9-4614-81a7-9921022760a1" style="display: none; margin: 0px;"><iframe frameborder="0" id="iframe9f0c0bd5-80e9-4614-81a7-9921022760a1" src="http://www.blogtrog.com/code.aspx?id=9f0c0bd5-80e9-4614-81a7-9921022760a1" style="border: 1px solid #e0e0e0; height: 100px; margin: 0px; width: 400px;"></iframe></div><div id="noIframeDiv9f0c0bd5-80e9-4614-81a7-9921022760a1" style="display: block; margin: 0px;"><pre><div><span style="color: black;"> ADFUtil.invokeEL(</span><span style="color: black;">"</span><span style="color: black;">#{bindings.EmpDeptVO.collectionModel.makeCurrent}</span><span style="color: black;">"</span><span style="color: black;">,
</span><span style="color: blue;">new</span><span style="color: black;"> Class[] { SelectionEvent.</span><span style="color: blue;">class</span><span style="color: black;"> },
</span><span style="color: blue;">new</span><span style="color: black;"> Object[] { selectionEvent });</span></div></pre></div><script language="javascript" src="http://www.blogtrog.com/scripts/bt_code.js" type="text/javascript">
</script><script language="javascript" type="text/javascript">
bt_code_init('9f0c0bd5-80e9-4614-81a7-9921022760a1');
</script><br />
3. Now, the selected row is set as current row and you can get the current row reference by using the below EL. Now, you can get all attributes of the selected row by using the above reference.<br />
<div id="iframeDiv56c2cf9c-f09f-402c-8c8d-2126d200e1e1" style="display: none; margin: 0px;"><iframe frameborder="0" id="iframe56c2cf9c-f09f-402c-8c8d-2126d200e1e1" src="http://www.blogtrog.com/code.aspx?id=56c2cf9c-f09f-402c-8c8d-2126d200e1e1" style="border: 1px solid #e0e0e0; height: 90px; margin: 0px; width: 400px;"></iframe></div><div id="noIframeDiv56c2cf9c-f09f-402c-8c8d-2126d200e1e1" style="display: block; margin: 0px;"><pre><div><span style="color: black;">Row selectedRow </span><span style="color: black;">=</span><span style="color: black;">
(Row)ADFUtil.evaluateEL(</span><span style="color: black;">"</span><span style="color: black;">#{bindings.EmpDeptVOIterator.currentRow}</span><span style="color: black;">"</span><span style="color: black;">);</span></div></pre></div><script language="javascript" src="http://www.blogtrog.com/scripts/bt_code.js" type="text/javascript">
</script><script language="javascript" type="text/javascript">
bt_code_init('56c2cf9c-f09f-402c-8c8d-2126d200e1e1');
</script><br />
4. Get the attribute value of Ename from the selected row and set it to a pageFlowScope variable say #{pageFlowScope.empName}. Add a popup in the jsf page that displays the #{pageFlowScope.empName} as the selected employee. Write your logic to invoke the popup in the same selectionListener method.<br />
<br />
Popup code in the jsf page:<br />
<div id="iframeDivce861abf-c30b-4a58-be28-169aa915a21b" style="display: none; margin: 0px;"><iframe frameborder="0" id="iframece861abf-c30b-4a58-be28-169aa915a21b" src="http://www.blogtrog.com/code.aspx?id=ce861abf-c30b-4a58-be28-169aa915a21b" style="border: 1px solid #e0e0e0; height: 150px; margin: 0px; width: 400px;"></iframe></div><div id="noIframeDivce861abf-c30b-4a58-be28-169aa915a21b" style="display: block; margin: 0px;"><pre><div><span style="color: blue;"><</span><span style="color: maroon;">af:popup </span><span style="color: red;">id</span><span style="color: blue;">="p1"</span><span style="color: red;"> binding</span><span style="color: blue;">="#{pageFlowScope.ExampleBean.displayNamePopup}"</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: blue;"><</span><span style="color: maroon;">af:dialog </span><span style="color: red;">id</span><span style="color: blue;">="d1"</span><span style="color: red;"> type</span><span style="color: blue;">="ok"</span><span style="color: red;"> title</span><span style="color: blue;">="Alert"</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: blue;"><</span><span style="color: maroon;">af:outputText </span><span style="color: red;">value</span><span style="color: blue;">="You have selected Employee: #{pageFlowScope.empName}"</span><span style="color: red;">
id</span><span style="color: blue;">="ot4"</span><span style="color: blue;">/></span><span style="color: black;">
</span><span style="color: blue;"></</span><span style="color: maroon;">af:dialog</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: blue;"></</span><span style="color: maroon;">af:popup</span><span style="color: blue;">></span></div></pre></div><script language="javascript" src="http://www.blogtrog.com/scripts/bt_code.js" type="text/javascript">
</script><script language="javascript" type="text/javascript">
bt_code_init('ce861abf-c30b-4a58-be28-169aa915a21b');
</script><br />
<b>Backing bean containing the selectionListener method and popup binding:</b><br />
<div id='iframeDiv2ff7338b-8d04-4ea3-9ea0-2ab591f1f910' style='display:none;margin:0px;'><iframe id='iframe2ff7338b-8d04-4ea3-9ea0-2ab591f1f910' src='http://www.blogtrog.com/code.aspx?id=2ff7338b-8d04-4ea3-9ea0-2ab591f1f910' style='width: 400px; height: 400px; border: 1px solid #e0e0e0;margin:0px;' frameborder='0'></iframe></div><div id='noIframeDiv2ff7338b-8d04-4ea3-9ea0-2ab591f1f910' style='display:block;margin:0px;'><pre><div><!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
--><span style="color: #0000FF;">public</span><span style="color: #000000;"> </span><span style="color: #0000FF;">class</span><span style="color: #000000;"> ExampleBean {
</span><span style="color: #0000FF;">private</span><span style="color: #000000;"> RichPopup displayNamePopup;
</span><span style="color: #0000FF;">public</span><span style="color: #000000;"> </span><span style="color: #0000FF;">void</span><span style="color: #000000;"> rowSelected(SelectionEvent selectionEvent) {
ADFUtil.invokeEL(</span><span style="color: #000000;">"</span><span style="color: #000000;">#{bindings.EmpDeptVO.collectionModel.makeCurrent}</span><span style="color: #000000;">"</span><span style="color: #000000;">,
</span><span style="color: #0000FF;">new</span><span style="color: #000000;"> Class[] { SelectionEvent.</span><span style="color: #0000FF;">class</span><span style="color: #000000;"> },
</span><span style="color: #0000FF;">new</span><span style="color: #000000;"> Object[] { selectionEvent });
Row selectedRow </span><span style="color: #000000;">=</span><span style="color: #000000;">
(Row)ADFUtil.evaluateEL(</span><span style="color: #000000;">"</span><span style="color: #000000;">#{bindings.EmpDeptVOIterator.currentRow}</span><span style="color: #000000;">"</span><span style="color: #000000;">);
ADFUtil.setEL(</span><span style="color: #000000;">"</span><span style="color: #000000;">#{pageFlowScope.empName}</span><span style="color: #000000;">"</span><span style="color: #000000;">,
selectedRow.getAttribute(</span><span style="color: #000000;">"</span><span style="color: #000000;">Ename</span><span style="color: #000000;">"</span><span style="color: #000000;">));
PopupUtil.invokePopup(displayNamePopup.getClientId(FacesContext.getCurrentInstance()));
;
}
</span><span style="color: #0000FF;">public</span><span style="color: #000000;"> </span><span style="color: #0000FF;">void</span><span style="color: #000000;"> setDisplayNamePopup(RichPopup displayNamePopup) {
</span><span style="color: #0000FF;">this</span><span style="color: #000000;">.displayNamePopup </span><span style="color: #000000;">=</span><span style="color: #000000;"> displayNamePopup;
}
</span><span style="color: #0000FF;">public</span><span style="color: #000000;"> RichPopup getDisplayNamePopup() {
</span><span style="color: #0000FF;">return</span><span style="color: #000000;"> displayNamePopup;
}
}
</span></div></pre></div><script language='javascript' src='http://www.blogtrog.com/scripts/bt_code.js' type='text/javascript'></script><script language='javascript' type='text/javascript'>bt_code_init('2ff7338b-8d04-4ea3-9ea0-2ab591f1f910');</script><br />
That's it. When the row is selected, the selectionListener method in the bean is called, current row is set to selected row, stores the current row's Ename attribute to pageFlowScope variable 'empName', invoke the popup programatically, and the same pageFlowScope variable will be displayed in the popup as selected employee name.<br />
<br />
<b>Sample screen shots:</b><br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://4.bp.blogspot.com/_ex9GjJ9fvbk/TNy9FP3xwnI/AAAAAAAAAQI/l-B2cY6RkeU/s1600/1.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="52" src="http://4.bp.blogspot.com/_ex9GjJ9fvbk/TNy9FP3xwnI/AAAAAAAAAQI/l-B2cY6RkeU/s320/1.JPG" width="320" /></a></div><br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://4.bp.blogspot.com/_ex9GjJ9fvbk/TNy9GAj8PsI/AAAAAAAAAQM/iEV3W_dTlwc/s1600/2.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="53" src="http://4.bp.blogspot.com/_ex9GjJ9fvbk/TNy9GAj8PsI/AAAAAAAAAQM/iEV3W_dTlwc/s320/2.JPG" width="320" /></a></div>Murali Papanahttp://www.blogger.com/profile/06991064825453310705noreply@blogger.com8tag:blogger.com,1999:blog-8389468608715252764.post-41948107717326756152010-11-10T11:33:00.000-08:002010-11-11T03:14:25.529-08:00ADF UI - Creating dropdown or menu buttonsCreating dropdown or menu buttons using ADF is easy. A dropdown menu button is the button with a dropdown icon which will display list of menu items on clicking the button or dropdown icon. Just go through the below steps to create a menu button.<br />
<br />
1. Add a af:commandButton or af:toolbarButton where you need to dropdown button. Now, in the '<b>popup</b>' facet, drag and drop <b>af:menu</b> and add af:menu item(i.e.,<b> af:commandMenuItem</b>)s to the af:menu. Sample code below:<br />
<div id="iframeDiv3a6f97da-2f2b-42e9-a84d-670d034b0e02" style="display: none; margin: 0px;"><iframe frameborder="0" id="iframe3a6f97da-2f2b-42e9-a84d-670d034b0e02" src="http://www.blogtrog.com/code.aspx?id=3a6f97da-2f2b-42e9-a84d-670d034b0e02" style="border: 1px solid #e0e0e0; height: 270px; margin: 0px; width: 400px;"></iframe></div><div id="noIframeDiv3a6f97da-2f2b-42e9-a84d-670d034b0e02" style="display: block; margin: 0px;"><pre><div><span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">af:commandToolbarButton </span><span style="color: red;">text</span><span style="color: blue;">="Options"</span><span style="color: red;"> id</span><span style="color: blue;">="commandToolbarButton1"</span><span style="color: red;">
disabled</span><span style="color: blue;">="#{bindings.EmpDeptVO.currentRow==null}"</span><span style="color: red;">
partialTriggers</span><span style="color: blue;">="t1"</span><span style="color: red;">
actionDelivery</span><span style="color: blue;">="none"</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: blue;"><</span><span style="color: maroon;">f:facet </span><span style="color: red;">name</span><span style="color: blue;">="popup"</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: blue;"><</span><span style="color: maroon;">af:menu </span><span style="color: red;">id</span><span style="color: blue;">="m1"</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: blue;"><</span><span style="color: maroon;">af:commandMenuItem </span><span style="color: red;">text</span><span style="color: blue;">="View"</span><span style="color: red;"> id</span><span style="color: blue;">="cmi1"</span><span style="color: red;"> action</span><span style="color: blue;">="view"</span><span style="color: blue;">/></span><span style="color: black;">
</span><span style="color: blue;"><</span><span style="color: maroon;">af:commandMenuItem </span><span style="color: red;">text</span><span style="color: blue;">="Edit"</span><span style="color: red;"> id</span><span style="color: blue;">="cmi2"</span><span style="color: red;"> action</span><span style="color: blue;">="edit"</span><span style="color: blue;">/></span><span style="color: black;">
</span><span style="color: blue;"><</span><span style="color: maroon;">af:commandMenuItem </span><span style="color: red;">text</span><span style="color: blue;">="Delete"</span><span style="color: red;"> id</span><span style="color: blue;">="cmi3"</span><span style="color: red;">
actionListener</span><span style="color: blue;">="#{bindings.Delete.execute}"</span><span style="color: red;">
partialTriggers</span><span style="color: blue;">="t1"</span><span style="color: blue;">/></span><span style="color: black;">
</span><span style="color: blue;"></</span><span style="color: maroon;">af:menu</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: blue;"></</span><span style="color: maroon;">f:facet</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: blue;"></</span><span style="color: maroon;">af:commandToolbarButton</span><span style="color: blue;">></span></div></pre></div><script language="javascript" src="http://www.blogtrog.com/scripts/bt_code.js" type="text/javascript">
</script><script language="javascript" type="text/javascript">
bt_code_init('3a6f97da-2f2b-42e9-a84d-670d034b0e02');
</script><br />
The above code in Structure window will look like this:<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://4.bp.blogspot.com/_ex9GjJ9fvbk/TNrx0CWshBI/AAAAAAAAAP8/XYkc2M28-Ho/s1600/1.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://4.bp.blogspot.com/_ex9GjJ9fvbk/TNrx0CWshBI/AAAAAAAAAP8/XYkc2M28-Ho/s1600/1.JPG" /></a></div><br />
2. The above code will render the menu button as shown below:<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://1.bp.blogspot.com/_ex9GjJ9fvbk/TNrx1ho5FJI/AAAAAAAAAQE/iMQ0O15E46g/s1600/3.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://1.bp.blogspot.com/_ex9GjJ9fvbk/TNrx1ho5FJI/AAAAAAAAAQE/iMQ0O15E46g/s1600/3.JPG" /></a></div><br />
<b>3. There are two types of menu buttons:</b><br />
i. Which will display dropdown list or menu items <b>on clicking the 'dropdown' icon</b>. This button will have a separator (vertical line '|') between the button text and the dropdown icon. It'll look like below. This is actually the default behavior. You can specify action and actionListener for this button and on clicking the button it'll cause navigation or fire actionListener based on the specified action and actionListener respectively.<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://2.bp.blogspot.com/_ex9GjJ9fvbk/TNrx0982LuI/AAAAAAAAAQA/vM9MbHJF6Mg/s1600/2.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://2.bp.blogspot.com/_ex9GjJ9fvbk/TNrx0982LuI/AAAAAAAAAQA/vM9MbHJF6Mg/s1600/2.JPG" /></a></div><br />
<br />
ii. Which will display drowdown list <b>on clicking the button itself</b>. This button won't have a separator (vertical line '|') between the button text and the dropdown icon. It'll look like below. To get this behavior, you need to set <b>actionDelivery="none"</b> for the button. <b>If you set this property, you can't specify either action or actionListener for the button</b> as it won't fire either action or actionListener.<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://1.bp.blogspot.com/_ex9GjJ9fvbk/TNrx1ho5FJI/AAAAAAAAAQE/iMQ0O15E46g/s1600/3.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://1.bp.blogspot.com/_ex9GjJ9fvbk/TNrx1ho5FJI/AAAAAAAAAQE/iMQ0O15E46g/s1600/3.JPG" /></a></div><br />
That's it. You can specify action and actionListener for the menu items in the dropdown menu and do whatever you want.Murali Papanahttp://www.blogger.com/profile/06991064825453310705noreply@blogger.com6tag:blogger.com,1999:blog-8389468608715252764.post-65049972662121706972010-11-07T07:12:00.000-08:002010-11-11T03:22:38.927-08:00ADF UI - Getting all pagedef attributes of a particular VO iterator programatically (find transients among them as well :) )This might be rare requirement to get handle on pagedef attributes of a particular VO iterator. But, it would be quite useful for some scenarios like when you want to get the values of attributes of a particular iterator present in the current jsff page (not each and every VO attribute) and compare them with the original values to know if the user has changed the attribute through the UI. It would be waste of effort to check all VO attributes if they're changed as the user can only change the attributes present in the UI jsff pages. <br />
<br />
But, it's not as easy as getting a reference to bindings (DCBindingContainer) and call the method getAttributeBindngs() on it. Even though it returns all the pagedef attribute bindings, they'll include attributes of all VO iterators in the pagedef. The tricky part is to get attributes of only a particular VO iterator in the pagedef. Here, in this post, I'll explain how to do that.<br />
<br />
I did some research and wrote the a method to retrieve all the pagedef attributes of the VO iterator specified by 'VOName' as a parameter. This method also has the logic to find out the transient attributes present the VO. This would be quite useful when you want to find out the transient attributes of a VOIterator in the pagedef and to do logic on them (like skipping them for comparision, etc.,).<br />
<br />
Method code in the bean:<br />
<div id="iframeDiv614be0d7-8503-455e-8d02-dc5ee3d7c601" style="display: none; margin: 0px;"><iframe frameborder="0" id="iframe614be0d7-8503-455e-8d02-dc5ee3d7c601" src="http://www.blogtrog.com/code.aspx?id=614be0d7-8503-455e-8d02-dc5ee3d7c601" style="border: 1px solid #e0e0e0; height: 300px; margin: 0px; width: 400px;"></iframe></div><div id="noIframeDiv614be0d7-8503-455e-8d02-dc5ee3d7c601" style="display: block; margin: 0px;"><pre><div><span style="color: black;"> </span><span style="color: blue;">public</span><span style="color: black;"> </span><span style="color: blue;">void</span><span style="color: black;"> storePageDefAttrs(String VOName) {
DCBindingContainer binding </span><span style="color: black;">=</span><span style="color: black;">
(DCBindingContainer)ADFUtil.evaluateEL(</span><span style="color: black;">"</span><span style="color: black;">#{bindings}</span><span style="color: black;">"</span><span style="color: black;">);
</span><span style="color: green;">//</span><span style="color: green;">getting the attribute bindings in the pagedef, it'll contain all pagedef attribute bindings of all VO iterators in pagedef</span><span style="color: green;">
</span><span style="color: black;"> List attrBindings </span><span style="color: black;">=</span><span style="color: black;"> binding.getAttributeBindings();
</span><span style="color: green;">//</span><span style="color: green;">getting iterator for attribute bindings</span><span style="color: green;">
</span><span style="color: black;"> Iterator itr </span><span style="color: black;">=</span><span style="color: black;"> attrBindings.iterator();
</span><span style="color: green;">//</span><span style="color: green;">getting the current row for the VOName</span><span style="color: green;">
</span><span style="color: black;"> ViewRowImpl row </span><span style="color: black;">=</span><span style="color: black;">
(ViewRowImpl)ADFUtil.evaluateEL(</span><span style="color: black;">"</span><span style="color: black;">#{bindings.</span><span style="color: black;">"</span><span style="color: black;"> </span><span style="color: black;">+</span><span style="color: black;"> VOName </span><span style="color: black;">+</span><span style="color: black;">
</span><span style="color: black;">"</span><span style="color: black;">Iterator.currentRow}</span><span style="color: black;">"</span><span style="color: black;">);
</span><span style="color: green;">//</span><span style="color: green;">pageDefAttrs will store pageDef attribute names for the given VO specified by 'VOName'</span><span style="color: green;">
</span><span style="color: black;"> List pageDefAttrs </span><span style="color: black;">=</span><span style="color: black;"> </span><span style="color: blue;">new</span><span style="color: black;"> ArrayList();
</span><span style="color: green;">//</span><span style="color: green;">transientAttrs will store trasient attribute names added in the pagedef for the given VO specified by 'VOName'</span><span style="color: green;">
</span><span style="color: black;"> List transientAttrs </span><span style="color: black;">=</span><span style="color: black;"> </span><span style="color: blue;">new</span><span style="color: black;"> ArrayList();
</span><span style="color: green;">//</span><span style="color: green;">iterating through all attribute bindings</span><span style="color: green;">
</span><span style="color: black;"> </span><span style="color: blue;">while</span><span style="color: black;"> (itr.hasNext()) {
AttributeBinding attrBinding </span><span style="color: black;">=</span><span style="color: black;"> (AttributeBinding)itr.next();
</span><span style="color: green;">//</span><span style="color: green;">getting the attribute name</span><span style="color: green;">
</span><span style="color: black;"> String attrName </span><span style="color: black;">=</span><span style="color: black;"> attrBinding.getName();
</span><span style="color: green;">//</span><span style="color: green;">getting the iterator binding for the attribute</span><span style="color: green;">
</span><span style="color: black;"> DCIteratorBinding attrIterBinding </span><span style="color: black;">=</span><span style="color: black;">
(DCIteratorBinding)ADFUtil.evaluateEL(</span><span style="color: black;">"</span><span style="color: black;">#{bindings.</span><span style="color: black;">"</span><span style="color: black;"> </span><span style="color: black;">+</span><span style="color: black;">
attrName </span><span style="color: black;">+</span><span style="color: black;">
</span><span style="color: black;">"</span><span style="color: black;">.iteratorBinding}</span><span style="color: black;">"</span><span style="color: black;">);
</span><span style="color: green;">//</span><span style="color: green;">getting the iterator name for the iterator binding</span><span style="color: green;">
</span><span style="color: black;"> String attrIterBidningName </span><span style="color: black;">=</span><span style="color: black;"> attrIterBinding.getVOName();
</span><span style="color: green;">//</span><span style="color: green;">checking if this attribute's iterator name is equal to the passed VOName</span><span style="color: green;">
</span><span style="color: black;"> </span><span style="color: blue;">if</span><span style="color: black;"> (VOName.equals(attrIterBidningName)) {
</span><span style="color: green;">//</span><span style="color: green;">if the attributes' iterator name is equal to passed VOName, this attributes belongs to the VO specified by 'VOName'. So adding it to pageDefAttrs.</span><span style="color: green;">
</span><span style="color: black;"> pageDefAttrs.add(attrName);
</span><span style="color: green;">//</span><span style="color: green;">getting the attribute index</span><span style="color: green;">
</span><span style="color: black;"> </span><span style="color: blue;">int</span><span style="color: black;"> attrIndex </span><span style="color: black;">=</span><span style="color: black;"> row.getAttributeIndexOf(attrName);
</span><span style="color: green;">//</span><span style="color: green;">getting the view attribute definition</span><span style="color: green;">
</span><span style="color: black;"> ViewAttributeDefImpl vDef </span><span style="color: black;">=</span><span style="color: black;">
(ViewAttributeDefImpl)row.getViewDef().getAttributeDef(attrIndex);
</span><span style="color: green;">//</span><span style="color: green;">checking if it's a transient attribute.</span><span style="color: green;">
</span><span style="color: black;"> </span><span style="color: blue;">boolean</span><span style="color: black;"> transientPageDefAttr </span><span style="color: black;">=</span><span style="color: black;">
(vDef.getEntityAttributeDef() </span><span style="color: black;">==</span><span style="color: black;"> </span><span style="color: blue;">null</span><span style="color: black;">) </span><span style="color: black;">||</span><span style="color: black;">
(vDef.getEntityAttributeDef().getColumnName() </span><span style="color: black;">==</span><span style="color: black;"> </span><span style="color: blue;">null</span><span style="color: black;">);
</span><span style="color: green;">//</span><span style="color: green;">if it's transient, adding it to transientAttrs list</span><span style="color: green;">
</span><span style="color: black;"> </span><span style="color: blue;">if</span><span style="color: black;"> (transientPageDefAttr) {
transientAttrs.add(attrName);
}
}
}
</span><span style="color: green;">//</span><span style="color: green;">stroing the pagedef attribute names and transient attribute names for the given VOName in the pageFlowScope variables.</span><span style="color: green;">
</span><span style="color: black;"> ADFUtil.setEL(</span><span style="color: black;">"</span><span style="color: black;">#{pageFlowScope.pageDefAttrs}</span><span style="color: black;">"</span><span style="color: black;">, pageDefAttrs);
ADFUtil.setEL(</span><span style="color: black;">"</span><span style="color: black;">#{pageFlowScope.trasientPageDefAttrs}</span><span style="color: black;">"</span><span style="color: black;">, transientAttrs);
</span><span style="color: black;">
}</span></div></pre></div><script language="javascript" src="http://www.blogtrog.com/scripts/bt_code.js" type="text/javascript">
</script><script language="javascript" type="text/javascript">
bt_code_init('614be0d7-8503-455e-8d02-dc5ee3d7c601');
</script><br />
The above code is self explanatory from the comments inline. It takes 'VOName' as a parameter and finally stores all pagedef attributes(including transients) for that VO in the ArrayList 'pageDefAttrs'. It'll also store transient attributes of the VO in the ArrayList 'transientAttrs'.<br />
<br />
I devloped a sample application that prints the all attributes and transient attributes present in the pagedef. When you <a href="http://adftips.googlecode.com/files/GettingPageDefAttributes.zip">download</a> and run the application, it'll open a search page. Search for a record and select one row and click on 'Edit' button. Now, you'll goto edit page and when you click on 'Show Pagedef Attributes' button, it'll print all attributes as well as the transient attributes present in the pagedef.<br />
<br />
Attributes in EmpDeptVO definition:<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://3.bp.blogspot.com/_ex9GjJ9fvbk/TNa-a69G7_I/AAAAAAAAAPg/EhXF6Lq2J0U/s1600/1.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="258" src="http://3.bp.blogspot.com/_ex9GjJ9fvbk/TNa-a69G7_I/AAAAAAAAAPg/EhXF6Lq2J0U/s320/1.JPG" width="320" /></a></div><br />
Attributes in DeptVO definition:<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://4.bp.blogspot.com/_ex9GjJ9fvbk/TNa-bUVaBuI/AAAAAAAAAPk/7ZxzSvHq_TA/s1600/2.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://4.bp.blogspot.com/_ex9GjJ9fvbk/TNa-bUVaBuI/AAAAAAAAAPk/7ZxzSvHq_TA/s1600/2.JPG" /></a></div><br />
<br />
Pagedef file containing some of the attributes from EmpDeptVO and DeptVO:<br />
<div id="iframeDiv84b7d153-a267-4967-9bce-fc06430ca0ab" style="display: none; margin: 0px;"><iframe frameborder="0" id="iframe84b7d153-a267-4967-9bce-fc06430ca0ab" src="http://www.blogtrog.com/code.aspx?id=84b7d153-a267-4967-9bce-fc06430ca0ab" style="border: 1px solid #e0e0e0; height: 400px; margin: 0px; width: 400px;"></iframe></div><div id="noIframeDiv84b7d153-a267-4967-9bce-fc06430ca0ab" style="display: block; margin: 0px;"><pre><div><span style="color: blue;"><?</span><span style="color: magenta;">xml version="1.0" encoding="UTF-8" </span><span style="color: blue;">?></span><span style="color: black;">
</span><span style="color: blue;"><</span><span style="color: maroon;">pageDefinition </span><span style="color: red;">xmlns</span><span style="color: blue;">="http://xmlns.oracle.com/adfm/uimodel"</span><span style="color: red;">
version</span><span style="color: blue;">="11.1.1.56.60"</span><span style="color: red;"> id</span><span style="color: blue;">="EditEmployeePageDef"</span><span style="color: red;">
Package</span><span style="color: blue;">="com.demo.fragments"</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: blue;"><</span><span style="color: maroon;">parameters</span><span style="color: blue;">/></span><span style="color: black;">
</span><span style="color: blue;"><</span><span style="color: maroon;">executables</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: blue;"><</span><span style="color: maroon;">variableIterator </span><span style="color: red;">id</span><span style="color: blue;">="variables"</span><span style="color: blue;">/></span><span style="color: black;">
</span><span style="color: blue;"><</span><span style="color: maroon;">iterator </span><span style="color: red;">Binds</span><span style="color: blue;">="EmpDeptVO"</span><span style="color: red;"> RangeSize</span><span style="color: blue;">="25"</span><span style="color: red;"> DataControl</span><span style="color: blue;">="DemoAMDataControl"</span><span style="color: red;">
id</span><span style="color: blue;">="EmpDeptVOIterator"</span><span style="color: blue;">/></span><span style="color: black;">
</span><span style="color: blue;"><</span><span style="color: maroon;">iterator </span><span style="color: red;">Binds</span><span style="color: blue;">="DeptVO"</span><span style="color: red;"> RangeSize</span><span style="color: blue;">="25"</span><span style="color: red;"> DataControl</span><span style="color: blue;">="DemoAMDataControl"</span><span style="color: red;">
id</span><span style="color: blue;">="DeptVOIterator"</span><span style="color: blue;">/></span><span style="color: black;">
</span><span style="color: blue;"></</span><span style="color: maroon;">executables</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: blue;"><</span><span style="color: maroon;">bindings</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: blue;"><</span><span style="color: maroon;">attributeValues </span><span style="color: red;">IterBinding</span><span style="color: blue;">="EmpDeptVOIterator"</span><span style="color: red;"> id</span><span style="color: blue;">="Ename"</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: blue;"><</span><span style="color: maroon;">AttrNames</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: blue;"><</span><span style="color: maroon;">Item </span><span style="color: red;">Value</span><span style="color: blue;">="Ename"</span><span style="color: blue;">/></span><span style="color: black;">
</span><span style="color: blue;"></</span><span style="color: maroon;">AttrNames</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: blue;"></</span><span style="color: maroon;">attributeValues</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: blue;"><</span><span style="color: maroon;">attributeValues </span><span style="color: red;">IterBinding</span><span style="color: blue;">="EmpDeptVOIterator"</span><span style="color: red;"> id</span><span style="color: blue;">="Job"</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: blue;"><</span><span style="color: maroon;">AttrNames</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: blue;"><</span><span style="color: maroon;">Item </span><span style="color: red;">Value</span><span style="color: blue;">="Job"</span><span style="color: blue;">/></span><span style="color: black;">
</span><span style="color: blue;"></</span><span style="color: maroon;">AttrNames</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: blue;"></</span><span style="color: maroon;">attributeValues</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: blue;"><</span><span style="color: maroon;">attributeValues </span><span style="color: red;">IterBinding</span><span style="color: blue;">="EmpDeptVOIterator"</span><span style="color: red;"> id</span><span style="color: blue;">="Loc"</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: blue;"><</span><span style="color: maroon;">AttrNames</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: blue;"><</span><span style="color: maroon;">Item </span><span style="color: red;">Value</span><span style="color: blue;">="Loc"</span><span style="color: blue;">/></span><span style="color: black;">
</span><span style="color: blue;"></</span><span style="color: maroon;">AttrNames</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: blue;"></</span><span style="color: maroon;">attributeValues</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: blue;"><</span><span style="color: maroon;">attributeValues </span><span style="color: red;">IterBinding</span><span style="color: blue;">="EmpDeptVOIterator"</span><span style="color: red;"> id</span><span style="color: blue;">="Mgr"</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: blue;"><</span><span style="color: maroon;">AttrNames</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: blue;"><</span><span style="color: maroon;">Item </span><span style="color: red;">Value</span><span style="color: blue;">="Mgr"</span><span style="color: blue;">/></span><span style="color: black;">
</span><span style="color: blue;"></</span><span style="color: maroon;">AttrNames</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: blue;"></</span><span style="color: maroon;">attributeValues</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: blue;"><</span><span style="color: maroon;">attributeValues </span><span style="color: red;">IterBinding</span><span style="color: blue;">="DeptVOIterator"</span><span style="color: red;"> id</span><span style="color: blue;">="Dname"</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: blue;"><</span><span style="color: maroon;">AttrNames</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: blue;"><</span><span style="color: maroon;">Item </span><span style="color: red;">Value</span><span style="color: blue;">="Dname"</span><span style="color: blue;">/></span><span style="color: black;">
</span><span style="color: blue;"></</span><span style="color: maroon;">AttrNames</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: blue;"></</span><span style="color: maroon;">attributeValues</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: blue;"><</span><span style="color: maroon;">attributeValues </span><span style="color: red;">IterBinding</span><span style="color: blue;">="DeptVOIterator"</span><span style="color: red;"> id</span><span style="color: blue;">="Loc1"</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: blue;"><</span><span style="color: maroon;">AttrNames</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: blue;"><</span><span style="color: maroon;">Item </span><span style="color: red;">Value</span><span style="color: blue;">="Loc"</span><span style="color: blue;">/></span><span style="color: black;">
</span><span style="color: blue;"></</span><span style="color: maroon;">AttrNames</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: blue;"></</span><span style="color: maroon;">attributeValues</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: blue;"><</span><span style="color: maroon;">attributeValues </span><span style="color: red;">IterBinding</span><span style="color: blue;">="EmpDeptVOIterator"</span><span style="color: red;"> id</span><span style="color: blue;">="attribute1"</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: blue;"><</span><span style="color: maroon;">AttrNames</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: blue;"><</span><span style="color: maroon;">Item </span><span style="color: red;">Value</span><span style="color: blue;">="attribute1"</span><span style="color: blue;">/></span><span style="color: black;">
</span><span style="color: blue;"></</span><span style="color: maroon;">AttrNames</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: blue;"></</span><span style="color: maroon;">attributeValues</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: blue;"><</span><span style="color: maroon;">attributeValues </span><span style="color: red;">IterBinding</span><span style="color: blue;">="EmpDeptVOIterator"</span><span style="color: red;"> id</span><span style="color: blue;">="attribute2"</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: blue;"><</span><span style="color: maroon;">AttrNames</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: blue;"><</span><span style="color: maroon;">Item </span><span style="color: red;">Value</span><span style="color: blue;">="attribute2"</span><span style="color: blue;">/></span><span style="color: black;">
</span><span style="color: blue;"></</span><span style="color: maroon;">AttrNames</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: blue;"></</span><span style="color: maroon;">attributeValues</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: blue;"></</span><span style="color: maroon;">bindings</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: blue;"></</span><span style="color: maroon;">pageDefinition</span><span style="color: blue;">></span></div></pre></div><script language="javascript" src="http://www.blogtrog.com/scripts/bt_code.js" type="text/javascript">
</script><script language="javascript" type="text/javascript">
bt_code_init('84b7d153-a267-4967-9bce-fc06430ca0ab');
</script><br />
<a href="http://1.bp.blogspot.com/_ex9GjJ9fvbk/TNa-bwbGKiI/AAAAAAAAAPo/f-JmGTFaGm4/s1600/3.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="278" src="http://1.bp.blogspot.com/_ex9GjJ9fvbk/TNa-bwbGKiI/AAAAAAAAAPo/f-JmGTFaGm4/s320/3.JPG" style="cursor: move;" width="320" /></a><br />
<br />
Ouptput attributes on running the sample application:<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://2.bp.blogspot.com/_ex9GjJ9fvbk/TNbAjLtKEBI/AAAAAAAAAPs/DHa8OjAssZA/s1600/4.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="54" src="http://2.bp.blogspot.com/_ex9GjJ9fvbk/TNbAjLtKEBI/AAAAAAAAAPs/DHa8OjAssZA/s320/4.JPG" width="320" /></a></div><br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://2.bp.blogspot.com/_ex9GjJ9fvbk/TNbAj5KWaWI/AAAAAAAAAPw/Sh6s7HUGnIg/s1600/5.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="127" src="http://2.bp.blogspot.com/_ex9GjJ9fvbk/TNbAj5KWaWI/AAAAAAAAAPw/Sh6s7HUGnIg/s320/5.JPG" width="320" /></a></div><br />
So, from the above screen shot you can see our method printed the EmpDeptVO's attributes and transient attributes present in the pagdef correctly.<br />
<br />
Enjoy :) !<br />
<br />
PS: In case, if you're aware of better approach than the above one, please share with me too. Thank you :)Murali Papanahttp://www.blogger.com/profile/06991064825453310705noreply@blogger.com6tag:blogger.com,1999:blog-8389468608715252764.post-57656013243876635362010-11-06T06:07:00.000-07:002010-11-11T03:25:06.302-08:00ADF UI - Region Interaction: From parent page to child region task flowIf you drop a task flow as a region in a jsf page and if you want to refresh the task flow region based on some action in the jsf, please go through this post. <br />
<br />
<b>Sample UseCase:</b><br />
For example if a Jsf Page contains departments table and on selecting a department from the table and click on button 'Show Employees', it should display the employees in the selected department. But suppose the employee details should come from a different task flow. We need to establish the communication between the parent jsf page and the task flow region in it. Sample application for this example can be downloaded from <a href="http://adftips.googlecode.com/files/RegionInteraction_ParentToChild.zip">here</a>.<br />
<br />
<b>Implementation Steps:</b><br />
<br />
<b>Task flow refresh Principle:</b><br />
<i>If you drop a task flow that takes some parameters as a region in a jsff page, the task flow binding will be added in the pagedef file. If you set refresh='ifNeeded' for the task flow binding, the task flow will be re-executed each time when the value for one of the passed parameters got changed. To be clear, here re-execution means the task-flow will re-execute from it's default activity in the task flow diagram.</i><br />
<br />
This example depends on the above principle.<br />
<br />
1. Create a jsff page and include departments table and add a button 'Show Employees'.<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://1.bp.blogspot.com/_ex9GjJ9fvbk/TNVQ1094kNI/AAAAAAAAAPQ/_VQfMf0VcRk/s1600/1.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="212" src="http://1.bp.blogspot.com/_ex9GjJ9fvbk/TNVQ1094kNI/AAAAAAAAAPQ/_VQfMf0VcRk/s320/1.JPG" width="320" /></a></div>2. Create a task flow that takes deptId as parameter and fetches the employees present the given department and shows them in a table.<br />
<br />
Task flow diagram with input parameter deptId:<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://3.bp.blogspot.com/_ex9GjJ9fvbk/TNVSA5LAoFI/AAAAAAAAAPU/Ef77WuGdCwo/s1600/2.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="197" src="http://3.bp.blogspot.com/_ex9GjJ9fvbk/TNVSA5LAoFI/AAAAAAAAAPU/Ef77WuGdCwo/s320/2.JPG" width="320" /></a></div><br />
3. Specify actionListener for the 'Show Employees' button and in the actionListener method, get the deptId selected in departments table and set to to a pageFlowScope variable.<br />
<br />
Java bean containing the actionListener method for 'Show Employees' button:<br />
<div id="iframeDiva88dc28a-7fdc-4ba6-b36c-96e09abd1adf" style="display: none; margin: 0px;"><iframe frameborder="0" id="iframea88dc28a-7fdc-4ba6-b36c-96e09abd1adf" src="http://www.blogtrog.com/code.aspx?id=a88dc28a-7fdc-4ba6-b36c-96e09abd1adf" style="border: 1px solid #e0e0e0; height: 250px; margin: 0px; width: 400px;"></iframe></div><div id="noIframeDiva88dc28a-7fdc-4ba6-b36c-96e09abd1adf" style="display: block; margin: 0px;"><pre><div><span style="color: blue;">public</span><span style="color: black;"> </span><span style="color: blue;">class</span><span style="color: black;"> ExampleBean {
</span><span style="color: blue;">private</span><span style="color: black;"> Integer deptId;
</span><span style="color: blue;">public</span><span style="color: black;"> </span><span style="color: blue;">void</span><span style="color: black;"> buttonClicked(ActionEvent ae){
Row currentDeptRow</span><span style="color: black;">=</span><span style="color: black;">(Row)ADFUtil.evaluateEL(</span><span style="color: black;">"</span><span style="color: black;">#{bindings.DeptVO.currentRow}</span><span style="color: black;">"</span><span style="color: black;">);
ADFUtil.setEL(</span><span style="color: black;">"</span><span style="color: black;">#{pageFlowScope.deptId}</span><span style="color: black;">"</span><span style="color: black;">,currentDeptRow.getAttribute(</span><span style="color: black;">"</span><span style="color: black;">Deptno</span><span style="color: black;">"</span><span style="color: black;">));
}
</span><span style="color: blue;">public</span><span style="color: black;"> </span><span style="color: blue;">void</span><span style="color: black;"> setDeptId(Integer deptId) {
</span><span style="color: blue;">this</span><span style="color: black;">.deptId </span><span style="color: black;">=</span><span style="color: black;"> deptId;
}
</span><span style="color: blue;">public</span><span style="color: black;"> Integer getDeptId() {
</span><span style="color: blue;">return</span><span style="color: black;"> deptId;
}
}</span></div></pre></div><script language="javascript" src="http://www.blogtrog.com/scripts/bt_code.js" type="text/javascript">
</script><script language="javascript" type="text/javascript">
bt_code_init('a88dc28a-7fdc-4ba6-b36c-96e09abd1adf');
</script><br />
<br />
4. Drop the employee details task flow as a region in the jsf page. Pass the same above pageFlowScope variable as a parameter to the dropped taskflow. Specify <b>refresh="ifNeeded"</b> for the task flow binding in pagedef. <br />
<br />
Task flow binding in the pagedef:<br />
<br />
<div id="iframeDiv35ea4aaf-469d-4a8f-b990-5c565e11f3fa" style="display: none; margin: 0px;"><iframe frameborder="0" id="iframe35ea4aaf-469d-4a8f-b990-5c565e11f3fa" src="http://www.blogtrog.com/code.aspx?id=35ea4aaf-469d-4a8f-b990-5c565e11f3fa" style="border: 1px solid #e0e0e0; height: 180px; margin: 0px; width: 400px;"></iframe></div><div id="noIframeDiv35ea4aaf-469d-4a8f-b990-5c565e11f3fa" style="display: block; margin: 0px;"><pre><div><span style="color: black;"> </span><span style="color: blue;"><</span><span style="color: maroon;">taskFlow </span><span style="color: red;">id</span><span style="color: blue;">="TaskFlow21"</span><span style="color: red;">
taskFlowId<span style="color: blue;">="/com/demo/taskflows/TaskFlow2.xml#TaskFlow2"</span><span style="color: red;"></span>
xmlns<span style="color: blue;">="http://xmlns.oracle.com/adf/controller/binding"</span><span style="color: red;"></span>
Refresh<span style="color: blue;">="ifNeeded"</span><span style="color: red;"> activation</span><span style="color: blue;">="deferred"</span><span style="color: blue;">></span><span style="color: black;"></span>
<span style="color: blue;"><</span><span style="color: maroon;">parameters</span><span style="color: blue;">></span><span style="color: black;"></span>
<span style="color: blue;"><</span><span style="color: maroon;">parameter </span><span style="color: red;">id</span><span style="color: blue;">="deptId"</span><span style="color: red;"> value</span><span style="color: blue;">="#{pageFlowScope.deptId}"</span><span style="color: blue;">/></span><span style="color: black;"></span>
<span style="color: blue;"></</span><span style="color: maroon;">parameters</span><span style="color: blue;">></span><span style="color: black;"></span>
<span style="color: blue;"></</span><span style="color: maroon;">taskFlow</span><span style="color: blue;">></span></span></div></pre></div><script language="javascript" src="http://www.blogtrog.com/scripts/bt_code.js" type="text/javascript">
</script><script language="javascript" type="text/javascript">
bt_code_init('35ea4aaf-469d-4a8f-b990-5c565e11f3fa');
</script><br />
<br />
That's it. This is how it works: When the user selects department in jsff and clicks on 'Show Employees' button, the actionListener method sets the pageFlowScope variable with the deptId selected and the same will be passed to the dropped task flow. As the task flow re-executes if any of it's input parameter changes, the employees will be queried based on passed deptId and the task flow will refreshed with the corresponding employee details. No 'partialTriggers' is required in this case. Refresh of task flow will be triggered automatically when the input parameter value is changed.<br />
<br />
Sample screen shots:<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://3.bp.blogspot.com/_ex9GjJ9fvbk/TNVSq9_vxrI/AAAAAAAAAPY/w6Fj4P5gdYc/s1600/4.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="97" src="http://3.bp.blogspot.com/_ex9GjJ9fvbk/TNVSq9_vxrI/AAAAAAAAAPY/w6Fj4P5gdYc/s320/4.JPG" width="320" /></a></div><br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://2.bp.blogspot.com/_ex9GjJ9fvbk/TNVSsSe5m1I/AAAAAAAAAPc/7QEVaznykaw/s1600/3.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="107" src="http://2.bp.blogspot.com/_ex9GjJ9fvbk/TNVSsSe5m1I/AAAAAAAAAPc/7QEVaznykaw/s320/3.JPG" width="320" /></a></div>Murali Papanahttp://www.blogger.com/profile/06991064825453310705noreply@blogger.com13tag:blogger.com,1999:blog-8389468608715252764.post-81468285210695676412010-11-05T11:53:00.000-07:002010-11-11T03:46:19.201-08:00ADF UI - Region Interaction: Between two peer region task flows present in a single parent pageGenerally, if we want to refresh a field or part of the page, we use ppr (partial page rendering) in ADF. We just specify the id of the component (<b>whose state change should trigger refresh</b>) for the partialTriggers property of the <b>required component to be refreshed</b>. It's that simple. But, when we use task flows as regions in our pages, many times we need to establish communication between the parent page containing the region and the region itself. Similarly if there are two regions in the same jsff and some times we need to refresh one region based on some actin done on another region. Here, in this post I'm going to explain this case.<br />
<br />
<b>Sample UseCase:</b><br />
For example, we have two task flows- one task flow displays the departments in a table and the second task flow shows the employees present in department for which the Deptno is passed as a task flow parameter. Now, the requirement is that based on the department selected in the first region, the second region needs to be refreshed with the employees in that particular selected department provided these two regions are dropped in a single jsf page. Sample example application can be downloaded from <a href="http://adftips.googlecode.com/files/RegionInteraction_peers.zip">here</a>. Here, actually we're establishing a communication between the two regions present in the same jsf page.<br />
<br />
<b>Implementation Details:</b><br />
Before going through the implmentation steps, lets have a quick review of task flow basics.<br />
<br />
<i>If you drop a task flow that takes some parameters as a region in a jsff page, the task flow binding will be added in the pagedef file. If you set refresh='ifNeeded' for the task flow binding, the task flow will be re-executed each time when the value for one of the passed parameters got changed. To be clear, here re-execution means the task-flow will re-execute from it's default activity in the task flow diagram.</i><br />
<br />
In other words, if you drop task flow TF that takes parameters param1,param2 in a jsf page abc.jsff, and if you specify refresh='ifNeeded' for the task flow binding in pagdef, and if you give the values for param1 and param2 as #{pageFlowScope.param1} and #{pageFlowScope.param2}, the task flow will be re-executed if any of the pageflowScope param values changed to a different value. <br />
<br />
Knowing the above point is very important to implement interaction between two regions. <br />
<br />
<b>Implementation Steps:</b><br />
1. Make two task flows ready - <br />
i. TaskFlow1 - This task flow displays departments table with a button 'Show Employees'. <br />
ii. TaskFlow2 - This task flow takes a parameter deptId and based on the passed deptId, it'll query the employees in the dept and displays them in a table.<br />
<br />
TaskFlow2 Diagram:<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://3.bp.blogspot.com/_ex9GjJ9fvbk/TNRQBxWgNvI/AAAAAAAAAO0/5pQZL5bWwgA/s1600/1.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="227" src="http://3.bp.blogspot.com/_ex9GjJ9fvbk/TNRQBxWgNvI/AAAAAAAAAO0/5pQZL5bWwgA/s320/1.JPG" width="320" /></a></div><br />
2. Create a java bean with the property deptId and generate accessors for it. Now, <a href="http://www.adftips.com/2010/11/adf-ui-beginner-creating-data-control.html">create data control for the bean</a>. <br />
<br />
Java bean containing the property 'deptId':<br />
<div id="iframeDiva54671ca-8202-4f5e-b6e3-b34dc8586501" style="display: none; margin: 0px;"><iframe frameborder="0" id="iframea54671ca-8202-4f5e-b6e3-b34dc8586501" src="http://www.blogtrog.com/code.aspx?id=a54671ca-8202-4f5e-b6e3-b34dc8586501" style="border: 1px solid #e0e0e0; height: 190px; margin: 0px; width: 400px;"></iframe></div><div id="noIframeDiva54671ca-8202-4f5e-b6e3-b34dc8586501" style="display: block; margin: 0px;"><pre><div><span style="color: blue;">package</span><span style="color: black;"> com.demo.beans;
</span><span style="color: blue;">public</span><span style="color: black;"> </span><span style="color: blue;">class</span><span style="color: black;"> SharedBean {
</span><span style="color: blue;">private</span><span style="color: black;"> Integer deptId;
</span><span style="color: blue;">public</span><span style="color: black;"> </span><span style="color: blue;">void</span><span style="color: black;"> setDeptId(Integer deptId) {
</span><span style="color: blue;">this</span><span style="color: black;">.deptId </span><span style="color: black;">=</span><span style="color: black;"> deptId;
}
</span><span style="color: blue;">public</span><span style="color: black;"> Integer getDeptId() {
</span><span style="color: blue;">return</span><span style="color: black;"> deptId;
}
}
</span></div></pre></div><script language="javascript" src="http://www.blogtrog.com/scripts/bt_code.js" type="text/javascript">
</script><script language="javascript" type="text/javascript">
bt_code_init('a54671ca-8202-4f5e-b6e3-b34dc8586501');
</script><br />
3. Now, in the actionListener method for 'Show Employees' button in task flow1, just get the selected deptId and set to the shared bean data control property.<br />
<br />
ActionListener method code:<br />
<div id="iframeDiv9f6c3a23-9755-4111-9a15-3c58ab3a3805" style="display: none; margin: 0px;"><iframe frameborder="0" id="iframe9f6c3a23-9755-4111-9a15-3c58ab3a3805" src="http://www.blogtrog.com/code.aspx?id=9f6c3a23-9755-4111-9a15-3c58ab3a3805" style="border: 1px solid #e0e0e0; height: 150px; margin: 0px; width: 400px;"></iframe></div><div id="noIframeDiv9f6c3a23-9755-4111-9a15-3c58ab3a3805" style="display: block; margin: 0px;"><pre><div><span style="color: black;"> </span><span style="color: blue;">public</span><span style="color: black;"> </span><span style="color: blue;">void</span><span style="color: black;"> buttonClicked(ActionEvent ae) {
Row currentDeptRow </span><span style="color: black;">=</span><span style="color: black;">
(Row)ADFUtil.evaluateEL(</span><span style="color: black;">"</span><span style="color: black;">#{bindings.DeptVO.currentRow}</span><span style="color: black;">"</span><span style="color: black;">);
ADFUtil.setEL(</span><span style="color: black;">"</span><span style="color: black;">#{bindings.deptId.attributeValue}</span><span style="color: black;">"</span><span style="color: black;">,
currentDeptRow.getAttribute(</span><span style="color: black;">"</span><span style="color: black;">Deptno</span><span style="color: black;">"</span><span style="color: black;">));
}</span></div></pre></div><script language="javascript" src="http://www.blogtrog.com/scripts/bt_code.js" type="text/javascript">
</script><script language="javascript" type="text/javascript">
bt_code_init('9f6c3a23-9755-4111-9a15-3c58ab3a3805');
</script><br />
4. Drop the two task flows in a single jsff page. It'll ask for the parameter for the TaskFlow2, give the same shared bean data control property 'deptId' as the parameter. Don't forget to set the 'refresh' property for the TaskFlow2 task flow binding to 'ifNeeded'.<br />
<br />
Parent jsff page code containing these two regions:<br />
<div id="iframeDiv3f89e6c4-2a70-4d3f-a488-181aa6e00ae5" style="display: none; margin: 0px;"><iframe frameborder="0" id="iframe3f89e6c4-2a70-4d3f-a488-181aa6e00ae5" src="http://www.blogtrog.com/code.aspx?id=3f89e6c4-2a70-4d3f-a488-181aa6e00ae5" style="border: 1px solid #e0e0e0; height: 320px; margin: 0px; width: 400px;"></iframe></div><div id="noIframeDiv3f89e6c4-2a70-4d3f-a488-181aa6e00ae5" style="display: block; margin: 0px;"><pre><div><span style="color: blue;"><?</span><span style="color: magenta;">xml version='1.0' encoding='windows-1252'</span><span style="color: blue;">?></span><span style="color: black;">
</span><span style="color: blue;"><</span><span style="color: maroon;">jsp:root </span><span style="color: red;">xmlns:jsp</span><span style="color: blue;">="http://java.sun.com/JSP/Page"</span><span style="color: red;"> version</span><span style="color: blue;">="2.1"</span><span style="color: red;">
xmlns:af</span><span style="color: blue;">="http://xmlns.oracle.com/adf/faces/rich"</span><span style="color: red;">
xmlns:f</span><span style="color: blue;">="http://java.sun.com/jsf/core"</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: blue;"><</span><span style="color: maroon;">af:panelGroupLayout </span><span style="color: red;">id</span><span style="color: blue;">="pgl1"</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: blue;"><</span><span style="color: maroon;">af:showDetailHeader </span><span style="color: red;">text</span><span style="color: blue;">="Interaction between two peer regions"</span><span style="color: red;">
disclosed</span><span style="color: blue;">="true"</span><span style="color: red;"> id</span><span style="color: blue;">="sdh1"</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: blue;"><</span><span style="color: maroon;">af:panelGroupLayout </span><span style="color: red;">id</span><span style="color: blue;">="pgl3"</span><span style="color: red;"> layout</span><span style="color: blue;">="scroll"</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: blue;"><</span><span style="color: maroon;">af:region </span><span style="color: red;">value</span><span style="color: blue;">="#{bindings.TaskFlow11.regionModel}"</span><span style="color: red;"> id</span><span style="color: blue;">="r1"</span><span style="color: blue;">/></span><span style="color: black;">
</span><span style="color: blue;"></</span><span style="color: maroon;">af:panelGroupLayout</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: blue;"><</span><span style="color: maroon;">af:spacer </span><span style="color: red;">width</span><span style="color: blue;">="10"</span><span style="color: red;"> height</span><span style="color: blue;">="10"</span><span style="color: red;"> id</span><span style="color: blue;">="s1"</span><span style="color: blue;">/></span><span style="color: black;">
</span><span style="color: blue;"><</span><span style="color: maroon;">af:panelGroupLayout </span><span style="color: red;">id</span><span style="color: blue;">="pgl4"</span><span style="color: red;"> layout</span><span style="color: blue;">="scroll"</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: blue;"><</span><span style="color: maroon;">af:region </span><span style="color: red;">value</span><span style="color: blue;">="#{bindings.TaskFlow21.regionModel}"</span><span style="color: red;"> id</span><span style="color: blue;">="r2"</span><span style="color: blue;">/></span><span style="color: black;">
</span><span style="color: blue;"></</span><span style="color: maroon;">af:panelGroupLayout</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: blue;"></</span><span style="color: maroon;">af:showDetailHeader</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: blue;"></</span><span style="color: maroon;">af:panelGroupLayout</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: blue;"></</span><span style="color: maroon;">jsp:root</span><span style="color: blue;">></span><span style="color: black;">
</span></div></pre></div><script language="javascript" src="http://www.blogtrog.com/scripts/bt_code.js" type="text/javascript">
</script><script language="javascript" type="text/javascript">
bt_code_init('3f89e6c4-2a70-4d3f-a488-181aa6e00ae5');
</script><br />
Parent Jsff pagedef file:<br />
<div id="iframeDiv0b4c5a04-8593-4055-8c59-b783fcb62816" style="display: none; margin: 0px;"><iframe frameborder="0" id="iframe0b4c5a04-8593-4055-8c59-b783fcb62816" src="http://www.blogtrog.com/code.aspx?id=0b4c5a04-8593-4055-8c59-b783fcb62816" style="border: 1px solid #e0e0e0; height: 560px; margin: 0px; width: 400px;"></iframe></div><div id="noIframeDiv0b4c5a04-8593-4055-8c59-b783fcb62816" style="display: block; margin: 0px;"><pre><div><span style="color: blue;"><?</span><span style="color: magenta;">xml version="1.0" encoding="UTF-8" </span><span style="color: blue;">?></span><span style="color: black;">
</span><span style="color: blue;"><</span><span style="color: maroon;">pageDefinition </span><span style="color: red;">xmlns</span><span style="color: blue;">="http://xmlns.oracle.com/adfm/uimodel"</span><span style="color: red;">
version</span><span style="color: blue;">="11.1.1.56.60"</span><span style="color: red;"> id</span><span style="color: blue;">="ParentPagePageDef"</span><span style="color: red;">
Package</span><span style="color: blue;">="com.demo.fragments"</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: blue;"><</span><span style="color: maroon;">parameters</span><span style="color: blue;">/></span><span style="color: black;">
</span><span style="color: blue;"><</span><span style="color: maroon;">executables</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: blue;"><</span><span style="color: maroon;">variableIterator </span><span style="color: red;">id</span><span style="color: blue;">="variables"</span><span style="color: blue;">/></span><span style="color: black;">
</span><span style="color: blue;"><</span><span style="color: maroon;">taskFlow </span><span style="color: red;">id</span><span style="color: blue;">="TaskFlow11"</span><span style="color: red;">
taskFlowId</span><span style="color: blue;">="/com/demo/taskflows/TaskFlow1.xml#TaskFlow1"</span><span style="color: red;">
activation</span><span style="color: blue;">="deferred"</span><span style="color: red;">
xmlns</span><span style="color: blue;">="http://xmlns.oracle.com/adf/controller/binding"</span><span style="color: red;">
Refresh</span><span style="color: blue;">="ifNeeded"</span><span style="color: blue;">/></span><span style="color: black;">
</span><span style="color: blue;"><</span><span style="color: maroon;">taskFlow </span><span style="color: red;">id</span><span style="color: blue;">="TaskFlow21"</span><span style="color: red;">
taskFlowId</span><span style="color: blue;">="/com/demo/taskflows/TaskFlow2.xml#TaskFlow2"</span><span style="color: red;">
activation</span><span style="color: blue;">="deferred"</span><span style="color: red;">
xmlns</span><span style="color: blue;">="http://xmlns.oracle.com/adf/controller/binding"</span><span style="color: red;">
Refresh</span><span style="color: blue;">="ifNeeded"</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: blue;"><</span><span style="color: maroon;">parameters</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: blue;"><</span><span style="color: maroon;">parameter </span><span style="color: red;">id</span><span style="color: blue;">="deptId"</span><span style="color: red;"> value</span><span style="color: blue;">="#{bindings.deptId.attributeValue}"</span><span style="color: blue;">/></span><span style="color: black;">
</span><span style="color: blue;"></</span><span style="color: maroon;">parameters</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: blue;"></</span><span style="color: maroon;">taskFlow</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: blue;"><</span><span style="color: maroon;">iterator </span><span style="color: red;">Binds</span><span style="color: blue;">="root"</span><span style="color: red;"> RangeSize</span><span style="color: blue;">="25"</span><span style="color: red;"> DataControl</span><span style="color: blue;">="SharedBean"</span><span style="color: red;">
id</span><span style="color: blue;">="SharedBeanIterator"</span><span style="color: blue;">/></span><span style="color: black;">
</span><span style="color: blue;"></</span><span style="color: maroon;">executables</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: blue;"><</span><span style="color: maroon;">bindings</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: blue;"><</span><span style="color: maroon;">attributeValues </span><span style="color: red;">IterBinding</span><span style="color: blue;">="SharedBeanIterator"</span><span style="color: red;"> id</span><span style="color: blue;">="deptId"</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: blue;"><</span><span style="color: maroon;">AttrNames</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: blue;"><</span><span style="color: maroon;">Item </span><span style="color: red;">Value</span><span style="color: blue;">="deptId"</span><span style="color: blue;">/></span><span style="color: black;">
</span><span style="color: blue;"></</span><span style="color: maroon;">AttrNames</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: blue;"></</span><span style="color: maroon;">attributeValues</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: blue;"></</span><span style="color: maroon;">bindings</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: blue;"></</span><span style="color: maroon;">pageDefinition</span><span style="color: blue;">></span></div></pre></div><script language="javascript" src="http://www.blogtrog.com/scripts/bt_code.js" type="text/javascript">
</script><script language="javascript" type="text/javascript">
bt_code_init('0b4c5a04-8593-4055-8c59-b783fcb62816');
</script><br />
That's it. Now, when the user selects a dept in TaskFlow1 region and clicks on 'Show Employees', the second task flow will be re-executed as the actionListener method changes value of the input parameter of the TaskFlow2. This triggers re-execution of TaskFlow2 and corresponding employees in selected dept in TaskFlow1 will be displayed in TaskFlow2.<br />
<br />
So, here we're establishing communication by using shared bean data control property. Sample Screenshots below:<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://4.bp.blogspot.com/_ex9GjJ9fvbk/TNRSVi6b4wI/AAAAAAAAAPA/ryruge55o0c/s1600/2.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img <="" border="0" height="97" img="" src="http://4.bp.blogspot.com/_ex9GjJ9fvbk/TNRSVi6b4wI/AAAAAAAAAPA/ryruge55o0c/s320/2.JPG" width="320" /></a></div><br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://2.bp.blogspot.com/_ex9GjJ9fvbk/TNRSddqSSDI/AAAAAAAAAPI/PgxkEc36aQA/s1600/3.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img <="" border="0" height="109" img="" src="http://2.bp.blogspot.com/_ex9GjJ9fvbk/TNRSddqSSDI/AAAAAAAAAPI/PgxkEc36aQA/s320/3.JPG" width="320" /></a></div>Murali Papanahttp://www.blogger.com/profile/06991064825453310705noreply@blogger.com5tag:blogger.com,1999:blog-8389468608715252764.post-48228739878940082182010-11-05T03:56:00.000-07:002010-11-11T03:45:22.486-08:00ADF UI - How to include Row Header for af:table?If you're using af:table and row selection is enabled for the table, a must for the table is 'Row Header'. Row header enables the user to select a single row from the table. To add a row header to the table, just add a blank column <b>as the first colum</b>n and specify <b>width="5"</b>, <b>minimumWidth="5"</b> and <b>rowHeader="true"</b> and specify <b>align="right"</b>. Don't include any field inside this row header column.<br />
<br />
Below is the code for row header. You can copy-paste this code as a first column in the table and that's it. You're done!<br />
<div id="iframeDiv5837ae97-783a-45d7-8cf4-e6222fd5ff36" style="display: none; margin: 0px;"><iframe frameborder="0" id="iframe5837ae97-783a-45d7-8cf4-e6222fd5ff36" src="http://www.blogtrog.com/code.aspx?id=5837ae97-783a-45d7-8cf4-e6222fd5ff36" style="border: 1px solid rgb(224, 224, 224); height: 80px; margin: 0px; width: 400px;"></iframe></div><div id="noIframeDiv5837ae97-783a-45d7-8cf4-e6222fd5ff36" style="display: block; margin: 0px;"><pre><div><span style="color: blue;"><</span><span style="color: maroon;">af:column </span><span style="color: red;">id</span><span style="color: blue;">="c4"</span><span style="color: red;"> rowHeader</span><span style="color: blue;">="true"</span><span style="color: red;"> width</span><span style="color: blue;">="5"</span><span style="color: red;"> minimumWidth</span><span style="color: blue;">="5"</span><span style="color: red;">
align</span><span style="color: blue;">="right"</span><span style="color: blue;">/></span></div></pre></div><script language="javascript" src="http://www.blogtrog.com/scripts/bt_code.js" type="text/javascript">
</script><script language="javascript" type="text/javascript">
bt_code_init('5837ae97-783a-45d7-8cf4-e6222fd5ff36');
</script><br />
<b>Sample screen shots:</b><br />
Table without row header:<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://2.bp.blogspot.com/_ex9GjJ9fvbk/TNPikavtU5I/AAAAAAAAAOs/oqZXxsGuxOM/s1600/1.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="126" src="http://2.bp.blogspot.com/_ex9GjJ9fvbk/TNPikavtU5I/AAAAAAAAAOs/oqZXxsGuxOM/s320/1.JPG" width="320" /></a></div><br />
Table after adding row header:<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://4.bp.blogspot.com/_ex9GjJ9fvbk/TNPil5_OJMI/AAAAAAAAAOw/J5wYd5fL4w0/s1600/2.JPG" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="139" src="http://4.bp.blogspot.com/_ex9GjJ9fvbk/TNPil5_OJMI/AAAAAAAAAOw/J5wYd5fL4w0/s320/2.JPG" width="320" /></a></div>Murali Papanahttp://www.blogger.com/profile/06991064825453310705noreply@blogger.com5tag:blogger.com,1999:blog-8389468608715252764.post-68613327601958861512010-11-04T14:27:00.000-07:002010-11-11T03:46:02.135-08:00ADF UI - Implementing multi-select table (Selecting and processing multiple rows)When it comes to implementation of multi-select table using Oracle ADF, it'll become little tricky. In this post, I'll explain how easily we can select multiple rows from af:table and process them for whatever need you have.<br />
<br />
For example, let's take Employee search screen and from the search results table, let's select multiple employee records and click on 'Delete' button to delete the selected employee records. You can download the sample application from <a href="http://adftips.googlecode.com/files/MultiSelectTable.zip">here</a>. Please follow the below mentioned steps:<br />
<br />
1. Drag and drop the VO as af:table into the jsff page and from the source remove the properties 'selectedRowKeys' and 'selectionListener'. And set 'rowSelection=multiple'. This will allow us to select multiple rows. You can select the multiple rows by clicking multiple rows pressing 'Ctrl' key or you can do the range selection by pression 'Shift' key. <br />
<br />
2. Now, add a binding for the af:table as a bean property. And, write an actionListener method for the 'Delete' button to invoke after selecting multiple rows. <br />
<br />
After doing this, the table code would look like this: <br />
<div id="iframeDivaee10f7d-9ce3-477d-a446-0ec6b199a1a2" style="display: none; margin: 0px;"><iframe frameborder="0" id="iframeaee10f7d-9ce3-477d-a446-0ec6b199a1a2" src="http://www.blogtrog.com/code.aspx?id=aee10f7d-9ce3-477d-a446-0ec6b199a1a2" style="border: 1px solid rgb(224, 224, 224); height: 240px; margin: 0px; width: 400px;"></iframe></div><div id="noIframeDivaee10f7d-9ce3-477d-a446-0ec6b199a1a2" style="display: block; margin: 0px;"><pre><div><span style="color: blue;"><</span><span style="color: maroon;">af:table </span><span style="color: red;">value</span><span style="color: blue;">="#{bindings.EmpDeptVO.collectionModel}"</span><span style="color: red;"> var</span><span style="color: blue;">="row"</span><span style="color: red;">
rows</span><span style="color: blue;">="#{bindings.EmpDeptVO.rangeSize}"</span><span style="color: red;">
emptyText</span><span style="color: blue;">="#{bindings.EmpDeptVO.viewable ? 'No data to display.' : 'Access Denied.'}"</span><span style="color: red;">
fetchSize</span><span style="color: blue;">="#{bindings.EmpDeptVO.rangeSize}"</span><span style="color: red;">
rowBandingInterval</span><span style="color: blue;">="0"</span><span style="color: red;">
rowSelection</span><span style="color: blue;">="multiple"</span><span style="color: red;"> id</span><span style="color: blue;">="t1"</span><span style="color: red;">
partialTriggers</span><span style="color: blue;">=":::qryId1 ::ctb1"</span><span style="color: red;">
columnStretching</span><span style="color: blue;">="column:c1"</span><span style="color: red;">
styleClass</span><span style="color: blue;">="AFStretchWidth"</span><span style="color: red;"> columnSelection</span><span style="color: blue;">="multiple"</span><span style="color: red;">
first</span><span style="color: blue;">="0"</span><span style="color: red;"> contentDelivery</span><span style="color: blue;">="immediate"</span><span style="color: red;"> autoHeightRows</span><span style="color: blue;">="10"</span><span style="color: red;">
binding</span><span style="color: blue;">="#{pageFlowScope.ExampleBean.searchResultsTable}"</span><span style="color: blue;">></span></div></pre></div><script language="javascript" src="http://www.blogtrog.com/scripts/bt_code.js" type="text/javascript">
</script><script language="javascript" type="text/javascript">
bt_code_init('aee10f7d-9ce3-477d-a446-0ec6b199a1a2');
</script><br />
The bean class having ActionListener method and the table binding:<br />
<div id="iframeDivf1e411fa-7821-413c-8454-50d184fc1f70" style="display: none; margin: 0px;"><iframe frameborder="0" id="iframef1e411fa-7821-413c-8454-50d184fc1f70" src="http://www.blogtrog.com/code.aspx?id=f1e411fa-7821-413c-8454-50d184fc1f70" style="border: 1px solid #e0e0e0; height: 500px; margin: 0px; width: 400px;"></iframe></div><div id="noIframeDivf1e411fa-7821-413c-8454-50d184fc1f70" style="display: block; margin: 0px;"><pre><div><span style="color: blue;">package</span><span style="color: black;"> com.demo.ui.bean;
</span><span style="color: blue;">import</span><span style="color: black;"> com.mpapana.bean.ADFUtil;
</span><span style="color: blue;">import</span><span style="color: black;"> java.util.ArrayList;
</span><span style="color: blue;">import</span><span style="color: black;"> java.util.Iterator;
</span><span style="color: blue;">import</span><span style="color: black;"> java.util.List;
</span><span style="color: blue;">import</span><span style="color: black;"> javax.faces.event.ActionEvent;
</span><span style="color: blue;">import</span><span style="color: black;"> oracle.adf.model.binding.DCBindingContainer;
</span><span style="color: blue;">import</span><span style="color: black;"> oracle.adf.view.rich.component.UIXTable;
</span><span style="color: blue;">import</span><span style="color: black;"> oracle.adf.view.rich.component.rich.data.RichTable;
</span><span style="color: blue;">import</span><span style="color: black;"> oracle.binding.OperationBinding;
</span><span style="color: blue;">public</span><span style="color: black;"> </span><span style="color: blue;">class</span><span style="color: black;"> ExampleBean {
</span><span style="color: blue;">private</span><span style="color: black;"> RichTable searchResultsTable;
</span><span style="color: blue;">public</span><span style="color: black;"> </span><span style="color: blue;">void</span><span style="color: black;"> setSearchResultsTable(RichTable searchResultsTable) {
</span><span style="color: blue;">this</span><span style="color: black;">.searchResultsTable </span><span style="color: black;">=</span><span style="color: black;"> searchResultsTable;
}
</span><span style="color: blue;">public</span><span style="color: black;"> RichTable getSearchResultsTable() {
</span><span style="color: blue;">return</span><span style="color: black;"> searchResultsTable;
}
</span><span style="color: blue;">public</span><span style="color: black;"> </span><span style="color: blue;">void</span><span style="color: black;"> deleteSelectedRows(ActionEvent ae) {
</span><span style="color: green;">//</span><span style="color: green;">getting table reference from binding</span><span style="color: green;">
</span><span style="color: black;"> UIXTable table </span><span style="color: black;">=</span><span style="color: black;"> getSearchResultsTable();
</span><span style="color: green;">//</span><span style="color: green;">getting iterator to iterate over selected row keys</span><span style="color: green;">
</span><span style="color: black;"> Iterator selection </span><span style="color: black;">=</span><span style="color: black;"> table.getSelectedRowKeys().iterator();
List rowIndexes </span><span style="color: black;">=</span><span style="color: black;"> </span><span style="color: blue;">new</span><span style="color: black;"> ArrayList();
</span><span style="color: blue;">while</span><span style="color: black;"> (selection.hasNext()) {
Object rowKey </span><span style="color: black;">=</span><span style="color: black;"> selection.next();
</span><span style="color: green;">//</span><span style="color: green;">setting the rowKey to table one by one</span><span style="color: green;">
</span><span style="color: black;"> table.setRowKey(rowKey);
</span><span style="color: blue;">int</span><span style="color: black;"> index </span><span style="color: black;">=</span><span style="color: black;"> table.getRowIndex();
</span><span style="color: green;">//</span><span style="color: green;">adding selected row indexes to a List</span><span style="color: green;">
</span><span style="color: black;"> rowIndexes.add(index);
System.out.println(</span><span style="color: black;">"</span><span style="color: black;">.... Row row=</span><span style="color: black;">"</span><span style="color: black;"> </span><span style="color: black;">+</span><span style="color: black;"> table.getRowData() </span><span style="color: black;">+</span><span style="color: black;"> </span><span style="color: black;">"</span><span style="color: black;">\t</span><span style="color: black;">"</span><span style="color: black;"> </span><span style="color: black;">+</span><span style="color: black;">
index);
}
DCBindingContainer bindings </span><span style="color: black;">=</span><span style="color: black;">
(DCBindingContainer)ADFUtil.evaluateEL(</span><span style="color: black;">"</span><span style="color: black;">#{bindings}</span><span style="color: black;">"</span><span style="color: black;">);
</span><span style="color: green;">//</span><span style="color: green;">getting operation binding reference to the AMImplMethod deleteSelectedRows()</span><span style="color: green;">
</span><span style="color: black;"> OperationBinding opBinding </span><span style="color: black;">=</span><span style="color: black;">
bindings.getOperationBinding(</span><span style="color: black;">"</span><span style="color: black;">deleteSelectedRows</span><span style="color: black;">"</span><span style="color: black;">);
</span><span style="color: green;">//</span><span style="color: green;">passing the selected row keys list to the AMImpl method</span><span style="color: green;">
</span><span style="color: black;"> opBinding.getParamsMap().put(</span><span style="color: black;">"</span><span style="color: black;">selectedRowIndexes</span><span style="color: black;">"</span><span style="color: black;">, rowIndexes);
opBinding.execute();
}
}
</span></div></pre></div><script language="javascript" src="http://www.blogtrog.com/scripts/bt_code.js" type="text/javascript">
</script><script language="javascript" type="text/javascript">
bt_code_init('f1e411fa-7821-413c-8454-50d184fc1f70');
</script><br />
In the above bean method <i>deleteSelectedRows</i>, we're getting the selected row keys and iterating over them and setting the row key to the table. We're doing this because, we hae to store te the table's row index in a list and this list will passed to the AMImpl method where the actual processing the rows is done.<br />
<br />
4. Write a method in AMImpl (deleteSelectedRows) which takes the List selectedRowIndexes as an argument. This method iterates over the selected row indeces and gets the row at the selected index and performs either update or delete on that row (which represents the selected row in the UI table).<br />
<div id="iframeDiv2ecf94bb-ba0c-4e71-915c-65da59e63400" style="display: none; margin: 0px;"><iframe frameborder="0" id="iframe2ecf94bb-ba0c-4e71-915c-65da59e63400" src="http://www.blogtrog.com/code.aspx?id=2ecf94bb-ba0c-4e71-915c-65da59e63400" style="border: 1px solid rgb(224, 224, 224); height: 250px; margin: 0px; width: 400px;"></iframe></div><div id="noIframeDiv2ecf94bb-ba0c-4e71-915c-65da59e63400" style="display: block; margin: 0px;"><pre><div><span style="color: black;"> </span><span style="color: blue;">public</span><span style="color: black;"> </span><span style="color: blue;">void</span><span style="color: black;"> deleteSelectedRows(List selectedRowIndexes) {
ViewObjectImpl empDeptVO </span><span style="color: black;">=</span><span style="color: black;"> </span><span style="color: blue;">this</span><span style="color: black;">.getEmpDeptVO();
</span><span style="color: blue;">for</span><span style="color: black;"> (</span><span style="color: blue;">int</span><span style="color: black;"> i </span><span style="color: black;">=</span><span style="color: black;"> </span><span style="color: black;">0</span><span style="color: black;">; i </span><span style="color: black;"><</span><span style="color: black;"> selectedRowIndexes.size(); i</span><span style="color: black;">++</span><span style="color: black;">) {
</span><span style="color: green;">//</span><span style="color: green;">getting the selected row index one by one</span><span style="color: green;">
</span><span style="color: black;"> </span><span style="color: blue;">int</span><span style="color: black;"> selectedRowIndex </span><span style="color: black;">=</span><span style="color: black;">(Integer) selectedRowIndexes.get(i);
</span><span style="color: green;">//</span><span style="color: green;">setting the current row to the row at selected index</span><span style="color: green;">
</span><span style="color: black;"> empDeptVO.setCurrentRowAtRangeIndex(selectedRowIndex);
</span><span style="color: green;">//</span><span style="color: green;">deleting the current row </span><span style="color: green;">
</span><span style="color: black;"> empDeptVO.removeCurrentRow();
}
</span><span style="color: green;">//</span><span style="color: green;">committing the transaction</span><span style="color: green;">
</span><span style="color: black;"> </span><span style="color: blue;">this</span><span style="color: black;">.getTransaction().commit();
}</span></div></pre></div><script language="javascript" src="http://www.blogtrog.com/scripts/bt_code.js" type="text/javascript">
</script><script language="javascript" type="text/javascript">
bt_code_init('2ecf94bb-ba0c-4e71-915c-65da59e63400');
</script><br />
Suppose, if you need to update the rows, sample code below:<br />
<div id="iframeDiv3d9593cf-1625-479e-b3a6-b568e263fde5" style="display: none; margin: 0px;"><iframe frameborder="0" id="iframe3d9593cf-1625-479e-b3a6-b568e263fde5" src="http://www.blogtrog.com/code.aspx?id=3d9593cf-1625-479e-b3a6-b568e263fde5" style="border: 1px solid #e0e0e0; height: 260px; margin: 0px; width: 400px;"></iframe></div><div id="noIframeDiv3d9593cf-1625-479e-b3a6-b568e263fde5" style="display: block; margin: 0px;"><pre><div><span style="color: black;"> </span><span style="color: blue;">public</span><span style="color: black;"> </span><span style="color: blue;">void</span><span style="color: black;"> updateSelectedRows(List selectedRowIndexes) {
ViewObjectImpl empDeptVO </span><span style="color: black;">=</span><span style="color: black;"> </span><span style="color: blue;">this</span><span style="color: black;">.getEmpDeptVO();
</span><span style="color: blue;">for</span><span style="color: black;"> (</span><span style="color: blue;">int</span><span style="color: black;"> i </span><span style="color: black;">=</span><span style="color: black;"> </span><span style="color: black;">0</span><span style="color: black;">; i </span><span style="color: black;"><</span><span style="color: black;"> selectedRowIndexes.size(); i</span><span style="color: black;">++</span><span style="color: black;">) {
</span><span style="color: green;">//</span><span style="color: green;">getting the selected row index one by one</span><span style="color: green;">
</span><span style="color: black;"> </span><span style="color: blue;">int</span><span style="color: black;"> selectedRowIndex </span><span style="color: black;">=</span><span style="color: black;">(Integer) selectedRowIndexes.get(i);
</span><span style="color: green;">//</span><span style="color: green;">setting the current row to the row at selected index</span><span style="color: green;">
</span><span style="color: black;"> empDeptVO.setCurrentRowAtRangeIndex(selectedRowIndex);
Row row </span><span style="color: black;">=</span><span style="color: black;"> empDeptVO.getCurrentRow();
</span><span style="color: green;">//</span><span style="color: green;">updating the Ename attribute</span><span style="color: green;">
</span><span style="color: black;"> row.setAttribute(</span><span style="color: black;">"</span><span style="color: black;">Ename</span><span style="color: black;">"</span><span style="color: black;">, row.getAttribute(</span><span style="color: black;">"</span><span style="color: black;">Ename</span><span style="color: black;">"</span><span style="color: black;">) </span><span style="color: black;">+</span><span style="color: black;"> </span><span style="color: black;">"</span><span style="color: black;">+</span><span style="color: black;">"</span><span style="color: black;">);
}
</span><span style="color: green;">//</span><span style="color: green;">committing the transaction</span><span style="color: green;">
</span><span style="color: black;"> </span><span style="color: blue;">this</span><span style="color: black;">.getTransaction().commit();
}</span></div></pre></div><script language="javascript" src="http://www.blogtrog.com/scripts/bt_code.js" type="text/javascript">
</script><script language="javascript" type="text/javascript">
bt_code_init('3d9593cf-1625-479e-b3a6-b568e263fde5');
</script><br />
<br />
5. The same AMImpl method will be invoked from the bean method (refer to: <a href="http://www.adftips.com/2010/10/adf-ui-executing-amimpl-method-in-ui.html">how to invoke AMImpl method in bean</a>) the selected rows will be deleted and the transaction is committed in the AMImpl's method. <br />
<br />
That's it. In a nut shell, the bean method will store selected row indexes in a list and the AMImpl method takes that list and does the operations (update or delete) on the rows at those selected indexes.<br />
<br />
Sample screen shots:<br />
1. Select two records 'SCOTT' and 'JAMES' and click 'Delete'.<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://3.bp.blogspot.com/_ex9GjJ9fvbk/TNMgOMvXJAI/AAAAAAAAAOk/KiVWK8oFAG0/s1600/1.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="116" src="http://3.bp.blogspot.com/_ex9GjJ9fvbk/TNMgOMvXJAI/AAAAAAAAAOk/KiVWK8oFAG0/s320/1.JPG" width="320" /></a></div> 2. Search again. The two records got deleted and won't appear in search results.<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://2.bp.blogspot.com/_ex9GjJ9fvbk/TNMgPTRN_MI/AAAAAAAAAOo/DkwU7yNbgq0/s1600/2.JPG" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="166" src="http://2.bp.blogspot.com/_ex9GjJ9fvbk/TNMgPTRN_MI/AAAAAAAAAOo/DkwU7yNbgq0/s320/2.JPG" width="320" /></a></div><br />
Enjoy :) !Murali Papanahttp://www.blogger.com/profile/06991064825453310705noreply@blogger.com5tag:blogger.com,1999:blog-8389468608715252764.post-16224948097264771512010-11-04T13:10:00.000-07:002010-11-11T04:20:14.047-08:00Jdeveloper Tip: Increasing the log sizeMany times you would have faced issues with the default log size in Jdeveloper. You get an exception, and when you scroll through the log to find out the stack trace, it was already gone as the log size is not sufficient. To increase the no. of lines for log, goto 'Tools' menu -> select 'Preferences..'<br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://3.bp.blogspot.com/_ex9GjJ9fvbk/TNMS1psV97I/AAAAAAAAAOg/2NLLgQ8XE00/s1600/2.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="226" src="http://3.bp.blogspot.com/_ex9GjJ9fvbk/TNMS1psV97I/AAAAAAAAAOg/2NLLgQ8XE00/s320/2.JPG" width="320" /></a></div><br />
Now, increase the log size in the 'Environment: Log' section:<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://3.bp.blogspot.com/_ex9GjJ9fvbk/TNMS0hM90PI/AAAAAAAAAOc/wuWyZNsbFS4/s1600/1.JPG" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="228" src="http://3.bp.blogspot.com/_ex9GjJ9fvbk/TNMS0hM90PI/AAAAAAAAAOc/wuWyZNsbFS4/s320/1.JPG" width="320" /></a></div>Murali Papanahttp://www.blogger.com/profile/06991064825453310705noreply@blogger.com4tag:blogger.com,1999:blog-8389468608715252764.post-85333626444208219072010-11-04T13:02:00.000-07:002010-11-11T04:21:05.753-08:00Jdeveloper Tip: Toggling line numbers in the code editorThe quickest way of showing line numbers for the code in code editor in Jdeveloper is just right click on the left hand side of code editor and select 'Toggle Line Numbers'.<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://4.bp.blogspot.com/_ex9GjJ9fvbk/TNMQ_0s02XI/AAAAAAAAAOQ/2TTkCGOZXvo/s1600/1.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="http://4.bp.blogspot.com/_ex9GjJ9fvbk/TNMQ_0s02XI/AAAAAAAAAOQ/2TTkCGOZXvo/s320/1.JPG" width="279" /></a></div><br />
If you prefer to show line numbers always, you can do that in settings for 'Code Editor: Line Gutter'. <br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://4.bp.blogspot.com/_ex9GjJ9fvbk/TNMRBLD-NXI/AAAAAAAAAOU/o3ZI5o87fbA/s1600/2.JPG" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://4.bp.blogspot.com/_ex9GjJ9fvbk/TNMRBLD-NXI/AAAAAAAAAOU/o3ZI5o87fbA/s1600/2.JPG" /></a></div><br />
<br />
There, you select 'Show Line Numbers' and save the settings. That's it! From next time onwards, the line numbers will be displayed in the code editor.<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://3.bp.blogspot.com/_ex9GjJ9fvbk/TNMRCCtky-I/AAAAAAAAAOY/oxOR4ab4X24/s1600/3.JPG" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="228" src="http://3.bp.blogspot.com/_ex9GjJ9fvbk/TNMRCCtky-I/AAAAAAAAAOY/oxOR4ab4X24/s320/3.JPG" width="320" /></a></div>Murali Papanahttp://www.blogger.com/profile/06991064825453310705noreply@blogger.com21tag:blogger.com,1999:blog-8389468608715252764.post-16784222492553937142010-11-04T12:41:00.000-07:002010-11-11T04:20:57.397-08:00Debugging Tip - Easy way of viewing stack traces in the server logWhile debugging, you may find it very difficult to scroll through entire 'Log' window to find out your stack traces in case if there is some error while running UI or model code. To view the stack traces available in the Server log, just right click in the log window and select 'Stack Traces..'.<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://4.bp.blogspot.com/_ex9GjJ9fvbk/TNMLpCLu4VI/AAAAAAAAAOA/ew7D59-1HvI/s1600/1.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="169" src="http://4.bp.blogspot.com/_ex9GjJ9fvbk/TNMLpCLu4VI/AAAAAAAAAOA/ew7D59-1HvI/s320/1.JPG" width="320" /></a></div><br />
Now, the 'Stack Traces' window will be opened and it'll show all the stack traces in the log.<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://3.bp.blogspot.com/_ex9GjJ9fvbk/TNML-DKtHwI/AAAAAAAAAOI/-XaNvvAG84Y/s1600/2.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="216" src="http://3.bp.blogspot.com/_ex9GjJ9fvbk/TNML-DKtHwI/AAAAAAAAAOI/-XaNvvAG84Y/s320/2.JPG" width="320" /></a></div><br />
You can navigate through the stack traces very easily in the 'Stack Traces' window. And, if you want to go to the some line in code from the stack trace, just select that line in stack trace and click on 'Go To' button in the window. Control will move to the code editor at the corresponding line no. If the source file is from different project, it'll ask to select the project containing the source and once you select the project it'll search in that project and goes to the corresponding line.<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://4.bp.blogspot.com/_ex9GjJ9fvbk/TNMMDYU1eMI/AAAAAAAAAOM/g33xwZNWYXc/s1600/3.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="216" src="http://4.bp.blogspot.com/_ex9GjJ9fvbk/TNMMDYU1eMI/AAAAAAAAAOM/g33xwZNWYXc/s320/3.JPG" width="320" /></a></div>Murali Papanahttp://www.blogger.com/profile/06991064825453310705noreply@blogger.com3tag:blogger.com,1999:blog-8389468608715252764.post-19854781177745249972010-11-03T09:38:00.000-07:002010-11-11T04:21:33.979-08:00ADF Model - Beginner: Exposing AMImpl methods as client interfaceIf you're using ADF BC, you would write your application logic in AMImpl methods in model project. But, if you want to use/call these methods in UI project, you should generate client interface for these methods. Here, let me show how to do that.<br />
<br />
For example let's take a DemoAMImpl has two methods 'getAllDepts' and 'getEmployeesInDept', to expose them in client's interface, follow the below steps:<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://2.bp.blogspot.com/_ex9GjJ9fvbk/TNGPa-mI0OI/AAAAAAAAANk/2TkWr7oBL2g/s1600/0.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="122" src="http://2.bp.blogspot.com/_ex9GjJ9fvbk/TNGPa-mI0OI/AAAAAAAAANk/2TkWr7oBL2g/s320/0.JPG" width="320" /></a></div><br />
1. Open application module DemoAM -> Click on 'Java' tab -> Click on 'Edit'(pencil) icon beside the 'Client Interface' section.<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://4.bp.blogspot.com/_ex9GjJ9fvbk/TNGPbz-lfcI/AAAAAAAAANo/29Q0iYyAii4/s1600/1.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="129" src="http://4.bp.blogspot.com/_ex9GjJ9fvbk/TNGPbz-lfcI/AAAAAAAAANo/29Q0iYyAii4/s320/1.JPG" style="cursor: move;" width="320" /></a></div><br />
2. In the 'Edit Client Interface' section, shuffle the methods you want to expose th right side and click 'OK'.<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://2.bp.blogspot.com/_ex9GjJ9fvbk/TNGPcFY8H0I/AAAAAAAAANs/PDhJuGRCV-E/s1600/2.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="223" src="http://2.bp.blogspot.com/_ex9GjJ9fvbk/TNGPcFY8H0I/AAAAAAAAANs/PDhJuGRCV-E/s320/2.JPG" width="320" /></a></div><br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://4.bp.blogspot.com/_ex9GjJ9fvbk/TNGPckQ6BLI/AAAAAAAAANw/-V9aU5czmSY/s1600/3.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="222" src="http://4.bp.blogspot.com/_ex9GjJ9fvbk/TNGPckQ6BLI/AAAAAAAAANw/-V9aU5czmSY/s320/3.JPG" width="320" /></a></div><br />
3. Now, you can see the added methods under the 'Client Interface' Section.<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://2.bp.blogspot.com/_ex9GjJ9fvbk/TNGPebYvq6I/AAAAAAAAAN0/dSO-hh5Fusw/s1600/4.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="142" src="http://2.bp.blogspot.com/_ex9GjJ9fvbk/TNGPebYvq6I/AAAAAAAAAN0/dSO-hh5Fusw/s320/4.JPG" width="320" /></a></div><br />
4. Now, if you expand the 'Data Controls' palette, you can see the newly added methods there so that you can drag and drop them into your UI project task flows or you can add them as methodAction bindings in pagedef.<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://3.bp.blogspot.com/_ex9GjJ9fvbk/TNGPeo1918I/AAAAAAAAAN4/oTyDZEHTwgo/s1600/5.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="148" src="http://3.bp.blogspot.com/_ex9GjJ9fvbk/TNGPeo1918I/AAAAAAAAAN4/oTyDZEHTwgo/s320/5.JPG" width="320" /></a></div><br />
Sample method binding in task flow:<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://4.bp.blogspot.com/_ex9GjJ9fvbk/TNGPgBl8ovI/AAAAAAAAAN8/j_RbLb1XA-0/s1600/6.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="168" src="http://4.bp.blogspot.com/_ex9GjJ9fvbk/TNGPgBl8ovI/AAAAAAAAAN8/j_RbLb1XA-0/s320/6.JPG" width="320" /></a></div>Murali Papanahttp://www.blogger.com/profile/06991064825453310705noreply@blogger.com5tag:blogger.com,1999:blog-8389468608715252764.post-9509703538959493522010-11-02T11:51:00.000-07:002010-11-11T04:22:16.109-08:00ADF UI - Tips to stretch different ADF components to occupy the entire page widthHere are the simple techniques to stretch different ADF components to occupy the entire page width.<br />
<br />
<b>1. Stretching af:table inside af:panelCollection:</b><br />
Just specify styleClass="AFStretchWidth" for af:panelCollection. You don't need to specify either 'width', 'style' or 'styleClass' for the af:table which is inside af:panelCollection.<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://2.bp.blogspot.com/_ex9GjJ9fvbk/TNBdFyU6vbI/AAAAAAAAANE/W_mjZdxYmus/s1600/5.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="200" src="http://2.bp.blogspot.com/_ex9GjJ9fvbk/TNBdFyU6vbI/AAAAAAAAANE/W_mjZdxYmus/s320/5.JPG" width="320" /></a></div><br />
Table before Stretching:<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://3.bp.blogspot.com/_ex9GjJ9fvbk/TNBVOJPvJaI/AAAAAAAAAM8/4MSP84OR9Cc/s1600/1.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="28" src="http://3.bp.blogspot.com/_ex9GjJ9fvbk/TNBVOJPvJaI/AAAAAAAAAM8/4MSP84OR9Cc/s320/1.JPG" width="320" /></a></div><br />
Table after Stretching:<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://1.bp.blogspot.com/_ex9GjJ9fvbk/TNBVPK1eo1I/AAAAAAAAANA/C-5n0hlVveA/s1600/2.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="27" src="http://1.bp.blogspot.com/_ex9GjJ9fvbk/TNBVPK1eo1I/AAAAAAAAANA/C-5n0hlVveA/s320/2.JPG" width="320" /></a></div><br />
<b>2. Stretching af:panelTabbed and af:panelSplitter:</b><br />
Just surround the component with af:panelStretchLayout and place the component in it's 'center' facet and specify styleClass="AFStretchWidth" for the af:panelStretchLayout. That's it. You don't need to set either 'style' or 'styleClass' properties for af:panelTabbed or af:panelSplitter.<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://3.bp.blogspot.com/_ex9GjJ9fvbk/TNBdkVm2G4I/AAAAAAAAANY/u7WtBxfXwew/s1600/6.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="128" src="http://3.bp.blogspot.com/_ex9GjJ9fvbk/TNBdkVm2G4I/AAAAAAAAANY/u7WtBxfXwew/s320/6.JPG" width="320" /></a></div><br />
af:panelTabbed before Stretching:<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://1.bp.blogspot.com/_ex9GjJ9fvbk/TNBdaEA_pLI/AAAAAAAAANU/muU5oMXZbkQ/s1600/3.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="189" src="http://1.bp.blogspot.com/_ex9GjJ9fvbk/TNBdaEA_pLI/AAAAAAAAANU/muU5oMXZbkQ/s320/3.JPG" width="320" /></a></div><br />
<div class="separator" style="clear: both; text-align: center;"><br />
</div>af:panelTabbed after Stretching:<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://1.bp.blogspot.com/_ex9GjJ9fvbk/TNBdLjoZ0yI/AAAAAAAAANI/a_6w9rs7_QY/s1600/4.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="69" src="http://1.bp.blogspot.com/_ex9GjJ9fvbk/TNBdLjoZ0yI/AAAAAAAAANI/a_6w9rs7_QY/s320/4.JPG" style="cursor: move;" width="320" /></a></div><br />
To stretch any other component, specifying the property styleClass="AFStretchWidth" should stretch the width of the component to occupy entire page. But, incase if it doesn't work try surrounding the component with af:panelStretchLayout and place the component in it's 'center' facet. Even if it doesn't work, try specifying styleClass="AFStretchWidth" for af:panelStretchLayout. One of these should definitely work :)<br />
<br />
PS: This will just stretch the width, if you want to increase the height for the component you need specify for height for the component in the 'Style' section by specifying 'inlineStyle' property if it doesn't have 'height' property already.Murali Papanahttp://www.blogger.com/profile/06991064825453310705noreply@blogger.com7tag:blogger.com,1999:blog-8389468608715252764.post-6486136457179206812010-11-02T10:54:00.000-07:002010-11-11T04:22:41.704-08:00ADF UI - How to get 'Format' menu for table in af:panelCollection?TO get the 'Format' menu in af:panelCollection, set columnSelection="multiple" for the af:table inside panelCollection. Actually, setting columnSelection="multiple" will allow user to select multiple table columns at once and apply formatting (Like resizing columns, wrapping the content in the columns, etc.,) and it'll also render a footer for the table which will show status messages like 'columnsHidden'.<br />
<div id="iframeDiv9760ea2a-f764-4038-9e52-edb2f6264ed5" style="display: none; margin: 0px;"><iframe frameborder="0" id="iframe9760ea2a-f764-4038-9e52-edb2f6264ed5" src="http://www.blogtrog.com/code.aspx?id=9760ea2a-f764-4038-9e52-edb2f6264ed5" style="border: 1px solid #e0e0e0; height: 200px; margin: 0px; width: 600px;"></iframe></div><div id="noIframeDiv9760ea2a-f764-4038-9e52-edb2f6264ed5" style="display: block; margin: 0px;"><pre><div><span style="color: blue;"><</span><span style="color: maroon;">af:table </span><span style="color: red;">value</span><span style="color: blue;">="#{bindings.EmpDeptVO.collectionModel}"</span><span style="color: red;"> var</span><span style="color: blue;">="row"</span><span style="color: red;">
rows</span><span style="color: blue;">="#{bindings.EmpDeptVO.rangeSize}"</span><span style="color: red;">
emptyText</span><span style="color: blue;">="#{bindings.EmpDeptVO.viewable ? 'No data to display.' : 'Access Denied.'}"</span><span style="color: red;">
fetchSize</span><span style="color: blue;">="#{bindings.EmpDeptVO.rangeSize}"</span><span style="color: red;">
rowBandingInterval</span><span style="color: blue;">="0"</span><span style="color: red;">
selectedRowKeys</span><span style="color: blue;">="#{bindings.EmpDeptVO.collectionModel.selectedRow}"</span><span style="color: red;">
selectionListener</span><span style="color: blue;">="#{bindings.EmpDeptVO.collectionModel.makeCurrent}"</span><span style="color: red;">
rowSelection</span><span style="color: blue;">="single"</span><span style="color: red;"> id</span><span style="color: blue;">="t1"</span><span style="color: red;">
styleClass</span><span style="color: blue;">="AFStretchWidth"</span><span style="color: red;">
columnSelection</span><span style="color: blue;">="multiple"</span><span style="color: red;">
first</span><span style="color: blue;">="0"</span><span style="color: red;"> contentDelivery</span><span style="color: blue;">="immediate"</span><span style="color: red;"> autoHeightRows</span><span style="color: blue;">="10"</span><span style="color: blue;">></span></div></pre></div><script language="javascript" src="http://www.blogtrog.com/scripts/bt_code.js" type="text/javascript">
</script><script language="javascript" type="text/javascript">
bt_code_init('9760ea2a-f764-4038-9e52-edb2f6264ed5');
</script><br />
Format menu in panelCollection:<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://3.bp.blogspot.com/_ex9GjJ9fvbk/TNBQO8C5JaI/AAAAAAAAAM0/AavymRx_NrY/s1600/1.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="36" src="http://3.bp.blogspot.com/_ex9GjJ9fvbk/TNBQO8C5JaI/AAAAAAAAAM0/AavymRx_NrY/s320/1.JPG" width="320" /></a></div>Status bar showing 'Columns Hidden':<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://2.bp.blogspot.com/_ex9GjJ9fvbk/TNBRhUmn-KI/AAAAAAAAAM4/LY7OR45iRog/s1600/2.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="113" src="http://2.bp.blogspot.com/_ex9GjJ9fvbk/TNBRhUmn-KI/AAAAAAAAAM4/LY7OR45iRog/s320/2.JPG" width="320" /></a></div>Murali Papanahttp://www.blogger.com/profile/06991064825453310705noreply@blogger.com8tag:blogger.com,1999:blog-8389468608715252764.post-3455899484569657322010-11-02T06:38:00.000-07:002010-11-11T04:23:42.942-08:00ADF UI - Setting default display rows to some fixed number (Removing extra space in tables)When you use af:table to display data, then by default the table will occupy more space than actually required (See image below).<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://3.bp.blogspot.com/_ex9GjJ9fvbk/TNAT8aY-6qI/AAAAAAAAAMs/7RW_tO7DO5Q/s1600/1.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="190" src="http://3.bp.blogspot.com/_ex9GjJ9fvbk/TNAT8aY-6qI/AAAAAAAAAMs/7RW_tO7DO5Q/s320/1.JPG" width="320" /></a></div><br />
In the above image, the table contains just two rows, but it's taking more space than required. To avoid that, we need to set table's ContentDelivery="immediate" and AutoHeightRows="<some_fixed_number>". See code below:<br />
<div id="iframeDiv6ce5534c-d549-46a7-a4da-4909b45c8ccc" style="display: none; margin: 0px;"><iframe frameborder="0" id="iframe6ce5534c-d549-46a7-a4da-4909b45c8ccc" src="http://www.blogtrog.com/code.aspx?id=6ce5534c-d549-46a7-a4da-4909b45c8ccc" style="border: 1px solid #e0e0e0; height: 250px; margin: 0px; width: 400px;"></iframe></div><div id="noIframeDiv6ce5534c-d549-46a7-a4da-4909b45c8ccc" style="display: block; margin: 0px;"><pre><div><span style="color: blue;"><</span><span style="color: maroon;">af:table </span><span style="color: red;">value</span><span style="color: blue;">="#{bindings.EmpDeptVO.collectionModel}"</span><span style="color: red;"> var</span><span style="color: blue;">="row"</span><span style="color: red;">
rows</span><span style="color: blue;">="#{bindings.EmpDeptVO.rangeSize}"</span><span style="color: red;">
emptyText</span><span style="color: blue;">="#{bindings.EmpDeptVO.viewable ? 'No data to display.' : 'Access Denied.'}"</span><span style="color: red;">
fetchSize</span><span style="color: blue;">="#{bindings.EmpDeptVO.rangeSize}"</span><span style="color: red;">
rowBandingInterval</span><span style="color: blue;">="0"</span><span style="color: red;">
selectedRowKeys</span><span style="color: blue;">="#{bindings.EmpDeptVO.collectionModel.selectedRow}"</span><span style="color: red;">
selectionListener</span><span style="color: blue;">="#{bindings.EmpDeptVO.collectionModel.makeCurrent}"</span><span style="color: red;">
rowSelection</span><span style="color: blue;">="single"</span><span style="color: red;"> id</span><span style="color: blue;">="t1"</span><span style="color: red;">
partialTriggers</span><span style="color: blue;">=":::qryId1 ::ctb1"</span><span style="color: red;">
columnStretching</span><span style="color: blue;">="column:c1"</span><span style="color: red;">
styleClass</span><span style="color: blue;">="AFStretchWidth"</span><span style="color: red;"> columnSelection</span><span style="color: blue;">="multiple"</span><span style="color: red;">
first</span><span style="color: blue;">="0"</span><span style="color: red;"> contentDelivery</span><span style="color: blue;">="immediate"</span><span style="color: red;"> autoHeightRows</span><span style="color: blue;">="10"</span><span style="color: blue;">></span></div></pre></div><script language="javascript" src="http://www.blogtrog.com/scripts/bt_code.js" type="text/javascript">
</script><script language="javascript" type="text/javascript">
bt_code_init('6ce5534c-d549-46a7-a4da-4909b45c8ccc');
</script><br />
From the above code, we can see that ContentDelivery="immediate" and AutoHeightRows="10". If we set this, if the no. of rows in the table are above 10, it'll just show first 10 rows. We need to scroll down to see the next rows. And, if the no. of rows in the table are below 10, the table just shows only that many no. of rows without any extra space (see image below).<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://4.bp.blogspot.com/_ex9GjJ9fvbk/TNAT9XQyu1I/AAAAAAAAAMw/li7MWiSLMok/s1600/2.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="84" src="http://4.bp.blogspot.com/_ex9GjJ9fvbk/TNAT9XQyu1I/AAAAAAAAAMw/li7MWiSLMok/s320/2.JPG" width="320" /></a></div>Murali Papanahttp://www.blogger.com/profile/06991064825453310705noreply@blogger.com1tag:blogger.com,1999:blog-8389468608715252764.post-90313263456645768702010-11-02T06:12:00.000-07:002010-11-11T04:24:16.199-08:00ADF UI - Hiding 'Detach', 'Wrap' and 'Freeze' icons from af:panelCollectionIf you dropped af:table inside af:panelCollection, then by default the buttons 'Datach' button icon will be rendered. Similarly, if you specify columnSelction="multiple", the buttons 'Wrap' and 'Freeze' will be rendered by default. So, if you want to hide those buttons, just specify featuresOff="detach freeze wrap" for af:panelCollection.<br />
<br />
Sample code below:<br />
<div id="iframeDivdbf2712f-2a07-49af-8daf-5903c4e6c244" style="display: none; margin: 0px;"><iframe frameborder="0" id="iframedbf2712f-2a07-49af-8daf-5903c4e6c244" src="http://www.blogtrog.com/code.aspx?id=dbf2712f-2a07-49af-8daf-5903c4e6c244" style="border: 1px solid #e0e0e0; height: 80px; margin: 0px; width: 400px;"></iframe></div><div id="noIframeDivdbf2712f-2a07-49af-8daf-5903c4e6c244" style="display: block; margin: 0px;"><pre><div><span style="color: blue;"><</span><span style="color: maroon;">af:panelCollection </span><span style="color: red;">id</span><span style="color: blue;">="pc1"</span><span style="color: red;"> styleClass</span><span style="color: blue;">="AFStretchWidth"</span><span style="color: red;">
featuresOff</span><span style="color: blue;">="detach freeze wrap"</span><span style="color: blue;">></span></div></pre></div><script language="javascript" src="http://www.blogtrog.com/scripts/bt_code.js" type="text/javascript">
</script><script language="javascript" type="text/javascript">
bt_code_init('dbf2712f-2a07-49af-8daf-5903c4e6c244');
</script><br />
PanelCollection without "featuresOff" set:<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://4.bp.blogspot.com/_ex9GjJ9fvbk/TNAN1PQwoeI/AAAAAAAAAMk/V_frtu7fynI/s1600/1.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="66" src="http://4.bp.blogspot.com/_ex9GjJ9fvbk/TNAN1PQwoeI/AAAAAAAAAMk/V_frtu7fynI/s320/1.JPG" width="320" /></a></div><br />
After setting featuresOff="detach freeze wrap":<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://3.bp.blogspot.com/_ex9GjJ9fvbk/TNAN4I8HD1I/AAAAAAAAAMo/qZ7dnUfUFJg/s1600/2.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="82" src="http://3.bp.blogspot.com/_ex9GjJ9fvbk/TNAN4I8HD1I/AAAAAAAAAMo/qZ7dnUfUFJg/s320/2.JPG" width="320" /></a></div><br />
As you can see, the panelCollection is clean without 'Detach', 'Freeze' and 'Wrap' icons after setting featuresOff="detach freeze wrap" .Murali Papanahttp://www.blogger.com/profile/06991064825453310705noreply@blogger.com12tag:blogger.com,1999:blog-8389468608715252764.post-44044824311820395522010-11-02T05:51:00.000-07:002010-11-11T04:24:45.243-08:00ADF UI - Implementing 'Export to Excel' functionalityHere, we'll see how to implement 'Export to Excel' functionality for ADF tables. For example you have a search results table and you want to export the search results to excel sheet on clicking the button 'Export to Excel'.<br />
<br />
To implement this, Drag and drop <b><af:exportCollectionActionListener></b> on 'Export to Excel' button. and specify <b>exportedId</b>="<i><span class="Apple-style-span" style="color: blue;"><search_results_table_id></span></i>" and <b>type</b>="<i><span class="Apple-style-span" style="color: blue;">excelHTML</span></i>". Give <b>fileName</b>="<i><span class="Apple-style-span" style="color: blue;">excel_file_name.xls</span></i>" and <b>title</b>="<i><span class="Apple-style-span" style="color: blue;">excel_sheet_name_within_excel_file</span></i>".<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://4.bp.blogspot.com/_ex9GjJ9fvbk/TNAIabtQPXI/AAAAAAAAAMU/kA7mTkkf3ZI/s1600/1.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://4.bp.blogspot.com/_ex9GjJ9fvbk/TNAIabtQPXI/AAAAAAAAAMU/kA7mTkkf3ZI/s1600/1.JPG" /></a></div><br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://3.bp.blogspot.com/_ex9GjJ9fvbk/TNAIbCuHyoI/AAAAAAAAAMY/Bh_EQDm_254/s1600/2.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="120" src="http://3.bp.blogspot.com/_ex9GjJ9fvbk/TNAIbCuHyoI/AAAAAAAAAMY/Bh_EQDm_254/s320/2.JPG" width="320" /></a></div><br />
The 'Export to Excel' toolbar button in 'Structure' window:<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://3.bp.blogspot.com/_ex9GjJ9fvbk/TNAJxLPuVsI/AAAAAAAAAMg/K1RzYWktV2U/s1600/4.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://3.bp.blogspot.com/_ex9GjJ9fvbk/TNAJxLPuVsI/AAAAAAAAAMg/K1RzYWktV2U/s1600/4.JPG" /></a></div><br />
Here is the code:<br />
<div id="iframeDiv88882167-c7d8-46bc-98dd-2d04f8297967" style="display: none; margin: 0px;"><iframe frameborder="0" id="iframe88882167-c7d8-46bc-98dd-2d04f8297967" src="http://www.blogtrog.com/code.aspx?id=88882167-c7d8-46bc-98dd-2d04f8297967" style="border: 1px solid #e0e0e0; height: 200px; margin: 0px; width: 400px;"></iframe></div><div id="noIframeDiv88882167-c7d8-46bc-98dd-2d04f8297967" style="display: block; margin: 0px;"><pre><div><span style="color: blue;"><</span><span style="color: maroon;">af:commandToolbarButton </span><span style="color: red;">text</span><span style="color: blue;">="Export to Excel"</span><span style="color: red;">
id</span><span style="color: blue;">="commandToolbarButton2"</span><span style="color: red;">
disabled</span><span style="color: blue;">="#{bindings.EmpDeptVO.currentRow==null}"</span><span style="color: red;">
partialTriggers</span><span style="color: blue;">="t1"</span><span style="color: blue;">></span><span style="color: black;">
</span><span style="color: blue;"><</span><span style="color: maroon;">af:exportCollectionActionListener </span><span style="color: red;">type</span><span style="color: blue;">="excelHTML"</span><span style="color: red;">
exportedId</span><span style="color: blue;">="t1"</span><span style="color: red;">
filename</span><span style="color: blue;">="SearchResults.xls"</span><span style="color: red;">
title</span><span style="color: blue;">="Search Results"</span><span style="color: blue;">/></span><span style="color: black;">
</span><span style="color: blue;"></</span><span style="color: maroon;">af:commandToolbarButton</span><span style="color: blue;">></span></div></pre></div><script language="javascript" src="http://www.blogtrog.com/scripts/bt_code.js" type="text/javascript">
</script><script language="javascript" type="text/javascript">
bt_code_init('88882167-c7d8-46bc-98dd-2d04f8297967');
</script><br />
That's it. Now, when you run the page and click on 'Export to Excel' button, it'll generate the excel file and asks to open or save the Excel.<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://3.bp.blogspot.com/_ex9GjJ9fvbk/TNAJNppdLQI/AAAAAAAAAMc/PuH_IwMXwfk/s1600/3.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="249" src="http://3.bp.blogspot.com/_ex9GjJ9fvbk/TNAJNppdLQI/AAAAAAAAAMc/PuH_IwMXwfk/s320/3.JPG" width="320" /></a></div><br />
Enjoy!!Murali Papanahttp://www.blogger.com/profile/06991064825453310705noreply@blogger.com14