Deprecated: Assigning the return value of new by reference is deprecated in /nfs/c01/h14/mnt/37629/domains/blog.evolutionarydawn.com/html/wp-includes/cache.php on line 36

Deprecated: Assigning the return value of new by reference is deprecated in /nfs/c01/h14/mnt/37629/domains/blog.evolutionarydawn.com/html/wp-includes/query.php on line 21

Deprecated: Assigning the return value of new by reference is deprecated in /nfs/c01/h14/mnt/37629/domains/blog.evolutionarydawn.com/html/wp-includes/theme.php on line 540
Evolutionary Dawn » Custom JSF Component 1.2

Evolutionary Dawn

June 11, 2009

Custom JSF Component 1.2

Filed under: Uncategorized — admin @ 12:25 pm

Since I had a hard time finding a complete solution anywhere online I decided that I would post a simple how-to for a JSF Custom component.

The problem that this component seeks to address is that the <f:verbatim> tag does not work properly in a <ui:repeat> tag.

This presented a issue to me because I have RAW HTML stored in my data model to be used in my simple blog application.

1. The most confusing thing about JSF Custom components.  YOU NEED 3 SEPERATE CLASSES TO IMPLEMENT A CUSTOM COMPONENT.

Alot of other tutorials will teach you there is a method in which you can use only two classes to accomplish the task, although this is true the most straight forward approach is to use 3 classes to implement your component.

The are as follows:

  1.  The component class (For this tutorial: HTMLVerbatimComponent) This class is technically where the “DATA” resisdes
  2. The tag class (For this tutorial: HTMLVerbatimTag) This class is the ADAPTER piece between the “JSF Page” and the DATA Model “Your component”
  3. The renderer class (For this tutorial: HTMLVerbatimRenderer) This class is response for the actual rendering of the HTML or OUTPUT.

The component class:

package com.mdb.web.jsf.component;
 
import javax.faces.component.UIComponentBase;
import javax.faces.context.FacesContext;
import javax.el.ValueExpression;
 
public class HTMLVerbatimComponent extends UIComponentBase {
 
    public HTMLVerbatimComponent() { }
 
    //Properties you want exposed as tag values must be exposed using getters/setters
    private String value;
    public String getValue() {
        if(value != null)
            return value;
        //If the value has not already been set interpret the Expression language and get resulting object
        Object value = this.getValueExpressionValue("value");
        return value != null ? (String)value : null;
    }
 
    public void setValue(String value) { this.value = value;}
 
    //Honestly I am not sure what this method does besides link the component to the config files
    public String getFamily() {
        return "com.mdb.web.jsf.component.HTMLVerbatim";
    }
 
    //Method allows component state to be stored
    @Override
    public Object saveState(FacesContext context) {
        return new Object[] { super.saveState(context), value};
    }
 
    //Method allows component state to be restored
    @Override
    public void restoreState(FacesContext context, Object object) {
        Object state[] = (Object[]) object;
        super.restoreState(context, state[0]);
        value = (String)state[1];
    }
 
    //Helper method to simplify getters/setters
    //This helps the JSF Component use Expression Language
    private Object getValueExpressionValue(String name) {
        ValueExpression ve = super.getValueExpression(name);
        return ve.getValue(FacesContext.getCurrentInstance().getELContext());
    }
}

The tag class:

package com.mdb.web.jsf.component;
 
import javax.faces.webapp.UIComponentELTag;
import javax.faces.component.UIComponent;
import javax.el.ValueExpression;
public class HTMLVerbatimTag extends UIComponentELTag {
    //Temporary holder property hence if I put
    //&lt;tag:htmlVerbatim value="#{SomeBackingBean.htmlText}"/&gt;
    //information is stored in this object until the data is pushed into the component in setProperties method
    private ValueExpression value = null;
    public HTMLVerbatimTag() {}
    public ValueExpression getValue() { return this.value;}
    public void setValue(ValueExpression value) { this.value = value;}
 
    //This is where the action happens
    //Data is taken from the tag on the JSF Page and placed into the Component
    @Override
    protected void setProperties(UIComponent component) {
        super.setProperties(component);
        HTMLVerbatimComponent verbatimComponent = (HTMLVerbatimComponent)component;
        if(value != null) {
            verbatimComponent.setValueExpression("value", value);
        }
    }
 
