|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjavax.faces.render.Renderer
tutorial.jsf.component.ajaxtree.AjaxTreeRenderer
public class AjaxTreeRenderer
Created: Nov 3, 2007
Title: AjaxComponentRenderer
Description:
Copyright: Copyright (c) 2008
Renderer for AjaxTree.
Two custom html attributes are used to send information. Each treeNode has a div that contains all its data and this div includes a nodeString="" and leaf="TRUE|FALSE" attributes. This could be done with hidden fields to stay within strict W3C. May add a flag on the tag allowing user to decide between the two: performance or compliance.
Originally, XML was used as the transport for the nodes, but now JSON is used to reduce size. The escapeJSON() method is taken from http://www.JSON.org/java/json_simple.zip.
Field Summary | |
---|---|
static java.lang.String |
DEFAULT_FACET
The default facet name that will be used if no facet is found for a node |
protected static java.lang.String |
HTML_CHILD_WRAPPER_CLASS
|
protected static java.lang.String |
HTML_CLICK_AREA_CLASS
|
protected static java.lang.String |
HTML_NODE_CLOSED
|
protected static java.lang.String |
HTML_NODE_OPENED
|
protected static java.lang.String |
HTML_NODE_STRING_NAME
|
protected static java.lang.String |
HTML_ROOT_CLOSED
|
protected static java.lang.String |
HTML_ROOT_LEAF
|
protected static java.lang.String |
HTML_SERVER_URL_CLASS
|
protected static java.lang.String |
HTML_TREE_NODE_CLASS
|
protected static java.lang.String |
HTML_USER_DATA_CLASS
|
Constructor Summary | |
---|---|
AjaxTreeRenderer()
default empty constructor |
Method Summary | |
---|---|
void |
encodeBegin(javax.faces.context.FacesContext context,
javax.faces.component.UIComponent component)
Writes out the root nodes and required resources. |
static java.lang.String |
escapeJSON(java.lang.String s)
This method is taken from http://www.JSON.org/java/json_simple.zip, by Fang Yidong. |
protected javax.faces.component.UIComponent |
findFacet(AjaxTree tree,
AjaxTreeNode node)
Gets the facet for a given node. |
protected java.lang.String |
getErrorString(java.lang.String msg)
|
protected java.lang.String |
getFacetOutput(javax.faces.context.FacesContext context,
AjaxTree tree,
AjaxTreeNode node)
Takes a tree and a node and uses the facet configured for that node type to generate an HTML string. |
boolean |
getRendersChildren()
AjaxTree does render children |
void |
handleAjaxRequest(javax.faces.context.FacesContext context,
javax.faces.component.UIComponent component)
Handles the request from the button, which was setup above in the encodeBegin() method. |
protected void |
renderRootNode(AjaxTree tree,
javax.faces.context.FacesContext context,
AjaxTreeNode node,
int rootNumber)
Renders a root node. |
Methods inherited from class javax.faces.render.Renderer |
---|
convertClientId, decode, encodeChildren, encodeEnd, getConvertedValue |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String DEFAULT_FACET
protected static final java.lang.String HTML_TREE_NODE_CLASS
protected static final java.lang.String HTML_CHILD_WRAPPER_CLASS
protected static final java.lang.String HTML_CLICK_AREA_CLASS
protected static final java.lang.String HTML_USER_DATA_CLASS
protected static final java.lang.String HTML_NODE_STRING_NAME
protected static final java.lang.String HTML_NODE_OPENED
protected static final java.lang.String HTML_NODE_CLOSED
protected static final java.lang.String HTML_ROOT_LEAF
protected static final java.lang.String HTML_ROOT_CLOSED
protected static final java.lang.String HTML_SERVER_URL_CLASS
Constructor Detail |
---|
public AjaxTreeRenderer()
Method Detail |
---|
public boolean getRendersChildren()
getRendersChildren
in class javax.faces.render.Renderer
public void encodeBegin(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component) throws java.io.IOException
encodeBegin
in class javax.faces.render.Renderer
java.io.IOException
protected void renderRootNode(AjaxTree tree, javax.faces.context.FacesContext context, AjaxTreeNode node, int rootNumber) throws java.io.IOException
.--NodeWrapper Div----------.
| .-------------------. |
| | LabelWrapper Div | |
| '-------------------' |
| .-------------------. |
| | ChildWrapper Div | |
| |
component
- out
- node
- rootNumber
- - A unique number for this root
java.io.IOException
protected java.lang.String getFacetOutput(javax.faces.context.FacesContext context, AjaxTree tree, AjaxTreeNode node)
context
- tree
- node
-
public void handleAjaxRequest(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component)
This is the XML format for the response. Its compact to go over the wire.
Note that the leaf element is a boolean value determining if the node will be rendered as expandable. TODO: Use the simple JSON api to encode the json
handleAjaxRequest
in interface AjaxComponentRenderer
protected javax.faces.component.UIComponent findFacet(AjaxTree tree, AjaxTreeNode node)
The precedence is this (falling to the next if no facet is found): 1) Get the facet based on node.getType-node.getLabel 2) Get the facet based on node.getType 3) Get the HtmlTreeRenderer.DEFAULT_FACET facet 4) Throw an NPE
Thanks to Larry Wood for the default facet idea.
tree
- node
-
protected java.lang.String getErrorString(java.lang.String msg)
public static java.lang.String escapeJSON(java.lang.String s)
If more JSON is used in Tomahawk, we could incorporate the jsonSimple api in.
" => \" , \ => \\
s
-
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |