skip to main | skip to sidebar

Java Programs and Examples with Output

Pages

  • Home
 
  • RSS
  • Twitter
Showing posts with label Tapestry Components. Show all posts
Showing posts with label Tapestry Components. Show all posts
Friday, September 7, 2012

An Overview of Tapestry Components

Posted by Admin at 11:45 AM – 0 comments
 
Introduction: 
Tapestry is a component-based web application framework, written in Java. Tapestry is
more than a simple templating system; Tapestry builds on the Java Servlet API to build a
platform for creating dynamic, interactive web sites. More than just another templating
language, Tapestry is a real framework for building complex applications from simple,
reusable components. The current stable Tapestry release is version 5.1.0.5. Version 4 and
below are relatively similar, whereas version 5 contains substantial changes. This
document describes the parameters and bindings of Tapestry in detail. It is not a tutorial
that is available as a separate document. Instead, this is a guide to some of the internals of
Tapestry, and is intended for experienced developers who wish to leverage Tapestry fully.

An overview of Tapestry:
Tapestry is an object-oriented Java web application framework to implement applications
in accordance with the model-view-controller design pattern.

MVC Design Pattern:
The main aim of MVC design pattern is to separate the business logic and data (the Model)
from the display logic (the View).
Ideally, the Model should have no idea of what displays its data (and how that data is
displayed) as there can potentially be numerous different views. The View in its turn
should have no idea of where the data it displays come from, as data can potentially come
from just anywhere. It is for the piece of code named Controller to ensure that a correct
piece of data was sent for processing to the Model and that the result of that processing
was forwarded to a proper view.

Tapestry – Component Centric:
The hardest part of understanding Tapestry is the fact that it is component-centric not
operation-centric. Most web technologies (Struts , servlets, PHP, etc.) are operation-centric.
We create servlets (or Actions, or what have you) that are invoked when a user clicks a link
or submits a form. We are responsible for selecting an appropriate URL, and the name and
type of any query parameters, so that we can pass along the information that we need in
the URL.

Everything is different inside Tapestry. Tapestry applications consist of pages; pages are
constructed from smaller components. Components may themselves be constructed from
other components. Every page has a unique name, and every component within a page
has its own unique id ... this is a component object model. Effectively, every component
has an address that can easily be incorporated into a URL.
In practical terms, we don't write a servlet for the add-item-to-shopping-cart operation. In
fact, we don't even write an add-item-to-shopping-cart component. What we do is take an
 existing component, such as Direct Link , and configure it. When the component renders, it
will create a callback URL. When you click that link, the callback URL (which includes the
name of the page and the id of the component within the page) will invoke a method on
the component ... and that method invokes your application-specific listener method.

Listener Methods:
Listener methods in Tapestry are very similar in intent to delegates in C#. In both cases, a
method of a particular object instance is represented as an object. We supply just the
listener method ... not an entire servlet. Tapestry takes care that our listener method is
invoked at the right time, under the right conditions. You don't have to think about how to
build that URL, what data goes in the URL, or how to hook it up to your application-specific
code--that's all handled by the framework.

Parameters and Bindings:
Tapestry components are designed to work with each other, within the context of a page
and application. The process of rendering a page is largely about pulling information from
a source into a component and doing something with it. For example, on a welcome page,
a component might get the userName property from the visit object and insert it into the
HTML response. Each component has a specific set of parameters. Parameters have a
name, a type and may be required or optional.
Parameters define the type of value needed, but not the actual value. This value is
provided by a special object called a binding. The binding is a bridge between the
component and the parameter value, exposing that value to the component as it is
needed. The reason for all this is to allow pages, and the components within them, to be
shared by many concurrent sessions ... a major facet in Tapestry's strategy for maintaining
application scalability. When a component needs the value of one of its parameters, it
must obtain the correct binding, an instance of interface IBinding, and invoke methods on
the binding to get the value from the binding. Additional methods are used with output
parameters to update the binding property.
There are two types of bindings: static and dynamic.
Static Bindings:
Static bindings are read-only; the value for the binding is specified in the component
specification as shown below.
<component id="now" type="Insert"> <binding name="value" value="currentDate"/> </component>
This is understood by Tapestry in the following way: to obtain the value, evaluate the
currentDate expression. Which means: go to the page class, find a method named
getCurrentDate(), invoke it, and whatever it returns will be the value you are looking for. So
the next step is to create the page class with the getCurrentDate() method in it.
Dynamic Bindings:
Dynamic bindings are more prevalent and useful. A dynamic binding uses a JavaBeans
property name to retrieve the value when needed by the component. The source of this
data is a property of some component. In fact, dynamic bindings use property paths,
allowing a binding to 'crawl' deeply through an object graph to access the value it needs.
This frees the components from relying totally on the properties of their container, instead
they are free to access properties of more distant objects.