    //Method links this tag object to the component in config files
    public String getComponentType() { return "com.mdb.web.jsf.component.HTMLVerbatim"; }
 
    //Method links this tag object to the renderer in config files
    public String getRendererType() { return "com.mdb.web.jsf.component.HTMLVerbatim";}
 
}

The renderer class:

package com.mdb.web.jsf.component;import javax.faces.render.Renderer;
 
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
import java.io.IOException;
 
public class HTMLVerbatimRenderer extends Renderer {public HTMLVerbatimRenderer() {}
 
    //Render your HTML HERE
    @Override
    public void encodeBegin(FacesContext context, UIComponent component) throws IOException {
        HTMLVerbatimComponent verbatimComponent = (HTMLVerbatimComponent)component;
        ResponseWriter writer = context.getResponseWriter();
        writer.write(verbatimComponent.getValue());
        writer.flush();
    }
 
}

Now you must make some changes to your configuration files and I make the big assumption you are using Facelets.

Create a file in your WEB-INF directory called: custom.taglib.xml

Add the following content (Edit accordingly for your own component and domain):

 
  "-//Sun Microsystems, Inc.//DTD Facelet Taglib 1.0//EN"
  "http://java.sun.com/dtd/facelet-taglib_1_0.dtd"&gt;
 
<facelet-taglib>
    <namespace>http://mechdrives.com/web/jsf/component/tags</namespace>
    <tag>
        <tag-name>htmlVerbatim</tag-name>
        <component>
            <component-type>com.mdb.web.jsf.component.HTMLVerbatim</component-type>
            <renderer-type>com.mdb.web.jsf.component.HTMLVerbatim</renderer-type>
        </component>
    </tag>
</facelet-taglib>

Edit your faces-config.xml and add the following content(Edit accordingly for your own component and domain):

 
<faces-config version="1.2">
    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-facesconfig_1_2.xsd"&gt;
    <component>
        <component-type>com.mdb.web.jsf.component.HTMLVerbatim</component-type>
        <component-class>com.mdb.web.jsf.component.HTMLVerbatimComponent</component-class>
    </component>
    <render-kit>
        <renderer>
            <component-family>com.mdb.web.jsf.component.HTMLVerbatim</component-family>
            <renderer-type>com.mdb.web.jsf.component.HTMLVerbatim</renderer-type>
            <renderer-class>com.mdb.web.jsf.component.HTMLVerbatimRenderer</renderer-class>
        </renderer>
    </render-kit>
    <application>
        <locale-config>
            <default-locale>en</default-locale>
        </locale-config>
        <view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
        <el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
    </application>
</faces-config>

Edit your web.xml and add the following content:

    <context-param>
<param-name>facelets.LIBRARIES</param-name>
<param-value>/WEB-INF/custom.taglib.xml;</param-value>
    </context-param>

Now you should be able to use your new component/tag simply by adding a namespace to your JSF Page as such:

 

then using the tag as such:

<custom:htmlverbatim value="#{SomeBackingBean.htmlText}">
</custom:htmlverbatim>

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment

You must be logged in to post a comment.

