1 // Copyright 2004-2008 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
.ActiveRecordSupport
.Scaffold
18 using Castle
.ActiveRecord
;
19 using Castle
.Components
.Common
.TemplateEngine
;
20 using Castle
.MonoRail
.Framework
;
23 /// Renders an edit form
26 /// Searchs for a template named <c>edit{name}</c>
28 public class EditAction
: AbstractScaffoldAction
30 public EditAction(Type modelType
, ITemplateEngine templateEngine
, bool useModelName
, bool useDefaultLayout
) :
31 base(modelType
, templateEngine
, useModelName
, useDefaultLayout
)
35 protected override string ComputeTemplateName(IControllerContext controller
)
37 return controller
.Name
+ "\\edit";
40 protected override void PerformActionProcess(IEngineContext engineContext
, IController controller
, IControllerContext controllerContext
)
42 base.PerformActionProcess(engineContext
, controller
, controllerContext
);
44 object idVal
= CommonOperationUtils
.ReadPkFromParams(controllerContext
.CustomActionParameters
, engineContext
.Request
, ObtainPKProperty());
48 if (!engineContext
.Flash
.Contains(Model
.Type
.Name
))
50 object instance
= ActiveRecordMediator
.FindByPrimaryKey(Model
.Type
, idVal
, true);
51 controllerContext
.PropertyBag
["instance"] = instance
;
52 controllerContext
.PropertyBag
[Model
.Type
.Name
] = instance
;
55 controllerContext
.PropertyBag
["prefix"] = Model
.Type
.Name
;
56 controllerContext
.PropertyBag
["id"] = idVal
;
60 throw new ScaffoldException("Could not obtain instance by using this id", ex
);
64 protected override void RenderStandardHtml(IEngineContext engineContext
, IController controller
, IControllerContext controllerContext
)
66 SetUpHelpers(engineContext
, controller
, controllerContext
);
67 RenderFromTemplate("edit.vm", engineContext
, controller
, controllerContext
);