I was suspecting something like that.

While you are right, that the context by default should not be in the
template (because it is a different context), there are two things, to
consider

- not being able to use components is the worse smell. do components
always need a context (should they fail without one)? In the example I
passed the component makes no obvious use of the context, at least.

- often I want to use UrlHelper (and my derivations from it) in mail
views. I currently handle this by my patched BooViewEngine, that
passes this in at the beginning. I cannot access my patch right now,
but I guess if I can access UrlHelper in the view, there must be a
context somewhere, too.

- probably it would be the best, if I could simply pass a context to
the mail view, if I want to make use of it, and have it plain as a
default.

You told me at another occasion that I could pass the UrlHelper as a
parameter. In the IDictionary passed in RenderMessage()? If it was
RenderMessage(viewName, layoutName, new Dictionary{{"Url", new
UrlHelper(context)}}), there could be a RenderMessage(viewName,
layoutName, context, new Dictionary{{"Url", new UrlHelper(context)}})
as an overload and have full functionality if needed.

Don't know if this would be doable, though.

Jan

On Thu, Sep 25, 2008 at 7:33 AM, Ayende Rahien <[EMAIL PROTECTED]> wrote:
> 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
>>
>>
>
>
> >
>



-- 
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