HTML and CSS Reference
In-Depth Information
Listing 6-5. Example Output Markup of the RandomTextRenderer
<div id="unique-identifier-of-the-component">
... Random text generated by the component ...
Now that we know how the markup should look like we can implement the renderer. Listing 6-6 shows the
implementation of the RandomTextRenderer .
Listing 6-6. Implementation of
package com.apress.projsf2html5.chapter6.components;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
import javax.faces.render.FacesRenderer;
import javax.faces.render.Renderer;
@FacesRenderer(componentFamily = RandomTextComponent.COMPONENT_FAMILY, rendererType =
public class RandomTextRenderer extends Renderer {
/** Renderer type of {@link RandomTextRenderer}. */
public static final String RENDERER_TYPE = "com.apress.projsf2html5.components
private static final Logger LOG = Logger.getLogger(RandomTextRenderer.class.getName());
public void encodeEnd(FacesContext context, UIComponent uicomponent) throws IOException {
ResponseWriter writer = context.getResponseWriter();
RandomTextComponent component = (RandomTextComponent) uicomponent;
try {
writer.startElement("div", component);
writer.writeAttribute("id", component.getClientId(), "id");
try {
} catch (IOException randomTextException) {
LOG.log(Level.SEVERE, "Could not generate random text", randomTextException);
} catch (IOException ex) {
LOG.log(Level.SEVERE, "Could not generate markup", ex);
Search WWH ::

Custom Search