Powered by WordPress

  • download ninja gaiden theme
  • adobe flash player 10.1 download zadarmo
  • download magic carpet ride steppenwolf mp3
  • download bots full game
  • download mp3 jashne aamade rasool
  • download pakistani contract act 1872
  • mtv riff raff time download
  • showdown britney spears download
  • lineage 2 level up download
  • vanbasco karaoke download ubuntu
  • konica minolta magicolor 4690mf download
  • download driver hp 550
  • download ub40 the best of
  • download suonerie iphone 4 originali
  • download musou orochi 2 pc
  • packed to the rafters download season 2
  • ten quick questions download for free
  • ragnarok online 2 download client
  • wifi hack crack download
  • gigabyte ga g31m s2l download driver
  • download judika full album 2011
  • adobe 9 download pc
  • canon pixma ip2600 download software
  • download mp3 gratis ariel tatum
  • download lagu barat nostalgia terpopuler
  • download mp3 the rain sepanjang jalan kenangan
  • diwali puja video download
  • download kane and undertaker theme song
  • jxplorer download for windows zip
  • brother printer drivers hl 2170w download
  • web download music mp3
  • download simcity deluxe for pc free
  • download episode 200 of south park
  • download sudden attack korean
  • how to download myxer on iphone
  • download spider man 2 online
  • adprep download 2003 r2
  • download pkgutil for solaris 10
  • gaona quien te dijo download
  • download celine dion when i fall in love
  • free download bangla pahari song
  • download fisier de 2011 pt fifa 08
  • m.fring.com download for samsung mobile
  • download ios 5 redmondpie
  • slower download than upload speed
  • download rada manojlovic crna ptica
  • download amr diab 2011 new album
  • download driver pixma mg 2100
  • download myriad pro light font free
  • blaxy girls rock yourself download fisierul meu
  • google tts download android
  • download mocca happy mp3
  • nfs undercover crack paul dll download
  • download igrice za samsung galaxy fit
  • uc browser 7.6 download java
  • mountains of makkah album download
  • micromax mmx 310g driver download
  • download feliz aniversA?rio para mim
  • survival world download minecraft
  • download lemmings 2 the tribes game
  • hakim bey mehmet erdem download
  • download mike oldfield voyager
  • pwnage tool 2.2 5 download
  • download sha la la kekkaishi
  • download lagu pusing setengah mati
  • eras demi bold free download
  • os cinco furiosos download
  • dqm joker 2 rom download
  • download ff9 iso disc 3
  • download redsnow 0.9 beta 4
  • download free eldorado puzzle game
  • download acrobat reader japanese
  • royal envoy 2 download vollversion
  • ir 3300 driver download xp
  • download nieuwste itunes gratis
  • nestopia download windows 7
  • made me glad hillsong download
  • download te duc barbati la detector
  • download michael buble xmas album
  • mariah carey 2009 download
  • download 50 tons de cinza
  • airport utility download 5.6
  • download ciara go girl
  • download of mirana wars
  • download l'incroyable histoire de winter le dauphin
  • siri could not download required
  • macroeconomia para concursos download
  • ishaqzaade movie free download single link
  • download mp3 nocturne secret garden
  • download lalala by auburn
  • pendulum blood sugar download ulub
  • download and i am telling you mp3
  • nba ballers phenom download pc
  • suspended by the throat download
  • download minilyrics plugin for windows media player
  • download lagu timang timang anakku sayang anang
  • download ie7 for windows 98
  • download midnight club 3 for pc free
  • download programmer's guide to java scjp certification
  • download filme o toque bv filmes
  • download yahoo mail emoticons
  • andien ungu saat bahagia download
  • download penetras bom de bico legendado
  • mafia wars autoplayer download for chrome
  • jelena rozga zanemari download free mp3
  • download ukf dubstep music
  • trey songz anticipation download free
  • download teeth the movie
  • download watchguard client vpn
  • download minus 1 damn feeling album
  • download hp procurve management software
  • download victorious the blonde squad
  • download hp fingerprint software
  • download gimp to mac
  • chino y nacho album download free
  • virtua tennis 6 download
  • download yu gi oh sacred cards
  • download remote host application
  • fxcop download visual studio 2005
  • programa para bloquear download
  • download it doesnt get better than this
  • dicionario online download gratis
  • internal modem driver download windows xp
  • download hana yori dango with english subtitles
  • download lagu ku harus bisa
  • download neighbours from hell pc
  • download hollywood wallpaper of actress
  • sometimes like you download mp3
  • dedication 4 green ranger download
  • boulevard of dreams download
  • download timon and pumba in tamil series
  • download squirrel sql 3.2.1 install jar
  • download insaniquarium revenge fish full version
  • smartstart dl360 g5 download
  • xiv gui 4 download
  • hungry heart opening download
  • knight online 1886 patch download
  • alicia keys troubles free download
  • download larga do meu pA
  • html color codes download free
  • twixtor 5 demo download
  • download anak jalanan sandhy sondoro
  • ala barfi video download
  • free download sye mp3 songs
  • download 30 for 30 episodes
  • 6.71 ai map download getdota
  • sagare tharam song download
  • free download g one movie in telugu
  • download livro mochileiros das galaxias
  • ho hey lumineers download mp3
  • download 5.00 m33 ctf themes
  • download album jang geun suk mp3
  • soleil bluetooth driver download free
  • no handlebars instrumental download
  • ipod touch download cydia free
  • java compiler download kostenlos
  • download teri kasam song
  • download rtw 1.3 patch
  • download remix of jannat 2 songs
  • download unified access gateway
  • yahoo messenger 1.0 ipa download
  • william shakespeare download books
  • download do cd roberio dos teclados
  • download dotnet framework ver 2.0
  • download burger shop 2 pc
  • download xiu xiu photo editor bahasa indonesia
  • download wale heaven in the afternoon mp3
  • download tomtom iberia iphone cracked
  • download wax i ain't a real man
  • free download ye betiyan babul ki
  • download ages of empire full version
  • download faded by red cafe
  • nes formats games download
  • download dbz budokai 2 highly compressed
  • download song hale dil unplugged
  • download unichrome pro igp
  • download gtr 2 demo
  • download redsn0w 0.9. 10b4
  • download dangdut full album
  • download curso gratis de ingles
  • download seether fake it
  • ost warcraft 2 download
  • free download background 3d powerpoint
  • download jack mannequin dark blue
  • download pet hotel game
  • download para combat arms
  • download memories remain anuar zain
  • download shopping center the sims 3
  • nokia e50 aplikacje download
  • download cd toca do vale 2012
  • roman reloaded 2.0 download
  • kelias i mokykla mp3 download
  • bout it instrumental download free
  • vishnu sahasranamam download subbulakshmi
  • bwin poker download for mac
  • download mp3 gratis nia lavenia
  • download songify on computer
  • minecraft arch city download
  • microsoft help html download
  • minecraft 1.2 5 cracked server download
  • peoplesoft application engine download
  • download asus p5kpl am lan driver
  • sony ericsson j108i download themes
  • wd tv live software download
  • download free dinosaur hunting games
  • download ios 5.1.1 sprint
  • bs player 0.8 free download
  • arco Aris do amor download
  • put a arch in yo back download
  • download nokia 5300 theme creator
  • sailor moon episode 45 download
  • nancy 7 download for free
  • free download iis dahlia payung hitam
  • download lagu avenged 4.00 am
  • download imma be by black eyed peas
  • chelsea grin font download
  • download ubersocial sherlock holmes theme
  • mh frontier english download
  • diA?rio roubado download legendado
  • download from above not the same
  • upload faster than download adsl
  • call of duty download exe
  • webgl download internet explorer
  • download piano lesson software
  • download fig tree by lara george
  • download forever knight season 1
  • gmc nav disc download
  • download game one piece colosseum mugen 2011
  • download underbelly razor episode 11
  • apne maa baap ka mp3 download
  • download de filmes sobre hackers
  • download ereader for tablet
  • download hawaii 5 0 1 temporada dublado
  • burger shop 3 download full version
  • megaman x5 ost download
  • download frankie cocozza catastrophic casanova for free
  • ozzy osbourne tribute 1987 download
  • download may ling love leads the way
  • download tekton pro ext negrito
  • download pokemon ruby jar
  • download sean paul get busy video
  • desert storm 2 download demo
  • vovA? zona 3 download 3gp
  • rahat new song download
  • j.cole the autograph download
  • download fm 2008 completo portugues atualizado
  • netflix download video quality
  • ghostscript download for mac os x
  • download company registration form in india
  • free download optitex 9.6 fashion design
  • hack warrock undetected 2011 download
  • il diavolo custode libro download
  • gulli sims 3 download
  • canon vixia hfm40 download to mac
  • milton nascimento download 2010
  • free download swat vs zombie
  • up & away download
  • 18 vayasu songs download free
  • download que sera wax tailor
  • udf software kostenlos download
  • e2652 java games download
  • download clone dvd 4.0
  • animal collective feels zip download
  • one tree hill 5x17 download ita
  • microsoft coding download page
  • download mp3 phantom begini begitu salah
  • zipgenius download gratis ita
  • mark sheet making software free download
  • download energy 2011 sets
  • download what makes you beautiful boyce avenue mp3
  • download livro coerAA?o e suas implicaAAes
  • manual fabio ulhoa download
  • download visual basic 210
  • download program de facut video din poze gratis
  • download undertaker big evil theme song
  • mozilla add ons download
  • hume tumse pyar kitna download
  • ipod download without itunes
  • download shinkenger ep 1
  • download videos from ncaa vault
  • download remix gotye somebody
  • eterno pra vocA? fiuk download
  • download dvd can you road hb
  • download damn small linux 2.1
  • download sports champions 2
  • download mahabharat serial in tamil
  • download songs of balam
  • xbox download cancel carry on
  • download alcatraz 2 temporada
  • download just want you to know
  • download apexdc for windows 8
  • psp iso download ffinsider
  • free download mp3 dangdut 90an
  • ankara oyun havalarA download
  • easeus partition master download
  • latest sakray download 2011
  • download pinch me mp3
  • download setup of google chrome
  • warrock download kostenlos deutsch chip
  • download opra mini 12
  • daruvu mp3 songs free download ziddu
  • download marathi old movies
  • marty robbins devil woman download
  • download blaupunkt car 2003 code generator
  • download eloise at the plaza movie
  • winpwn download for mac
  • download reo speedwagon in my dreams mp3
  • wifi connecting software download
  • download precious sans font
  • download gritos do alem avi
  • aprendendo a montar 2 download
  • leila forouhar eshghe to download
  • download hp scanjet g2410 for windows 7 driver
  • download fnatic counter strike 1.6
  • download plants vs zombies tieng viet
  • free download of russell peters videos
  • download parade light me up
  • download game empires and allies
  • fpga based implementation of signal processing systems download
  • wings of prey kaufen download
  • ludacris stand up download
  • ima go getta instrumental download
  • still life 2 download full version
  • download ande londe mp3
  • download east indian songs free
  • gohan wo okasu download mp3
  • dog whisperer download season 1
  • 90210 download melhor da telona
  • talisman online patch 1862 download
  • download adobe imageready 7.0
  • dowA?d rzeczowy numer 2 download
  • download rita de cassia 2012
  • download ban hack gb
  • jagjit singh download mp3
  • download rock anos 80 internacional
  • rct triple thrill pack download
  • download glasses malone glass house
  • boku no animal life download
  • gimme 20 dollars song download
  • spiral bonds of reasoning download
  • download bob marley two joints
  • download honey bunny ringtone zedge
  • twelve sky 2 download ph
  • download microsoft acpi compliant embedded controller driver
  • tagebuch download fA?r mac
  • bios 8440p hp download
  • messenger download fAr vista
  • download yoari excuse me
  • motorola original data kit download
  • nawigacja do noki 2710 download
  • free download of chocolatier game
  • download ellie goulding anything could happen
  • download naats of owais raza qadri free
  • nvidia download driver beta
  • set download default program
  • download inotia 3 apk 1.2.5
  • download songs of bommarillu telugu movie
  • tu o ploaie download fileshare
  • gerenciador de download que preste
  • download mp3 irwansyah saskia
  • download lame acm mp3
  • download greek traditional music
  • battlefield vietnam download windows 7
  • ghouls 'n ghosts download rom
  • download ippadi mazhai adithal mp3
  • download nicolae guta o lacrima curge
  • mp4 download online youtube
  • melvins the bride screamed download
  • download free lg gm360 apps
  • magnificent 7 theme download
  • grasu xxl perfect download
  • siavash ghomeishi khatereh download
  • download yui how crazy your love
  • chrome download video plugin
  • mencari internet download manager
  • multisim download free with crack
  • download sophos control centre
  • download mp3 triad sedang mikirin kamu
  • download foxit reader 6.0 free
  • download sub english anime
  • heroes 4 peb.pl download
  • oracle 10g tutorial download poulton
  • comag sl35 software update download
  • download sims 3 censor patch
  • could not download information xbmc
  • download free internal medicine books
  • download bangla remix songs
  • download mart'nalia ao vivo 2005
  • download fallout 3 patch 1.7
  • geforce 9600m gt download driver
  • ayyappa child song download
  • download sengoku basara psp iso
  • download scott pilgrim books for free
  • download ai la trieu phu iphone
  • jls download one shot
  • download free xps viewer and xps writer
  • download gzip for windows vista
  • vst plugin sytrus vsti download
  • download kolohe kai genuine love
  • o reino download dublado rmvb