Register | Log in | RSS channel for codegravity.com homepage Bookmark!

284/2NEW projects | 71 services | 215 websites | 834/3NEW freelancers | 2126 topics | advertise



Login:



Forgot your password?
Forgot your username?
Create an account
JoomlaWatch Agent

Users

Most active users today from total of 107:
garikello, Peerke, jakkrit, dayanand, andrew_saber, giakhanh, mohalb, carmachhh, fguyon, dfireablaze, boho, phoeker, ozedfr, amoluca, JDev, blackie, ashish_php, Pascale, tinytim007, kostas13


19.9%United States United States
17.9%India India
9.3%Germany Germany
5.5%Russian Federation Russian Federation
4.4%United Kingdom United Kingdom
4.3%France France
4%Australia Australia
3.8%Netherlands Netherlands
3.8%Poland Poland
3.7%Italy Italy

Today: 942
Yesterday: 1402
This Week: 5232
Last Week: 8869
This Month: 2344
Last Month: 37593
Total: 117024


Partners:

HTML5, CSS3, SVG, tutorials

Freelance ColdFusion, Flex, PHP

Olejomalby, abstraktne obrazy

Camping Europe

WinAsm Studio

Vyšné Ružbachy

Sochy, Reštaurovanie

R.E.M.

Valid XHTML 1.0 Transitional

RSS feed:

Statistics:
Search Engine Genie Promotion Widget
Home

Custom JSF component - Birthday

One of the powerful feature of JSF is to extend its tag library and create custom tags. Developers can use this feature and enhance the tags that are provided by JSF implementations (e.g. sun, myfaces, etc). Or they can straight away start writing the tags of their own. Today we’ll see how easy it is to create a custom tag in JSF. Let’s try out with an example, to create a tag, which will display today’s date and a list of people who has birthday today.

Step 1 – web.xml

 

Make an entry for the custom tags definition file.

We need to define 2 configurations,

URI that will be used when this tag is used inside a JSF page.

Location of the tags definition file.

Step 2 – custom-tags.tld

Create custom-tags.tld in the specified location and mention details about the custom tag.

Here we mention the name of the tag, the class which will provide additional information about this tag.

Step 3 – faces-config.xml

Next step is to modify the faces-config.xml file and make an entry for this tag.

Here we specify 2 configurations,

  • Component which will act as a model (data holder) for this tag.
  • Renderer which will create UI for this tag.

    Step 4 – Tag class

    Then we create a class file that was defined in custom-tags.tld file. This class MUST extend UIComponentTag. We need to implement 2 abstract methods to get the component and the renderer for this tag. Copy+paste these from the faces-config.xml file.

    Step 5 – Model class

    The model class will extend from UIComponentBase. We need to implement a method to return the family of this tag. Copy paste the family from faces-config.xml file.

    Step 6 – Renderer class

    The renderer class extends from Renderer to override encodeBegin and encodeEnd methods. The encodeBegin method should contain the HTML code which will get written when the tag is opened. Similarly the encodeEnd method should contain the HTML code which will get written when the tag is closed.

    Step 7 – JSF Page

    The last step is to write the JSF page. For this we need to include the custom tag library that we had written and give a prefix for its tags. Then use the custom tag in the page.

    Output

    HTML Source code

    Conclusion

    Similarly we can write more complex tags which defines a set of attributes which can be used in the HTML code, e.g. style, width, height, etc. We can also extend any predefined tag and override the functionality as per the requirement.

     

  • Source code

    Download the source code for this article.


    Author: gauravk
 

Comments  

 
0 #1 mate tee 2009-12-05 22:14
Now that we have presented a high level view of what JSF is, let's dive into the particulars of what a component is. In JSF, a component is a group of interacting classes that together provide a reusable piece of web-based user interface code. A component is made up of three classes that work closely together.
Quote
 

Add comment


Security code
Refresh

No Tweets

Add URL of a programming website
register as a freelancer
submit your project
open freelance projects you can work on
webmaster resources
write paid blog posts about programming - tips and articles
bugs and features

Recommended: (advertise)
Download Joomlawatch 1.2.12


HostMonster.com -
best cheap Joomla Web hosting. Website joomlawatchdemo.com is hosted by them with domain for $6,95/mo.

FastDomain.com -
Fast Domain hosting. Hostmonster alternative. Also for $6.95/month.


Advertise Here
-
Promote your services and get the new customers from the community of webmasters / programmers visiting CodeGravity.com

Register as a Freelancer -
Submit your project experiences, programming languages and your other skills


Outsource your project
-
Submit your project description with all the requirements to more than 600 freelancers from around the world for FREE.


Freelancers, create paid articles
-
Looking for freelancers with experiences in Java to write paid articles on their experiences

Green Geeks Hosting -
World's best selling green web hosting



News from Twitter:
No Tweets
RSS Feeds:new

rss Freelance
rss Projects
rss Forum
rss Resources

Popular:
MathGuard
download mathguard
Random screenshot:

linoopz15.jpg


Poll

At what price would you purchase JoomlaWatch ad-free license?
 
Privacy policy | Advertise | Donate | Doucovanie Nemcina
Joomla Visitors Google Map
Loading map...
Joomla Visitors Google Map
Visitors Google Map Agent

Locations of visitors to this page


©2003-2010 Codegravity.com