コード例 #1
0
ファイル: FormEngine.cs プロジェクト: asty-labs/nasty-web
        /**
         * Renders main view for the Form, using the model returned by prepareModel-method.
         * Generates javascript to initialize all rendered components.
         *
         * @param form  Form to be rendered
         * @return      HtmlFragment with rendered HTML and initialization script
         */
        public HtmlFragment RenderMainView(Form form)
        {
            form.FormEngine = this;
            var builder = new StringBuilder();

            builder.Append(ComponentRenderingHelper.GetStartTag(form));
            var model = form.PrepareModel();
            var reg   = new RenderingContext(form);

            reg.Collect(() => builder.Append(_viewRenderer.RenderMainView(form, model)));
            builder.Append(ComponentRenderingHelper.GetEndTag(form));
            var script = new JsClosure(delegate
            {
                form.Init();
                foreach (var comp in reg.Components)
                {
                    comp.Init();
                }
                form.AfterInit();
                UpdateForm(form);
            });

            return(new HtmlFragment(builder.ToString(), script));
        }