Connected Parameters:
In most cases, a developer is not interested in bindings; an easier model for developers is
one in which Tapestry uses the parameters and bindings to set properties of the
component automatically. Starting in release 2.1, Tapestry includes this behavior, with
some constraints and limitations.
Part of the <parameter> specification for a parameter is the direction, which can be one of
the following values:
in
Input parameter; the value is drawn from the binding (if bound) and applied to the
corresponding component property just before rendering the component.
form
A parameter which matches the semantics of a form component. The parameter is treated
like an in parameter when the page is rendering. When the form containing the
component is submitted, the connected property is read (after the component renders),
and the value applied to the parameter.
custom
Tapestry does not try to connect the parameter with any property; the component is
responsible for accessing the binding and retrieving or setting values. This type must be
used for any kind of output parameter, or for an input parameter where the property may
be accessed other than during the rendering of the component.
Defining a parameter as direction in causes Tapestry to connect the parameter to the
corresponding property of the component. The parameter specification must identify the
Java type of the property. Properties must be read/write (they must have both getter and
setter methods).
Tapestry will set properties from parameters just before rendering the component. After
the component renders, the parameters are cleared; they are returned to inital values.
Tapestry reads these initial values just before it sets the properties the first time. This
makes it very easy to set defaults for optional parameters: just provide a default value for
the corresponding instance variable.
Connected Parameter - Specification

<specification ...>
<parameter name="color" direction="in" java-type="java.awt.Color"/>
...
Connected Parameter - Java Code
public class ColorComponent extends AbstractComponent {
 private Color color = Color.RED;

 public Color getColor()

 {
  return color;
 }

 public void setColor(Color color) {
  this.color = color;
 }

 protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle) throws RequestCycleException 
 { 
 writer.begin("font"); 
 writer.attribute("color", ^RequestContext;.encodeColor(color); 
 renderWrapped(writer, cycle); 
 writer.end(); 
 }
}

In this example, the component writes its content inside a <font> element, with the HTML
color attribute set from the color parameter. RequestContext includes a static
convienience method for converting from a Color object to an encoded color that will be
meaningful to a web browser.
The parameter is optional and defaults to red if not specified (that is, if the parameter is not
bound). At runtime, Tapestry will invoke setColor() first (if the color parameter is bound). It
will then invoke renderComponent(). Finally (even if renderComponent() throws an
exception) it will invoke setColor() again, to restore it back to the default value, Color.RED.
This code includes a defect: because the parameter is optional, there is nothing to prevent
it from being bound to null.

Formal vs Informal Parameters:
Tapestry components have two types of parameters: formal and informal.

Formal Parameter:
Formal parameters are parameters defined in the component specification. Each formal
parameter has a specific (case sensitive) name and may be required or optional.
In many cases, there is a one-to-one mapping between a Tapestry component and a
specific HTML tag. For example, Body and <body>, Form and <form>, etc. In other cases, a
Tapestry component produces a known single HTML tag. For example, ActionLink,
DirectLink, PageLink and ServiceLink all produce an <a> tag. To support truly rich
interfaces, it is often necessary to specify additional attributes of the HTML tags; usually
this means setting the class of a tag so as to get visual properties from a style sheet. In
other cases, display attributes may be specified inline. In theory, these components could
define additional formal parameters for each possible HTML attribute, but there are a huge
number of possible attributes, many of which are specific to a particular browser.
  
