1 // Copyright 2004-2007 Castle Project - http://www.castleproject.org/
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle
.MonoRail
.ActiveRecordScaffold
18 using Castle
.Components
.Binder
;
19 using Castle
.MonoRail
.Framework
;
21 using Castle
.Components
.Common
.TemplateEngine
;
25 /// Renders an inclusion form
28 /// Searchs for a template named <c>new{name}</c>
30 public class NewAction
: AbstractScaffoldAction
32 protected object instance
;
34 public NewAction(Type modelType
, ITemplateEngine templateEngine
, bool useModelName
, bool useDefaultLayout
) :
35 base(modelType
, templateEngine
, useModelName
, useDefaultLayout
)
39 protected override string ComputeTemplateName(Controller controller
)
41 return String
.Format(@"{0}\new{1}", controller
.Name
, Model
.Type
.Name
);
44 protected override void PerformActionProcess(Controller controller
)
46 base.PerformActionProcess(controller
);
50 instance
= Activator
.CreateInstance(Model
.Type
);
52 // instance = binder.BindObject(Model.Type,
54 // builder.BuildSourceNode(controller.Request.QueryString) );
57 controller
.PropertyBag
["prefix"] = Model
.Type
.Name
;
58 controller
.PropertyBag
["instance"] = instance
;
61 protected override void RenderStandardHtml(Controller controller
)
63 SetUpHelpers(controller
);
64 RenderFromTemplate("new.vm", controller
);