如何在不知道flex和coldfusion中的字段类型或其id的情况下将表单保存到数据库?

时间:2010-06-17 15:18:56

标签: database flex forms dynamic arraycollection

我正在开发一个函数,可以根据对DB的调用在Flex中在运行时生成表单。对DB的调用返回字段类型,id,工具提示等作为arraycollection,然后解析arraycollection以确定基于数组中的类型字段显示什么控件 - 这个位工作正常。

但是,我仍然试图使用CFC将表单字段保存回数据库。

我的表单呈现代码如下,但如何保存输入数据库的值?

我的渲染代码..

    [Bindable]
    public var getglobalprofileb:ArrayCollection;

    public function init(event:ResultEvent):void {
                getglobalprofileb = event.result as ArrayCollection;

        var form:Form = new Form();

          for each(var elements:Object in getglobalprofileb)

            {  
                    switch(elements.type.toString()) 
                            { 
                                case "text": 

                                            var fi:FormItem = new FormItem(); 
                                            fi.toolTip = elements.tooltip.toString();
                                            fi.required = elements.required;
                                            fi.direction = elements.direction;

                                            var li:Label = new Label();
                                            li.text = elements.label;
                                            li.width = 100;

                                            var ti:TextInput = new TextInput(); 
                                            ti.text = elements.default_text.toString();
                                            ti.width = 200;
                                            ti.id = elements.id;

                                            form.addChild(fi);
                                            fi.addChild(li);
                                            fi.addChild(ti);

                                               break; 
                                  case "int": 
                                  break;


                                case "textarea": 
                                            var fa:FormItem = new FormItem(); 
                                            fa.toolTip = elements.tooltip;
                                            fa.required = elements.required;
                                            fa.direction = elements.direction;

                                            var la:Label = new Label();
                                            la.text = elements.label;
                                            la.width = 100;

                                            var ta:TextArea = new TextArea(); 
                                            ta.text = elements.default_text;
                                            ta.id = elements.id;
                                            ta.width = 200;
                                            ta.height = 100;

                                            form.addChild(fa);
                                            fa.addChild(la);
                                            fa.addChild(ta);

                                               break; 
                                  case "int": 
                                  break; 


                                  case "DateField": 
                                            var fdf:FormItem = new FormItem(); 
                                            fdf.toolTip = elements.tooltip;
                                            fdf.required = elements.required;
                                            fdf.direction = elements.direction;

                                            var ldf:Label = new Label();
                                            ldf.text = elements.label;
                                            ldf.width = 100;

                                            var tdf:DateField = new DateField(); 
                                            tdf.formatString="DD/MM/YYYY";
                                            tdf.width = 200;
                                            tdf.id = elements.id;

                                            form.addChild(fdf);
                                            fdf.addChild(ldf);
                                            fdf.addChild(tdf);

                                               break; 
                                  case "int": 
                                  break; 


                                  case "combobox": 
                                            var fcb:FormItem = new FormItem(); 
                                            fcb.toolTip = elements.tooltip;
                                            fcb.required = elements.required;
                                            fcb.direction = elements.direction;

                                            var lcb:Label = new Label();
                                            lcb.text = elements.label;
                                            lcb.width = 100;

                                            var tcb:combobox = new ComboBox();
                                            tcb.id = elements.id;
                                            tcb.width = 200;


                                            var datas:String = elements.Datas;
                                            var arr:ArrayCollection = new ArrayCollection ( 
                                                            datas.split(",")  
                                                                   );

                                            tcb.dataProvider = arr ;

                                            form.addChild(fcb);
                                            fcb.addChild(lcb);
                                            fcb.addChild(tcb);

                                            break; 
                                  case "int": 
                                  break; 

                                  case "HSlider": 
                                            var fhs:FormItem = new FormItem(); 
                                            fhs.toolTip = elements.tooltip;
                                            fhs.required = elements.required;
                                            fhs.direction = elements.direction;

                                            var lhs:Label = new Label();
                                            lhs.text = elements.label;
                                            lhs.width = 100;

                                            var ths:HSlider = new HSlider(); 
                                            ths.tickInterval = 10;
                                            ths.liveDragging = true;
                                            ths.snapInterval = 1;
                                            ths.width = 200;
                                            ths.id = elements.id;

                                            form.addChild(fhs);
                                            fhs.addChild(lhs);
                                            fhs.addChild(ths);

                                           break; 
                                  case "int": 
                                  break; 


                                case "CheckBox": 
                                            var fchb:FormItem = new FormItem(); 
                                            fchb.toolTip = elements.tooltip;
                                            fchb.required = elements.required;
                                            fchb.direction = elements.direction;

                                            var lchb:Label = new Label();
                                            lchb.text = elements.label;
                                            lchb.width = 100;

                                            var tchb:CheckBox = new CheckBox (); 
                                            tchb.id = elements.id; 

                                            form.addChild(fchb);
                                            fchb.addChild(lchb);
                                            fchb.addChild(tchb);

                                            break; 
                                  case "int": 
                                  break; 


                                  case "NumericStepper": 
                                            var fns:FormItem = new FormItem(); 
                                            fns.toolTip = elements.tooltip;
                                            fns.required = elements.required;
                                            fns.direction = elements.direction;

                                            var lns:Label = new Label();
                                            lns.text = elements.label;
                                            lns.width = 100;

                                            var tns:NumericStepper = new NumericStepper (); 
                                            tns.id = elements.id; 

                                            form.addChild(fns);
                                            fns.addChild(lns);
                                            fns.addChild(tns);

                                            break; 
                                  case "int": 
                                  break; 


                                case "Richtext": 
                                            var frte:FormItem = new FormItem(); 
                                            frte.toolTip = elements.tooltip;
                                            frte.required = elements.required;
                                            frte.direction = elements.direction;

                                            var lrte:Label = new Label();
                                            lrte.text = elements.label;
                                            lrte.width = 100;

                                            var trte:RichTextEditor = new RichTextEditor (); 
                                            trte.width = 400;
                                            trte.id =  elements.id;


                                            form.addChild(frte);
                                            frte.addChild(lrte);
                                            frte.addChild(trte);

                                           break; 
                                  case "int": 
                                  break; 




                             }
                     }    

                    this.addChild( form);



                 }   

1 个答案:

答案 0 :(得分:0)

以与Flex接收数据相同的方式将数据发送回CF.

创建通用Object的实例,向其添加属性;我猜id,default_text,label,direction,required,tooltip等...添加'finalVAlue'属性。

在CF中,我认为默认对象应该显示为结构;虽然如果可能的话,我强烈建议在cF和Flex中为这些数据创建一个Value Object,并使用Flex Remoting CFC到AS3对象映射。

如果您需要访问您创建的Flex中的所有表单元素,而不知道ID,则可以使用numChildren和getChildAt对所有子项执行循环。


更新: 以下是创建通用对象和添加属性的示例:

var newObject : Object = new Object();
newObject.property1 = 'some value';
newObject.property2 = 'some other value;
newObject.finalValue = textInput.text;