Informal Parameter:
Instead, Tapestry has the concept of an informal parameter. This is an "additional"
parameter, not specified in the component's specification. In most cases, where informal
parameters are allowed, they are added as additional HTML attributes (there are a few
special exceptions, such as the Script component).
Informal parameters do have some limitations. Informal parameters that conflict with the
names of any formal parameters, or with any of the HTML attributes generated directly by
the component, are silently ommitted. The comparison is case-insensitve. Thus, for a
DirectLink component, you can not change the href attribute, even if you supply a Href (or
other variation) informal parameter.
Not all Tapestry components even allow informal parameters; this is explicitly stated in the
component specification.

Conclusion:
Since every entity of Tapestry project can be analyzed separately, it is easy to edit the code
as well as debug the errors when we create a complex web project. Tapestry components
are "black boxes" that are involved with both rendering HTML responses and responding
to HTTP requests. In this document we have learnt the fundamentals of different
parameters and components that are used in Tapestry.
[ Read More ]
Read more...
Older Posts
Subscribe to: Posts ( Atom )

List of Java Programs

  • Java Program to check Greater between the Two Number
  • Java Program to find that given number is Palindrome or not
  • Java Program to Demonstrate the Use of Pre and Post Operator
  • Java Program to Reverse the Given Number
  • Java Program to Print Number in the Given Data Type
  • Program to Demonstrate Skipping using Continue
  • Program to find whether entered character is a vowel or Consonant
  • Java Program to Calculate the Sum of Digits of Given Number
  • How to swap two numbers using only two variables
  • Checking the Given Number is Armstrong or Not
  • Average an Array of Values
  • Display ASCII Code Instead of Character
  • Comparison of Two Variable using If
  • Printing Table In java using While Loop
  • Generate Random Number Using Math.Random Function
  • To Find roots of Quadratic Equation
  • Performing Arithmetic Opration on Two Variable
  • Concatenation of Two String in Java
  • Command Line Argument in JAVA
  • Java Hello World Program
  • Calculate Circle Perimeter | Java Program
  • Calculate the Area of Circle | Java Program
  • To Find Whether Given Year is a Leap Year or not
  • Popular
  • Recent
  • Archives

Total Pageviews

Sparkline

Followers

