HTML and CSS Reference
In-Depth Information
On the component we will also have to implement getters and setters for the attributes that we want to expose
and collect from the page author. The attributes with description and default values can be found in Table 6-1 .
Table 6-1. Attributes for the Random Text Component
Attribute
Description
Default
textType
Type of random text to generate
gibberish
outputTag
Type of HTML to generate. Either p for paragraphs or ul for unordered list.
P
count
Number of paragraphs or items to return
10
minWords
Minimum number of words to return in each paragraph or item.
5
maxWords
Maximum number of words to return in each paragraph or item.
10
Lastly, we will need a method for obtaining the random text. The method will collect the attributes and invoke
the RandomTextAPI. A complete listing of the RandomTextComponent can be found in Listing 6-3.
Listing 6-3. RandomTextComponent.java—The UIComponent Implementation of Our Component
package com.apress.projsf2html5.chapter6.components;
import java.io.IOException;
import javax.faces.component.FacesComponent;
import javax.faces.component.UIComponentBase;
// "RandomText" is the Component Type
@FacesComponent(RandomTextComponent.COMPONENT_TYPE)
public class RandomTextComponent extends UIComponentBase {
/** Component family of {@link RandomTextComponent}. */
public static final String COMPONENT_FAMILY = "RandomText";
/** Component type of {@link RandomTextComponent}. */
public static final String COMPONENT_TYPE = "RandomText";
/** Attribute name constant for textType. */
private static final String ATTR_TEXT_TYPE = "textType";
/** Default value for the textType attribute. */
private static final String ATTR_TEXT_TYPE_DEFAULT = "lorem";
/** Attribute name constant for outputTag. */
private static final String ATTR_OUTPUT_TAG = "outputTag";
/** Default value for the outputTag attribute. */
private static final String ATTR_OUTPUT_TAG_DEFAULT = "p";
/** Attribute name constant for count. */
private static final String ATTR_COUNT = "count";
 
Search WWH ::




Custom Search