ART#109 - What is a droplet? ( OR Dynamo Servlet Bean)



Droplets.. are known by many names in many places viz. Dynamo Servlet Beans, ATG Servlet Beans, ATG Custom Servlets, Dynamo Servlet etc. etc... they all refer to our very own "Droplet".

What is a droplet?
A droplet is basically ATG's custom servlet which has some atg-specific customization. Just like we use HttpServlet in J2EE, we have have DynamoServlet class which implements javax.servlet.Servlet interface in ATG. (Of course there are many layers of implementation between Servlet and DynamoServlet).
Now, our DynamoServlet class has javax.servlet.Servlet in its hierarchy, therefore it becomes a servlet. There is also a layer of GenericService between Servlet and DynamoServlet to provide it with some nucleus capabilities (so that it can act as a nucleus component). Below diagram describes this:-







Therefore, to create a droplet, we extend "DynamoServlet" class, and override its "service()" method to run our custom code. Now, let us move on to create our very own "Hello World" droplet !!

How to create a droplet?
Since we are familiar with extending out of the box component, creation of droplet would be a piece of cake.
All you need to do is, 
1. Create a new class and extend atg.servlet.DynamoServlet
2. Override "service()" method and write your code. This method is a starting point for your droplet, when it is invoked.



3. Create a configuration file, and set the $class nucleus property to point to your custom class created in Step#1.










How to invoke a droplet?
Just like servlets in J2EE, Droplets are generally invoked from JSPs. Whenever, we are writing JSPs, we make sure that we do not add any "logic" in JSPs. If we want some of the content to be dynamically displayed using a logic, we use a droplet!

Let us create a JSP, and use it to invoke a droplet.
1. Create a JSP in the following location in your module:-
<ATG_MODULE>/j2ee-apps/<YOUR_APP_NAME>/<YOUR_WAR_FILE_NAME>.war/helloWorld.jsp

2. Add the <%@ taglib uri="/dspTaglib" prefix="dsp" %> on top of the jsp. This is to make your JSP aware of ATG's very own custom "dsp" tag library.

3. Invoke your droplet using <dsp:droplet> tags:-

<dsp:droplet name="{YOUR_DROPLET_COMPONENT_PATH}">
</dsp:droplet>

NOTE: Try to use tags in the form <dsp:droplet></dsp:droplet> and NOT 
<dsp:droplet name="..something.." />. 
Sometimes ATG does not like that and your JSP is not executed correctly. See below screenshot for details:-





The JSP would produce the following output:-
















Now that we know how a droplet is created and how we can invoke it, we can easily display dynamic content on our web-application!
Let us move on and understand droplets in more detail..


Back



Next





15 comments:

  1. can you please share your email id ?

    ReplyDelete
    Replies
    1. You can post your questions here and i'll be glad to answer them.

      Delete
  2. Hi Monis, I tried the same steps as given here to create a droplet. The output of my JSP is in plain text and not HTML. Infact the HTML tags also show up in the browser.

    ReplyDelete
    Replies
    1. Hi Jaya,

      You can try adding

      pResponse.setContentType("text/html");

      in your droplet. This will render HTML on your page instead of plain-text.

      Delete
  3. And the same thing happens with my form handler? Any thoughts?

    ReplyDelete
    Replies
    1. The basic component-class structure is same, but a formhandler is different in many ways.
      You can have a look at the article HERE (ART#113): http://learnoracleatg.blogspot.in/2014/11/art113-how-to-usecreate-formhandlers-in.html

      Delete
  4. Hi monis, I'm getting

    Error 500--Internal Server Error

    javax.servlet.jsp.JspException: CANT_FIND_DROPLET: Unable to find the droplet with name "/atg/hello/HelloWorldComponent". I have done same as above.

    Can you help y this is happening.

    ReplyDelete
    Replies
    1. This means that your component is not getting resolved.
      Make sure that the HelloWorldComponent.properties is present in the config-path inside the folders /atg/hello

      Delete
  5. hi Monis,

    can you please explain what exactly is the difference between component and droplet

    ReplyDelete
    Replies
    1. A droplet is a special type of component.
      The class you use in a droplet's component must extend DynamoHttpServlet.

      Delete
    2. In a normal component (non-droplet), you can have any class.

      Delete
  6. hi Monis,

    can you please explain the difference between droplet and component.

    ReplyDelete
    Replies
    1. a Droplet is a special type of component which extends DynamoServlet and is generally used for display logic.

      Delete

Subscribe

Get All The Latest Updates Delivered Straight Into Your Inbox For Free!

Flickr