Sunday 21 February 2016

Creating Custom Droplets



Droplet:
In simple Droplet is a combination of Servlets and javaBeans. You can embed these droplets in your JSPs to display dynamic content. These droplets can be nested and pass parameters between themselves. These Droplets are also called as DynamoServlets.There are lot many out-of–box droplets provided by ATG.They are categorized into
·         Standard Servlet Beans
                Some of them include:


Ø  IsEmpty
Ø  IsNull
Ø  ProtocolChange
Ø  Range
Ø  Redirect
Ø  Switch
Ø  TableForEach
Ø  TableRange
Ø  BeanProperty
Ø  Cache
Ø  Compare
Ø  CurrencyFormatter
Ø  ErrorMessageForEach
Ø  For
Ø  ForEach
Ø  Format




·         Repository  Servlet Beans
Some of them include:


Ø  ItemLookupDroplet
Ø  NavHistoryCollector
Ø  PipelineChainInvocation
Ø  PossibleValues
Ø  RelationalViewDroplet
Ø  RQLQueryForEach
Ø  RQLQueryRange
Ø  SQLQueryForEach
Ø  SQLQueryRange



·         XML  Servlet Beans
Some of them include:


Ø  NodeForEach
Ø  NodeMatch
Ø  DOM
Ø  XML Transform



·         Transaction  Servlet Beans
Ø  EndTransactionDroplet
Ø  TransactionDroplet
Parameters of a Servlet bean include:
          Input Parameter
         Input parameters are parameters you pass to the Servlet Beans
          Output Parameters
         Output parameters are parameters whose values are set by the Servlet bean
          Open Parameters
-      Open parameters contain the HTML that is rendered by the servlet bean. The HTML that an open parameter renders is marked off by beginning and ending dsp:oparam tags. This HTML can include dynamic elements, such as dsp:valueof tags, for displaying the values of output parameters
Parameter Scope :
o   In general, the values of input, output, and open parameters apply only within the servlet bean that uses them ie., Private Scope.
o   A parameter used by a servlet bean is undefined outside the beginning and ending dsp:droplet tags.
o   The value of a page parameter applies everywhere on the page, including within the servlet bean (page scope).
o   If the servlet bean has a parameter with the same name as the page parameter, the servlet bean parameter value overrides the page value, but only within the servlet bean
Steps to create a Custom Droplet:
Step 1: Create a new ATG module.  In Source folder create a Droplet class.
Step 2: Create a Properties file for the Droplet in the config folder
Example:  TestDroplet.properties
Step 3: Droplet class should extend javax.servlet.Servlet or atg.servlet.DynamoServlet class
Step 4:Implement the service method of the Servlet

Example:

public class TestDroplet  extends DynamoServlet {
 int name;
 public TestDroplet () {
    System.out.println ("InTestDroplet Constructor");
 }
 public void service (DynamoHttpServletRequest request, DynamoHttpServletResponse response) throws ServletException, IOException {
ServletOutputStream out = response.getOutputStream ();
    out.println ("Hello World! My name is "+name);
 }
 public int getName () { return name; }
 public void setName (int name) {
    System.out.println ("setting name attribute to " + name);
    this.age = age;
 }
}
Step 5: call the droplet in your JSP as shown below.
<%@ taglib uri="/dspTaglib" prefix="dsp" %>
<dsp:page>
<html>
<head><title>Hello World</title></head>
<body>
Hello World!!!
<dsp:droplet name="/TestDroplet">
</dsp:droplet>
</body>
</html>
</dsp:page>

Step 6: Access your jsp from Browser. You will see the output.

WRITING CUSTOMIZED DROPLETS WITH PARAMETERS:

File name: test.jsp
<%@ taglib uri="/dspTaglib" prefix="dsp" %>
<dsp:page>
<html>
<head>
<title>DSBtest</title>
</head>
<body>
<h1>DSB Test </h1>
<p>From a java object:
<dsp:droplet name="/atg/droplet/test1">
<dsp:param name="name" value="atg-tips"/>
<dsp:oparam name="output">
          Name is : <dsp:valueof param="myName"></dsp:valueof><br>
</dsp:oparam>
<dsp:oparam name="output1">
          Project is : <dsp:valueof param="project"></dsp:valueof><br>
</dsp:oparam>
<dsp:oparam name="output2">
          Module is : <dsp:valueof param="module"></dsp:valueof><br>
</dsp:oparam>
</dsp:droplet>
</body>
</html>
</dsp:page>
File name: test1.properties
$class=test.DropletA
$scope=global



File name: DropletA.java
public class DropletA extends DynamoServlet {
          @Override
public void service(DynamoHttpServletRequest request,
DynamoHttpServletResponse response) throws ServletException,
                             IOException {
super.service(request, response);
request.setParameter("project", "MyProject");
System.out.println("DropletA.service() request object is : "+request);
request.serviceParameter("output1",request, response);
request.setParameter("module", "myModule");
System.out.println("DropletA.service() request object is : "+request);
request.serviceParameter("output2",request, response);

          }

}

You can Create Droplets with Parameters also. Try it out and Post a comment for any Queries.

0 comments:

Post a Comment

 
;