Wednesday, January 8, 2014

ATG FormHandler - Create a New FormHandler

Form Handler Introduction :

Form handlers are specialized Nucleus components that can be embedded in our JSPs to do form validation and based on the results do certain actions like inserting into database, forwarding the user to some other JSP page etc. Form Handlers is based on  “Service to Workers” (push based) approach of MVC2 design pattern.





Step 1 : Create a Form Handler java class for example "LoginFormHandler"

LoginFormHandler.java


Step 2 : Create a properties file for LoginFormHandler class


Step 3 : Access in Login JSP

Enable java Debugger in Eclipse


ATG Droplet - Creating a New Droplet

Droplet Introduction : 

Dynamo Servlet Beans are specialized Nucleus components that can be embedded in our JSPs to display dynamic content.  Droplets are based on MVC2 Dispatcher View (pull based) design pattern.

Writing New Droplet :

CustomDroplet.java

Step 1 :  Create a Java file for example "CustomDroplet" extending DynamoServlet  and override Service method to contruct the logic.

public class CustomDroplet extends DynamoServlet {

public void service(DynamoHttpServletRequest dynamoHttpServletRequest,
            DynamoHttpServletResponse dynamoHttpServletResponse)
            throws ServletException, IOException {


dynamoHttpServletRequest.setParameter("CustomValue", "i am a new user");

dynamoHttpServletRequest.serviceLocalParameter("output",
                dynamoHttpServletRequest, dynamoHttpServletResponse);


}

Here serviceLocalParameter can also be replaceable with serviceParameter. serviceLocalParameter method makes the output parameter available only to that droplet i .e (DynamoServlet  block(as show below) in jsp  and outside the droplet block, the parameter wont be available) and where as serviceParameter makes the output accessible outside the droplet also.

Step 2 : Create a properties file for example "CustomDroplet" with scope as global.

CustomDroplet.properties

$class=com.view.CustomDroplet

Step 3: Access the Droplet in JSP.

 CustomeDropletPage.jsp

<dsp:page>
<dsp:importbean bean="/com/view/CustomDroplet"/>

<dsp:droplet name="CustomDroplet">
    <dsp:oparam name="output">
        New Value: <b><dsp:valueof param="CustomValue">CustomValueis Null</dsp:valueof></b> <br/>
    </dsp:oparam>
</dsp:droplet>

</dsp:page>