Okay, this is most certainly a bug, but it is not a trivial one.
The underlying problem is that to render a view component, you have to use
the engine context, because you need access to the IViewComponentFactory.
This is not passed to the view engine during construction of the view for
the mail message.
In particular, we have this two overloads:

///<summary>
/// Processes the view - using the templateName
/// to obtain the correct template
/// and writes the results to the System.TextWriter.
/// </summary>
void Process(string templateName, TextWriter output, IEngineContext context,
IController controller, IControllerContext controllerContext);

/// <summary>
/// Processes the view - using the templateName
/// to obtain the correct template
/// and writes the results to the System.TextWriter.
/// </summary>
void Process(string templateName, string layoutName, TextWriter output,
IDictionary<string,object> parameters);

The first is used for normal views, the second for mail messages.
Since the second one doesn't have a context, the view can't figure out the
view component factory and fails.

Now, for the actual resolution. It would require the email template server
to know about the engine context, and I am not sure if this is something
that is desirable.
thoughts?


On Wed, Sep 24, 2008 at 6:20 AM, Jan Limpens <[EMAIL PROTECTED]> wrote:

> Hi Ayende,
>
> my test skills are quite mediocre, I did not find out how to create a
> unit test for this. (and could not inspire myself on the castle
> sourcecode from where I am now)
> However I did create a solution that does nothing else than reproduce
> the error in isolation. Maybe have a look at this :)
>
> --
> Jan
>
> On Tue, Sep 23, 2008 at 2:34 PM, Ayende Rahien <[EMAIL PROTECTED]> wrote:
> > Please create a test case that shows the issue.
> >
> > On Tue, Sep 23, 2008 at 6:25 PM, Jamie Fraser <[EMAIL PROTECTED]>
> > wrote:
> >>
> >> Is it possible to use a Component within a mail template? When I do so
> >> I get a NullRefException
> >>
> >> My mail/info.brail contains:
> >>
> >> <% component OrderConfirmation, [EMAIL PROTECTED]: order, @isWeb: isWeb} %>
> >>
> >> The error I get, when calling RenderMailMessage(view, layout,
> >> parameters); (with "Info", "Mail" and some parameters) is
> >>
> >> MonoRailException
> >>
> >> Message:
> >> Exception on process view: mail\Info
> >> Last accessed variable: isWeb
> >>
> >>
> >> StackTrace:
> >>   at Castle.MonoRail.Views.Brail.BooViewEngine.HandleException(String
> >> templateName, BrailBase view, Exception e) in
> >>
> >>
> c:\data\castle\castle\trunk\MonoRail\Castle.MonoRail.Views.Brail\BooViewEngine.cs:line
> >> 289
> >>   at Castle.MonoRail.Views.Brail.BooViewEngine.RenderView(String
> >> templateName, BrailBase view) in
> >>
> >>
> c:\data\castle\castle\trunk\MonoRail\Castle.MonoRail.Views.Brail\BooViewEngine.cs:line
> >> 165
> >>   at Castle.MonoRail.Views.Brail.BooViewEngine.Process(String
> >> templateName, TextWriter output, IEngineContext context, IController
> >> controller, IControllerContext controllerContext) in
> >>
> >>
> c:\data\castle\castle\trunk\MonoRail\Castle.MonoRail.Views.Brail\BooViewEngine.cs:line
> >> 146
> >>   at Castle.MonoRail.Views.Brail.BooViewEngine.Process(String
> >> templateName, String layoutName, TextWriter output, IDictionary`2
> >> parameters) in
> >>
> c:\data\castle\castle\trunk\MonoRail\Castle.MonoRail.Views.Brail\BooViewEngine.cs:line
> >> 197
> >>   at
> >>
> Castle.MonoRail.Framework.Services.DefaultViewEngineManager.Process(String
> >> templateName, String layoutName, TextWriter output, IDictionary`2
> >> parameters) in
> >>
> c:\data\castle\castle\trunk\MonoRail\Castle.MonoRail.Framework\Services\DefaultViewEngineManager.cs:line
> >> 179
> >>   at
> >> Castle.MonoRail.Framework.EmailTemplateService.RenderMailMessage(String
> >> templateName, String layoutName, IDictionary parameters) in
> >>
> >>
> c:\data\castle\castle\trunk\MonoRail\Castle.MonoRail.Framework\Services\EmailTemplateService.cs:line
> >> 140
> >>   at Castle.MonoRail.Framework.Controller.RenderMailMessage(String
> >> templateName, String layoutName, IDictionary parameters) in
> >>
> >>
> c:\data\castle\castle\trunk\MonoRail\Castle.MonoRail.Framework\Controller.cs:line
> >> 1415
> >>   at
> >>
> FestaExpress.Web.Site.MVC.Controllers.BaseController.RenderExtEmailMessage(String
> >> view, String layout, IDictionary parameters) in
> >>
> >>
> C:\CODE\fexdev\FestaExpress\branches\1.5\FestaExpress.Web.Site.MVC\Controllers\BaseController.cs:line
> >> 128
> >>   at
> FestaExpress.Web.Site.MVC.Controllers.DebugController.SendOrderMail()
> >> in
> >>
> C:\CODE\fexdev\FestaExpress\branches\1.5\FestaExpress.Web.Site.MVC\Controllers\DebugController.cs:line
> >> 30
> >>   at
> >>
> FestaExpress.Web.Site.MVC.Controllers.DebugController.ViewOrderInfo(Int32
> >> orderId) in
> >>
> C:\CODE\fexdev\FestaExpress\branches\1.5\FestaExpress.Web.Site.MVC\Controllers\DebugController.cs:line
> >> 72
> >>
> >>
> >>
> >> Inner exception:
> >>
> >> NullReferenceException
> >>
> >> Message:
> >> Object reference not set to an instance of an object.
> >>
> >>
> >> StackTrace:
> >>   at BrailView_Info.Run()
> >>   at Castle.MonoRail.Views.Brail.BooViewEngine.RenderView(String
> >> templateName, BrailBase view) in
> >>
> >>
> c:\data\castle\castle\trunk\MonoRail\Castle.MonoRail.Views.Brail\BooViewEngine.cs:line
> >> 161
> >>
> >>
> >>
> >> I have tried this even with a simple Component (one with no
> >> parameters) and get the same error.
> >>
> >> Any ideas?
> >>
> >> -Jamie
> >>
> >>
> >
> >
> > >
> >
>
>
>
> --
> Jan
> ___________________
> [EMAIL PROTECTED]
> www.limpens.com
> +55 (11) 3082-1087
> +55 (11) 3097-8339
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Castle Project Users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/castle-project-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to