EchoPoint
1.0

echopoint.ui.layout
Class JspTemplateLayoutManagerUI

java.lang.Object
  extended byechopoint.ui.layout.LayoutManagerPeer
      extended byechopoint.ui.layout.JspTemplateLayoutManagerUI
All Implemented Interfaces:
ComponentMapper, ComponentPeerMapper, JspRenderingContext, nextapp.echoservlet.html.Renderable, java.io.Serializable

public class JspTemplateLayoutManagerUI
extends LayoutManagerPeer
implements JspRenderingContext, nextapp.echoservlet.html.Renderable

JspTemplateLayoutManagerUI is the backend layout peer class for the component JspTemplateLayoutManager. This class uses the following rendering strategy because of characteritics of the Echo rendering scheme and also the Servlet output mechanism. * When the standard Echo render(rc,parentElement) method is called, the JSP is included using a NoOp servlet response. This is done because at this stage output is not meant to be sent to the actual servlet stream but rather an Element hierarchy is to be built. * Any required ComponentStyle values and Service includes must be generated at the Element render time and cannot be displayed until actual output render time. * If during a this Element render, StyleSheet information is applied, then the render is repeated to ensure that the updated style information makes its way into the HtmlDocument. * The UI peer implements Renderable and adds itself as the content in the Element hierarchy. This allows it to be called back later when the actual servlet output stream is being written to. This callback is the render(PrintWriter) method. * Later in the Renderable render method, the JSP content is written to the actual serlvet output stream including any included components. * A one time flag is used to control whether component properties have been previously been set. This is needed because a JSP render will occcur each time the template is displayed, however you only want the properties to be applied only once.

See Also:
Serialized Form

Field Summary
 
Fields inherited from interface echopoint.ui.jsp.JspRenderingContext
JSPRENDERINGCONTEXT
 
Fields inherited from interface nextapp.echoservlet.html.Renderable
INDENT_STRING
 
Constructor Summary
JspTemplateLayoutManagerUI()
           
 
Method Summary
 CompilationContext getCompilationContext()
          Returns the CompilationContext needed to render Echo output.
 nextapp.echo.Component getComponent(java.lang.String name)
          Returns a Component based on the name given.
 nextapp.echoservlet.ComponentPeer getComponentPeer(nextapp.echo.Component component)
          Returns a ComponentPeer based on the Component given.
 nextapp.echoservlet.html.Element getOutputElement()
          Returns the top level output Element in play
 nextapp.echoservlet.RenderingContext getRenderingContext()
          Returns the RenderingContext needed to render Echo output.
 boolean getStylesApplied()
          Returns true of Styles have been applied during execution the JSP render.
 boolean isFinalOutputOccurring()
          Returns true if final output to the underlying JSP stream is occurring.
 void render(java.io.PrintWriter pw, int depth, boolean parentWhitespaceRelevant)
          Renders the renderable object to the given PrintWriter.
 void render(nextapp.echoservlet.RenderingContext rc, nextapp.echoservlet.html.Element parent, nextapp.echoservlet.ComponentPeer parentPeer, nextapp.echoservlet.ComponentPeer[] children)
          We render the Component as a Renderable which defers the rendering until the actual Servlet output stream is being written to!
 void setCompilationContext(CompilationContext context)
          Sets the compilation context in play
 void setComponentPeers(nextapp.echoservlet.ComponentPeer[] peers)
          Sets the list of child component peers
 void setFinalOutputOccurring(boolean b)
           
 void setOutputElement(nextapp.echoservlet.html.Element element)
          Sets the output element in play
 void setRenderingContext(nextapp.echoservlet.RenderingContext rc)
          Sets the RenderingContext to be used to render Echo output.
 void setStylesApplied(boolean stylesApplied)
          Sets whether styles have been applied during a JSP render
 
Methods inherited from class echopoint.ui.layout.LayoutManagerPeer
getLayoutManager, registered, setLayoutManager
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JspTemplateLayoutManagerUI

public JspTemplateLayoutManagerUI()
Method Detail

render

public void render(nextapp.echoservlet.RenderingContext rc,
                   nextapp.echoservlet.html.Element parent,
                   nextapp.echoservlet.ComponentPeer parentPeer,
                   nextapp.echoservlet.ComponentPeer[] children)
We render the Component as a Renderable which defers the rendering until the actual Servlet output stream is being written to! If we dont do this then it can bomb on some application servers. The JSP spec implies that you can only ask for and write to the output stream once and app servers such as tomcat enforce this.

