Refresh Your Java - Before Java Interview
We are Agile, believe in less Documentation - Only Quick notes (Java Interview Questions) of Java/J2ee Read more....
Spring DWR is called known as Spring Direct Web
Remoting , here is the Full working example
of DWR with
.jst (Java Script Template) file.
Server Side Changes
:
Step 1:
Create your Java
Service Class with Business methods, in our example we have only
one method
"loadContractInformationByUser"
public class ContactManager implements Serializable {
public
List<contractIDInformationDTO>
loadContractInformationByUser(String userId){
return retValue;
}
}
Step 2:
Add this Service Class to your Spring
Configuration file and use "<dwr:remote>"
element to inform Spring Container
that this
is going to be used for Web Remoting.
<bean
id="ContactManager"
class="com.salesorder.bl.ContactManager"
scope="session">
<dwr:remote
javascript="ContactManagerJS">
<dwr:include
method="loadContractInformationByUser"
/>
<dwr:filter
class="com.salesorder.ajax.DwrSecurityFilter"
/>
</dwr:remote>
<property
name="contractWrapperService"
ref="contractWrapperService" />
</bean>
Client Side Changes:
Step 3:
Add the following JS files to your JSP page.
<script type="text/JavaScript"
src="<%=request.getContextPath()%>/dwr/interface/ContractManagerJS.js"></script>
<script type="text/JavaScript"
src="<%=request.getContextPath()%>/dwr/engine.js"></script>
<script type="text/JavaScript"
src="<%=request.getContextPath()%>/dwr/util.js"></script>
Step 4:
Add the following JS method to make a
Server side call, please note that we are invoking
your
business method by using "ContactManagerJS"
which will be created by Spring Framework
based on your
Service Class.
function
populatecontractInformation(){
ContactManagerJS.loadcontractByUser(<%=request.getParameter("userObjid")%>,
function(data){
var obj =
{ contractInfoList : data , contactidShow :
window.contractIDShow};
TrimPath.processTemplateFile('/web/templates/jst/contractIDInformation.jst',obj,$('contractInfoInSession'));
});
}
Step 5:
Create the contractInfoTable.jst
template file as shown below.
<table
border="1"
id="contractInfoTable"
class="formLayout">
<tr>
<td
style='width:100px;'><label><b>Product
Name</b></label></td>
{if cirIDShow ==
0}
<td
style='width:100px;'><label><b>Contract
ID
</b></label></td>
{/if}
{if cirIDShow
== 1}
<td
style='width:100px;'><label><b>Old
Contract ID
</b></label></td>
<td
style='width:100px;'><label><b>New
Contract ID
</b></label></td>
{/if}
</tr>
{for contract in
contractInfoList}
<tr>
<td>
${contract.productName}
</td>
<td>
${contract.oldcontractID}
</td>
{if cirIDShow == 1}
<td>
${contract.contractID}
{if contract.oldcontractID != null &&
contract.oldcontractID != "" &&
contract.oldcontractID != contract.contractID}
<img src="images/your.png"
width="20"
height="14">
{/if}
</td>
{/if}
</tr>
{forelse}
<tr><td
colspan="4"></td></tr>
{/for}
</table>
This Portal is intended to put all Java/J2ee related topics at one single place for quick referance, not only Technical , but also the Project Management Related thing such as Development Process methodoogies build process, unit testing etc.,
This Portal has More than 500 Java Interview Questions (also could be Considered as Quick Notes) very neatly separated topic by topic with simple diagrams which makes you easily understandable. Importantly these are from our Realtime expericance.