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
.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(Controller controller
)
37 return String
.Format(@"{0}\edit{1}", controller
.Name
, Model
.Type
.Name
);
40 protected override void PerformActionProcess(Controller controller
)
42 base.PerformActionProcess(controller
);
44 object idVal
= CommonOperationUtils
.ReadPkFromParams(controller
, ObtainPKProperty());
48 if (!controller
.Flash
.Contains(Model
.Type
.Name
))
50 object instance
= ActiveRecordMediator
.FindByPrimaryKey(Model
.Type
, idVal
, true);
51 controller
.PropertyBag
["instance"] = instance
;
52 controller
.PropertyBag
[Model
.Type
.Name
] = instance
;
55 controller
.PropertyBag
["prefix"] = Model
.Type
.Name
;
56 controller
.PropertyBag
["id"] = idVal
;
60 throw new ScaffoldException("Could not obtain instance by using this id", ex
);
64 protected override void RenderStandardHtml(Controller controller
)
66 SetUpHelpers(controller
);
67 RenderFromTemplate("edit.vm", controller
);