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

  • black ass sluts
  • Just teen tits
  • sex black love songs
  • disney anal pics asian girl pussy amateur thumbs
  • teen schoolgirl ass
  • japanese sex maga
  • nubiles pussy tube
  • pictures of men sucking womens tits
  • naked vaions pictures
  • adult movie free asian thumbs
  • lina nudes wife swingers
  • alexis sex vids
  • nude wife masterbation vids
  • video feeling girl up
  • interracial movie thumbs
  • big black dicks lil white chicks 7921940317
  • big sex ass video
  • 7177818226 Amazing hot girls
  • dy fingering my pussy
  • succulent juicy pussy horny irish girls video
  • young teens tiny titys
  • fat teen lesbian
  • Naked lady ecstasy
  • oral sex free stories
  • free daily asian sex video
  • women sex young men
  • young fucking teen vids Thai pretty girls moroe girls sexy
  • fart girl orgasm
  • wife sex pics torrent
  • japanese young teens pics
  • ex wife sex tubes young daughter fuck
  • breath taking asian girls
  • 4518653
  • youngest teen girl jap
  • latina mature pussy chicks with big dicks fucking girls
  • teen thong closeup
  • lesbian anal blonde free erotic sexy stories in bengali tight black teen ass
  • indian hairy naked girls
  • Milf with huge tits
  • teenie free fuck
  • free pregnent fuck videoes milf group sex pics
  • Real life vagina
  • free streaming movies xvid
  • extrait de video amateur
  • fat ass black women long platinum blonde hairstyle gallery
  • keisha knight pulliam black men pictures
  • very teen girl
  • gagged teen fuck
  • girls drugged and fuck Blonde lesbians have sex
  • Elisha cuthbert sex scene
  • Interracial cock sucking
  • young shaved japan pussy photo
  • black lesbians dee and jenn
  • wife sex stories jolene
  • video alogs
  • mean girls picture kevin
  • Kajol big boobs
  • ebony pussy close ups
  • sweet girls fuck
  • forced to suck dick bi 6742148052 picturesof naked boys
  • Ftv naked model
  • fuck drunk girl movies
  • with black girls 8509023055
  • girls fuck s free trailer
  • beautiful young french girl invites watch
  • asian sex star chubby young little girls naked
  • full length erotic movie download
  • glamour girl escort
  • girl riding dick
  • sexy facial jessica
  • search youngster boy naked
  • books for teen girl
  • Naked indian ass
  • interracial xxx rated videos
  • Nice girl pussy
  • blonde star lesbian
  • pantyhose sex lesbians brown skirt
  • athletes pics
  • gravee videos Hot girl in leather
  • real drunk party fuck video bbw
  • exotic beatiful ebony girls
  • lesbian pink babes
  • Latin lesbians sex
  • teen green sweater fuck
  • teen filled with jizz video closeup sex free
  • japanese milky nipples
  • amateur vacation wife bikini free emo teen pics mature tease galleries
  • tiny virgin pussy pics
  • fat blonde pussy
  • aussie chicks galleries links free
  • ebony babes xxx lesbian sex in oil black kind girls 7239376813
  • naked black girl with big asses
  • lyn asian star
  • batman hardcore anal
  • celebrity movie sex tapes
  • free young ethnic girl
  • Super sexy girls pictures
  • hotwife fuck husband
  • bleach girls tits
  • short people xxx
  • free spanking pussy stories
  • Hot girls taking shower
  • petite evening jackets
  • petite gourmande cooking classes
  • skull fuck fucking bondage 3650206325 Pictures of girls cumming telecharger video gratuite handjob
  • Kardashian sex video
  • nude deluxe wives asian
  • infinity hardcore video
  • south korean tits teen asian pussy
  • married women free sex videos
  • free amateur submitted pics and vids hardcore black trannies sexvilla everlust a girls
  • jesse jane blowjob video
  • girls pussy video Set sexy girls
  • screencap blonde breeding bench black
  • possible side effects of anal sex 4486236139
  • Indian university sexy girls
  • c tits shaved pussy manga babes image galleries
  • free drunk sex pics pics
  • teen sucking huge black dick
  • ladies hairy pussy
  • hardcore party com
  • outdoor xxx sex
  • Dominican big ass huge dick brutal fuck 6386427301 ex girlfriend sex naked oops gallery watch young girls govt charged halloween sexy girl
  • cartoon lesbian
  • pictures of star shauna grant
  • free movies hairy pussy teend
  • girls from girls next door naked
  • norwegian teen girl picture
  • cheating black girl tubes
  • college boys hardcore pics
  • petite teen defloration
  • hot jeans babes girls Teen preparation for acting free flash vids for mac
  • wives to cheat and fuck
  • pictures of black silky camel toe
  • nicole pussy dolls sex pics
  • movies free gangbang world record
  • brazillian teen girls
  • young girl old man by pool
  • wife fuck nigger dicks
  • nude wife and girlfriend pictures
  • naked neighbor movies
  • free xxx video teen
  • free hardcore busty movies
  • cherry potter cherry petite new galleries
  • spread ass cheeks galleries butt plug for my wife adult videos erotic
  • forced fuck my pussy
  • bristol palin ass pics
  • interacial teen girl young fuck tubes
  • Hot girls with hot tits
  • nude amateur babes hairy free pics
  • ali fedotowsky bikini pics
  • thai babes pics fotos
  • petite cumshot galleries
  • pics of trinny and susannah naked
  • tube teens fat chest young wife free video jennifer anistone sexy naked nude 2775628792 mature lesbians on redtube
  • photo galleries boys girls nude
  • sexy neighbor girls
  • private amateur video
  • Asian bikini nude
  • tommy chong wife pictures
  • cheerleader movie
  • cum earing shemale sex free
  • sex in the bathroom free videos
  • indian mistress maid fffm lesbian stories
  • Jeans ass videos
  • fluff girls closeup of pussy pictures
  • hermaprodites asian movies
  • girls sex s cams
  • darla crane ass to mouth vids Only sex xxx mature pussy hunt Hayden sex video
  • videos lesbians
  • link wo girls cup video
  • girl phat ass
  • young teen pussy movies galleries le petite turret mature video dump
  • young little girls gallery
  • asian flair curtain panals
  • big breasts sex girl masterbation movies sleeping teens galleries
  • sexe amateur powered by vbulletin
  • young teachers id like to fuck lorissa mccomas sex video men performing oral sex on themselves