Coder Social home page Coder Social logo

jsf-google-url-shortener's Introduction

Preface

This project demonstrates how to create a custom JSF composite component using a faces component and renderer. It relies on the google url shortner api.

Installation / Requirements

This project has been tested with JSF 2.X

Begin by including the following 3 files in your project:

  • UrlShortenerAPI.java - Creates a oAuth request to the google api to shorten the provided URL
  • UrlShortenerComponent.java - Creates a standard faces component and implements the url attribute for passing the url to be shortened
  • UrlShortenerRenderer.java - Generates a link based on the url passed into the custom component to be rendered to the screen

In the web.xml register a new taglib

<context-param>
   <param-name>javax.faces.FACELETS_LIBRARIES</param-name>
   <param-value>/WEB-INF/googleurlshortener.taglib.xml</param-value>
</context-param>

Now in the new taglib you need to register the UrlShortener and attribute that will be passed to it. Create the new file in /webapp/WEB-INF/googleurlshortener.taglib.xml

<?xml version="1.0" encoding="UTF-8"?>
<facelet-taglib
    xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facelettaglibrary_2_0.xsd"
    version="2.0">
    <namespace>http://com.sixthpoint.google/urlshortener</namespace>
    <tlib-version>1.0</tlib-version>
    <jsp-version>2.2</jsp-version>
    <short-name>googleurlshortener</short-name>
    <uri>http://www.sixthpoint.com/</uri>
    <tag>
        <tag-name>urlshortener</tag-name>
        <component>
            <component-type>UrlShortener</component-type>
            <renderer-type>com.sixthpoint.jsf.google.url.shortener.components.UrlShortenerRenderer</renderer-type>
        </component>
        <attribute>
            <name>url</name>
            <type>java.lang.String</type>
            <description>The url that is to be shortened.</description>
        </attribute>
    </tag>
</facelet-taglib>

In each xhtml page you want to use this new component, place the following the namespaces

xmlns:six="http://com.sixthpoint.google/urlshortener"

Now you can use the new component as many times as you want on the page. This is a simple example:

<six:urlshortener id="googleURL" rendered="#{example.url.length() gt 0}" url="#{example.url}" />

A more in depth article can be read here: http://blog.sixthpoint.com/creating-a-simple-jsf-component-google-url-shortener/

jsf-google-url-shortener's People

Contributors

sixthpoint avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.