Popular Posts of This Week

  • Implementation of a basic generic tree, with labels of type T - Data Structure
    // This implements a basic generic tree, with labels of type T, // pointer to the parent node, and a singly linked list of children nodes...
  • Java program to create a Binary Heap and Perform various operation
    A binary heap (min-heap) is a complete binary tree with elements from a partially ordered set, such that the element at every node is less ...
  • Sort an Integer array with Bucket Sort
    Here is a java program to Sort an Integer array with Bucket Sort class BucketSort { public int[] bucketSort(int[] array) { /...
  • Merge-Sort Algorithm implementation in JAVA
    Merge-Sort Function void MergeSort(int low, int high) // a[low : high] is a global array to be sorted. // Small(P) is true if there...
  • To Sort an Interger Array using Shell Sort
    To Sort an Interger Array using Shell Sort class ShellSort { public static int[] shellSort(int[] array) { int N = array.length; ...
  • Create an Adjacency matrix Graph and perform Add and Remove operation
    import java.util.ArrayList; import java.util.ArrayList; import java.util.LinkedList; import java.util.List; import java.util.Queue; import...
  • Use a StreamTokenizer object to parse a string separated by commas
     Use a StreamTokenizer object to parse a string entered from the keyboard containing a series of data items separated by commas and output ...
  • Singly linked list with header - Data Structure
    class OrderedList { private int value; private OrderedList next; // Note: No setValue() method or setNext() methods are provide...
  • Find File in a Zip File Example
    Find File in a Zip File Example. This Java example shows how to find a particular file in a zip file using ZipFile ...
  • Stack implemented as array - Data Structure
    // Stack implemented as array public class ArrayStack<T> { private T[] stack; private int numElements = 0; // points to s...
Powered by Blogger.

Archives

  • ▼  2014 ( 4 )
    • ▼  August ( 4 )
      • Java program to create a Binary Heap and Perform v...
      • Create an Adjacency matrix Graph and perform Add a...
      • To Sort an Interger Array using Shell Sort
      • Sort an Integer array with Bucket Sort
  • ►  2013 ( 6 )
    • ►  August ( 1 )
    • ►  April ( 5 )
  • ►  2012 ( 673 )
    • ►  November ( 9 )
    • ►  October ( 223 )
    • ►  September ( 272 )
    • ►  August ( 2 )
    • ►  June ( 1 )
    • ►  February ( 67 )
    • ►  January ( 99 )
 

Our Blogs

  • Linux Tutorial
  • C Programming Tutorial

Labels

  • Agile Methodology ( 1 )
  • Algorithm ( 3 )
  • AntiSamy ( 1 )
  • Arithmetic Operation ( 1 )
  • Array Example ( 9 )
  • ArrayList Examples ( 11 )
  • Average an Array of Values ( 1 )
  • Barcode Example ( 1 )
  • Basic Java Programs ( 34 )
  • Bing API Example ( 2 )
  • BitSet Example ( 1 )
  • Boolean Example ( 1 )
  • Bouncy Castle API ( 1 )
  • Break Statement ( 2 )
  • BufferedReader Example ( 2 )
  • Calendar Example ( 1 )
  • Chart Generation Example ( 1 )
  • Command Line Argument ( 1 )
  • Comparator Example ( 1 )
  • Concatenation of String ( 1 )
  • Continue Statement ( 1 )
  • Control Structure ( 1 )
  • Copy File Example ( 1 )
  • CRC Example ( 1 )
  • CSV Example ( 6 )
  • Data Structure ( 5 )
  • Date Example ( 2 )
  • Directory Example ( 1 )
  • Do - While Loop Example ( 1 )
  • Domino Database ( 1 )
  • Email Example ( 8 )
  • Encryption Example ( 3 )
  • Excel Example ( 15 )
  • Factorial Example ( 1 )
  • File Upload Example ( 1 )
  • Find Roots of Quadratic Equation ( 1 )
  • FTP Example ( 2 )
  • Graph Examples ( 1 )
  • Greater between Two Numbers ( 1 )
  • GSON Library ( 1 )
  • HashMap Example ( 1 )
  • HashSet Example ( 1 )
  • Hello World Program ( 1 )
  • If Condition ( 2 )
  • Inner Class Example ( 1 )
  • iText Example ( 3 )
  • JAR File ( 1 )
  • JAVA Applet ( 1 )
  • Java Applications ( 1 )
  • Java AWT Example ( 9 )
  • Java Certification ( 1 )
  • Java Class Examples ( 15 )
  • Java Collection Example ( 1 )
  • Java Command Example ( 4 )
  • Java Constructor Examples ( 1 )
  • Java Currency Example ( 1 )
  • Java Database Example ( 3 )
  • Java Date and Time Example ( 3 )
  • Java DateFormat Example ( 3 )
  • Java Examples ( 2 )
  • Java Exception Example ( 5 )
  • Java File Example ( 22 )
  • Java GUI Example ( 1 )
  • Java Image Examle ( 3 )
  • Java Inheritance Example ( 3 )
  • Java Input Output Example ( 1 )
  • Java IO Example ( 3 )
  • Java Jar Example ( 1 )
  • Java JSON Example ( 3 )
  • Java Mail Examples ( 4 )
  • Java Map Example ( 5 )
  • Java MapReduce Example ( 2 )
  • Java MultiThreading Example ( 7 )
  • Java Network Example ( 9 )
  • Java Package ( 1 )
  • Java Programs ( 1 )
  • Java RMI ( 1 )
  • Java Robot Class Examples ( 2 )
  • Java Runtime Example ( 1 )
  • Java Swing Example ( 9 )
  • Java Util Example ( 1 )
  • Java Vector Example ( 4 )
  • Java Voice Example ( 1 )
  • Java Webservice Example ( 1 )
  • Java XML Example ( 3 )
  • Java Zip Class Examples ( 2 )
  • JDBC ( 9 )
  • JDK Version Comparison ( 1 )
  • JFrame Example ( 3 )
  • JOptionPane Dialog Example ( 1 )
  • JPanel Example ( 1 )
  • JSP Example ( 2 )
  • JSTL Example ( 1 )
  • jUnit Example ( 2 )
  • LinkedList Example ( 2 )
  • List Example ( 1 )
  • Long Variable ( 1 )
  • Lottery Nubmer ( 1 )
  • MD5 Hashing Example ( 3 )
  • Memory Management Example ( 1 )
  • Method Override ( 1 )
  • MIDI Sound ( 8 )
  • Module Operator Example ( 2 )
  • Multiplication Table ( 1 )
  • Observer Interface Example ( 1 )
  • Operator Example ( 5 )
  • Pagination ( 1 )
  • Palindrome Number ( 1 )
  • Pass By Reference Example ( 1 )
  • Pass By Value Example ( 1 )
  • PDF File Example ( 3 )
  • PDF Generation Example ( 4 )
  • Pre and Post Operator ( 2 )
  • Prime Number ( 3 )
  • Progress Bar Example ( 1 )
  • Property List Example ( 2 )
  • Random Function ( 7 )
  • Recursion Example ( 2 )
  • Regex Example ( 2 )
  • Remote Host Example ( 2 )
  • Robot Class ( 4 )
  • Searching Example ( 3 )
  • Slideshow ( 1 )
  • Sorting Example ( 7 )
  • SpringLayout Example ( 1 )
  • Stack Example ( 4 )
  • Static Variable ( 1 )
  • StreamTokenizer Example ( 2 )
  • String Example ( 19 )
  • Struts2 Example ( 1 )
  • Sum of Digits ( 1 )
  • Swap Two Numbers ( 1 )
  • Switch Case ( 3 )
  • Tapestry Components ( 1 )
  • Thumbnail Example ( 2 )
  • TimerTask Example ( 2 )
  • To Calculate Volume ( 1 )
  • To Check Armstrong Number ( 1 )
  • Tree Example ( 1 )
  • TreeMap Example ( 1 )
  • TreeSet Example ( 1 )
  • Two Dimensional Array Example ( 1 )
  • UUID ( 1 )
  • Validation Example ( 2 )
  • Variable Casting ( 1 )
  • While Loop ( 1 )
  • XML Parsing ( 7 )
  • XSS Attacks ( 1 )
  • Zip File ( 15 )

Popular Posts

  • Java program to create a Binary Heap and Perform various operation
    A binary heap (min-heap) is a complete binary tree with elements from a partially ordered set, such that the element at every node is less ...
  • Creating Dynamic Macro Enabled Excel by Java
    We can create a dynamic macro enabled excel by java: We need to create a excel sheet template with macro on server. we can copy the...
  • Implementation of a basic generic tree, with labels of type T - Data Structure
    // This implements a basic generic tree, with labels of type T, // pointer to the parent node, and a singly linked list of children nodes...
  • To Sort an Interger Array using Shell Sort
    To Sort an Interger Array using Shell Sort class ShellSort { public static int[] shellSort(int[] array) { int N = array.length; ...
  • Create an Adjacency matrix Graph and perform Add and Remove operation
    import java.util.ArrayList; import java.util.ArrayList; import java.util.LinkedList; import java.util.List; import java.util.Queue; import...
  • Sort an Integer array with Bucket Sort
    Here is a java program to Sort an Integer array with Bucket Sort class BucketSort { public int[] bucketSort(int[] array) { /...
  • Merge-Sort Algorithm implementation in JAVA
    Merge-Sort Function void MergeSort(int low, int high) // a[low : high] is a global array to be sorted. // Small(P) is true if there...
  • Stack implemented as array - Data Structure
    // Stack implemented as array public class ArrayStack<T> { private T[] stack; private int numElements = 0; // points to s...
  • Printing Table In java using While Loop
    Here is a Java Program to Print the Table public class Table { public static void main(String[] args) { int no = Integer.p...
  • Java Class to Calculate the Volume of Box
    Here is a Java Class to Calculate the Volume of Box. class Box { double width; double height; double depth; // This is the con...
 
 
© 2011 Java Programs and Examples with Output | Designs by Web2feel & Fab Themes

Bloggerized by DheTemplate.com - Main Blogger