We also have to perform the rendering during the standard render(rc,parent) call otherwise ComponentStyle information is not added to the HtmlDocument nor are any required Service URIs.

This is because the Renderable render methods is called AFTER the HEAD section of the document has already been written and hence we cant add any more during our actual render.

This does introduce some problems. If a child component peer writes to the body or head tag during its render() method then it will end up with 2 lots of Element objects in the tag. This can cause problems with a ConcurrentModificationException because at actual Echo servlet stream output time, the Echo code is iterating the body or head tag at the same time that the 2nd pass is adding content to it.

But with Echo 1.0.4, the RenderingContext contructor has been opened up and we can crate a "fake" context to fool the output into going to the bit bucket.

Specified by:
render in class LayoutManagerPeer
See Also:
for more information on rendering

render

public void render(java.io.PrintWriter pw,
                   int depth,
                   boolean parentWhitespaceRelevant)
Renders the renderable object to the given PrintWriter. This uses the Renderable interface to render the layout manager, rather than the standard Element method.

This allows the JSP to be "included inline" during the actual output to the browser client. It can then "write" the JspWriter output inline as it is executed.

Specified by:
render in interface nextapp.echoservlet.html.Renderable
Parameters:
pw - The PrintWriter to render to.
depth - The indentation depth that should be applied to the element being rendered.
parentWhitespaceRelevant - A flag that indicates whether the containing element is sensitive to white space.

getComponent

public nextapp.echo.Component getComponent(java.lang.String name)
Description copied from interface: ComponentMapper
Returns a Component based on the name given.

Specified by:
getComponent in interface ComponentMapper
See Also:
ComponentMapper.getComponent(java.lang.String)

getComponentPeer

public nextapp.echoservlet.ComponentPeer getComponentPeer(nextapp.echo.Component component)
Description copied from interface: ComponentPeerMapper
Returns a ComponentPeer based on the Component given. This may return null if the peer is not available, say if the Component is currently invisible.

Specified by:
getComponentPeer in interface ComponentPeerMapper
See Also:
ComponentPeerMapper.getComponentPeer(nextapp.echo.Component)

getOutputElement

public nextapp.echoservlet.html.Element getOutputElement()
Returns the top level output Element in play


getRenderingContext

public nextapp.echoservlet.RenderingContext getRenderingContext()
Description copied from interface: JspRenderingContext
Returns the RenderingContext needed to render Echo output.

Specified by:
getRenderingContext in interface JspRenderingContext
See Also:
JspRenderingContext.getRenderingContext()

getCompilationContext

public CompilationContext getCompilationContext()
Description copied from interface: JspRenderingContext
Returns the CompilationContext needed to render Echo output.

Specified by:
getCompilationContext in interface JspRenderingContext
See Also:
JspRenderingContext.getCompilationContext()

setRenderingContext

public void setRenderingContext(nextapp.echoservlet.RenderingContext rc)
Sets the RenderingContext to be used to render Echo output.

Parameters:
rc - the RenderingContext

setCompilationContext

public void setCompilationContext(CompilationContext context)
Sets the compilation context in play

Parameters:
context -

setComponentPeers

public void setComponentPeers(nextapp.echoservlet.ComponentPeer[] peers)
Sets the list of child component peers

Parameters:
peers -

setOutputElement

public void setOutputElement(nextapp.echoservlet.html.Element element)
Sets the output element in play

Parameters:
element -

isFinalOutputOccurring

public boolean isFinalOutputOccurring()
Description copied from interface: JspRenderingContext
Returns true if final output to the underlying JSP stream is occurring.

Specified by:
isFinalOutputOccurring in interface JspRenderingContext
See Also:
JspRenderingContext.isFinalOutputOccurring()

setFinalOutputOccurring

public void setFinalOutputOccurring(boolean b)

getStylesApplied

public boolean getStylesApplied()
Description copied from interface: JspRenderingContext
Returns true of Styles have been applied during execution the JSP render.

Specified by:
getStylesApplied in interface JspRenderingContext
See Also:
JspRenderingContext.getStylesApplied()

setStylesApplied

public void setStylesApplied(boolean stylesApplied)
Description copied from interface: JspRenderingContext
Sets whether styles have been applied during a JSP render

Specified by:
setStylesApplied in interface JspRenderingContext
Parameters:
stylesApplied - true if they have been applied
See Also:
JspRenderingContext.setStylesApplied(boolean)

EchoPoint
1.0