Apache
  Home arrow Apache arrow Page 4 - Apache Tapestry and Custom Components:...
Dev Shed Forums 
Administration  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
APACHE

Apache Tapestry and Custom Components: DateInput
By: Alexander Kolesnikov
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 10
    2007-06-19

    Table of Contents:
  • Apache Tapestry and Custom Components: DateInput
  • Creating the DateInput Component
  • Creating the Models
  • Wiring everything
  • Implementing PageBeginRenderListener

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
     
    ADVERTISEMENT

    The Web Buyer's Guide is your best source for white papers on a wide range of IT products and services. This Week's Featured White Papers: Taming the Threat Landscape by Symantec

    Apache Tapestry and Custom Components: DateInput - Wiring everything
    (Page 4 of 5 )

    Finally, we need to create a component class. It will bring together all the constituents and make them work together toward the goal that we’ve defined:

    public abstract class DateInput extends BaseComponent implements

       PageBeginRenderListener {

       

        @Parameter(required = true)

        public abstract Date getDate();

        public abstract void setDate(Date d);

      

        private Calendar c = Calendar.getInstance();

       

        public void pageBeginRender(PageEvent event) {

            c.setTime(getDate() == null ? new Date() : getDate());

        }

       

        public IPropertySelectionModel getDaysModel() {

            return new DayModel();

        }

       

        public IPropertySelectionModel getMonthsModel() {

            return new LocalisedMonthsModel(getPage().getLocale());

        }

       

        public IPropertySelectionModel getYearsModel() {

            return new YearModel();

        }

       

        public int getDay() {

            return c.get(Calendar.DATE);

        }

       

        public void setDay(int day) {

            c.set(Calendar.DATE, day);

        }

       

        public int getMonth() {

            return c.get(Calendar.MONTH);

        }

       

        public void setMonth(int month) {

            c.set(Calendar.MONTH, month);

        }

       

        public int getYear() {

            return c.get(Calendar.YEAR);

        }

       

        public void setYear(int year) {

            c.set(Calendar.YEAR, year);

            setDate(c.getTime());

        }

    }

    Most of this code is very simple, but there are a few points that are worth commenting upon. There are three methods returning models to PropertySelection components, and one of them is slightly unusual:

    public IPropertySelectionModel getMonthsModel() {

       return new LocalisedMonthsModel(getPage().getLocale());

    }

    Here you can see how our component gets a reference to the page, onto which it will be placed (the getPage() method is available to every component), and then asks the page for the current Locale. The page’s answer is then passed to the LocalisedMonthsModel constructor, so that the names for the months were shown in an appropriate language.

    Perhaps the most interesting fragment of this code is how we define the parameter required by our custom component:

    @Parameter(required = true)

    public abstract Date getDate();

    public abstract void setDate(Date d);

    You should already be used to abstract getters and setters – our way of asking Tapestry to implement whatever is needed automatically. Here we also clarify that this will be a parameter named date, and this parameter is required. This means that if someone will want to use DateInput, they will need to provide a binding named date, and if they don’t, Tapestry will throw an exception.

    Using the abstract getter, we can obtain in our code the value provided by the page class through the required binding, and when the user submits the results of his or her input, we’ll use the abstract setter to report to the page on which the date was selected.

    More Apache Articles
    More By Alexander Kolesnikov


       · I know that the topic of creating custom components raises significant number of...
       · I think I tightly followed your code, but I still get an error when I try to...
       · Check if the 'date' binding of the DateInput is actually bound to something in the...
       · Hi :)I have built the component where one introduces the address. How I can pass...
       · I am not completely sure what you mean, but it sounds like you could have an Address...
       · I have the same problem. There is [i]public abstract Date getDateOfBirth();[/i]...
       · Sorry, I see the mistake. Not `name="value"` but `name="date"`.
       · Sorry for not answering in time - I am completing a book on Tapestry 5 and working...
       · Sorry for not continuing the tutorial for a while. A publisher contacted me and...
       · It's a pleasure to learn Tapestry with your great tutorial!I'm truely looking...
       · It seems that some people dont like to use the specifications page and like to make...
     

       

    APACHE ARTICLES

    - Putting Apache in Jail
    - Containing Intrusions in Apache
    - Server Limits for Apache Security
    - Setting Permissions in Apache
    - Installing Apache
    - Apache Installation and Configuration
    - Apache Tapestry and Custom Components: DateI...
    - Tapestry and AJAX: Autocompleter and InlineE...
    - PropertySelection and IPropertySelectionMode...
    - The DatePicker and Shell Components of Apach...
    - Apache Tapestry: ASO and More Components
    - Apache Tapestry and DirectLink, IoC and DI
    - Making a CelebrityCollector with Apache Tape...
    - Apache Tapestry and Listener Methods, Condit...
    - The Properties of Tapestry Pages




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway