Loading
Spring DWR Example with JST

Java Quick Notes

Refresh Your Java - Before Java Interview

We are Agile, believe in less Documentation - Only Quick notes (Java Interview Questions) of Java/J2ee Read more....


Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet

Go to SiteMap

Q)  Spring DWR Example with JavaScript Template


Ans)

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>



Back to top

------------------------- We hope you got necessary Info On -----------------------------------------

Spring DWR Example with JST


Spring DWR Example with JST

-------------------------------------------------------------------------------------------------------



Face Book
Request for a Mock Interview/Training

Get a PDF

Face Book
Same look (Read) on any device, this is Ads free