C# Class Castle.MonoRail.Framework.ViewComponent

Base class for reusable UI Components.
Implementors should override ViewComponent.Initialize for implement proper initialization (if necessary). Also implement ViewComponent.Render as by default it will render a default view on [ViewFolderRoot]/components/[componentname].

You can also override ViewComponent.SupportsSection if your component supports neste sections (ie templates provided on the view that uses the view component.

Another way is to use the ViewComponentDetailsAttribute to specify a custom name and the sections supported.

Notice that view components can render strings or views on their folder. You can create sophisticate components with that mixture. Sections allow the users of your component to give it a block of content, usually customizing or definiting the content to be especially rendered by your component.

A very simplist view component that renders the time. public class ShowTime : ViewComponent { public override void Initialize() { } public override void Render() { RenderText("Time: " + DateTime.Now.ToString()); } }

This can be used from the view using the following syntax (NVelocity view engine)

#component(ShowTime)
Show file Open project: nats/castle-1.0.3-mono Class Usage Examples

Public Methods

Method Description
Init ( IRailsEngineContext engineContext, IViewComponentContext componentContext ) : void

Invoked by the framework.

Initialize ( ) : void

Called by the framework once the component instance is initialized

Render ( ) : void

Called by the framework so the component can render its content

SupportsSection ( string name ) : bool

Implementor should return true only if the name is a known section the view component supports.

Protected Methods

Method Description
CancelView ( ) : void

Cancels the view processing.

HasSection ( String sectionName ) : bool

Determines whether the current component declaration on the view has the specified section.

RenderBody ( ) : void

Renders the component body.

RenderBody ( TextWriter writer ) : void

Renders the body into the specified TextWriter

RenderSection ( String sectionName ) : void

Renders the the specified section

RenderSection ( String sectionName, TextWriter writer ) : void

Renders the the specified section

RenderSharedView ( String name ) : void

Specifies the shared view to be processed after the component has finished its processing. (A partial view shared by others views and usually in the root folder of the view directory).

RenderText ( String content ) : void

Renders the specified content back to the browser

RenderView ( String name ) : void

Specifies the view to be processed after the component has finished its processing.

RenderView ( String component, String name ) : void

Specifies the view to be processed after the component has finished its processing.

Private Methods

Method Description
BindComponentParameters ( ) : void

Binds the component parameters.

BindParameter ( ViewComponentParamAttribute paramAtt, PropertyInfo property, IConverter converter ) : void
GetBaseViewPath ( ) : String
GetBaseViewPath ( String componentName ) : String

Method Details

CancelView() protected method

Cancels the view processing.
protected CancelView ( ) : void
return void

HasSection() protected method

Determines whether the current component declaration on the view has the specified section.
protected HasSection ( String sectionName ) : bool
sectionName String Name of the section.
return bool

Init() public method

Invoked by the framework.
public Init ( IRailsEngineContext engineContext, IViewComponentContext componentContext ) : void
engineContext IRailsEngineContext Request context
componentContext IViewComponentContext ViewComponent context
return void

Initialize() public method

Called by the framework once the component instance is initialized
public Initialize ( ) : void
return void

Render() public method

Called by the framework so the component can render its content
public Render ( ) : void
return void

RenderBody() protected method

Renders the component body.
protected RenderBody ( ) : void
return void

RenderBody() protected method

Renders the body into the specified TextWriter
protected RenderBody ( TextWriter writer ) : void
writer System.IO.TextWriter The writer.
return void

RenderSection() protected method

Renders the the specified section
protected RenderSection ( String sectionName ) : void
sectionName String Name of the section.
return void

RenderSection() protected method

Renders the the specified section
protected RenderSection ( String sectionName, TextWriter writer ) : void
sectionName String Name of the section.
writer System.IO.TextWriter The writer.
return void

RenderSharedView() protected method

Specifies the shared view to be processed after the component has finished its processing. (A partial view shared by others views and usually in the root folder of the view directory).
protected RenderSharedView ( String name ) : void
name String
return void

RenderText() protected method

Renders the specified content back to the browser
protected RenderText ( String content ) : void
content String The content to render.
return void

RenderView() protected method

Specifies the view to be processed after the component has finished its processing.
protected RenderView ( String name ) : void
name String
return void

RenderView() protected method

Specifies the view to be processed after the component has finished its processing.
protected RenderView ( String component, String name ) : void
component String
name String
return void

SupportsSection() public method

Implementor should return true only if the name is a known section the view component supports.
public SupportsSection ( string name ) : bool
name string section being added
return bool