5 Replies Latest reply on Feb 18, 2010 3:30 AM by David_F57

    Trying to save rich text editor data into the DB

    nikos101 Level 2

      I'm having trouble in FB4 trying to save rich text editor data into the DB and then extracting the data into a Rich Text control. Can this be done?

        • 1. Re: Trying to save rich text editor data into the DB
          nikos101 Level 2

          I figured how to save the HTML text but when trying to display I tried this   <s:RichText  textFlow="{TextFlowUtil.importFromString(this.data.text)}"/>

           

          eg

             <s:List id="list" width="100%"  color="0x0050AA"  height="100%"       dataProvider="{getAlltbNoticesResult.lastResult}" creationComplete="list_creationCompleteHandler(event)" >
                         
                          <s:itemRenderer >
                             
                              <fx:Component   id="fixingItem">
                                  <s:ItemRenderer  width="100%">
                                      <fx:Script>
                                          <![CDATA[
                                              import spark.utils.TextFlowUtil;
                                          ]]>
                                      </fx:Script>
                                  <s:HGroup verticalAlign="middle"  >
                                         
                                          <s:Label text="{this.data.title}" />
                                          <s:RichText  textFlow="{TextFlowUtil.importFromString(this.data.text)}"/>
                                         
                                      </s:HGroup>
                                  </s:ItemRenderer>
                              </fx:Component>
                          </s:itemRenderer>
                      </s:List>
                      <s:RichText width="100%" height="127"  id="preview" textFlow="{TextFlowUtil.importFromString(list.selectedItem.text)}">
                         
                      </s:RichText>

           

          Error: Unknown element http://ns.adobe.com/textLayout/2008::TEXTFORMAT
              at BaseTextLayoutImporter/reportError()[E:\dev\gumbo_beta2\frameworks\projects\textLayout\te xtLayout_conversion\src\flashx\textLayout\conversion\BaseTextLayoutImporter.as:557]
             ect

           

          any ideas?

          • 2. Re: Trying to save rich text editor data into the DB
            David_F57 Level 5

            Hi Nikos,

             

            I have done something similar, this should work

             

            output to database

             

            mydb.contentfield = TextConverter.export(editor.textFlow, TextConverter.TEXT_LAYOUT_FORMAT, ConversionType.STRING_TYPE).toString();

             

             

            input from database

             

            editor.textFlow = TextConverter.importToFlow(mydb.contentfield, TextConverter.TEXT_LAYOUT_FORMAT);

             

             

            David

             

            1 person found this helpful
            • 3. Re: Trying to save rich text editor data into the DB
              nikos101 Level 2

              Thanks but I get this

               

              Multiple markers at this line: -rte -1119: Access of possibly undefined property textFlow through a
              reference with static type mx.controls:RichTextEditor.
              -1120: Access of undefined property
              TextConverter. -1120: Access of undefined property ConversionType. -1120: Access of undefined
              property TextConverter.

              • 5. Re: Trying to save rich text editor data into the DB
                David_F57 Level 5

                Hi,

                 

                the following code retrieves from an sql table the CONTENT field is 'largetext' - When exporting text it is exported out as TEXT_LAYOUT_FORMAT which is basically an xml format with a primary tag of textflow. (I just ripped the relevant bits out of something i'm working on), and added a save and load to give you an idea.

                 

                 

                <?xml version="1.0" encoding="utf-8"?>

                <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"

                   xmlns:s="library://ns.adobe.com/flex/spark"

                   xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" creationComplete="app_creationCompleteHandler(event)" xmlns:menusservice="services.menusservice.*">

                <fx:Script>

                <![CDATA[

                import flashx.textLayout.conversion.ConversionType;

                import flashx.textLayout.conversion.TextConverter;

                 

                import mx.controls.Alert;

                import mx.events.FlexEvent;

                import mx.events.Request;

                import mx.rpc.events.ResultEvent;

                 

                import valueObjects.Menus;

                 

                private var ldr:URLLoader = new URLLoader();

                 

                protected function app_creationCompleteHandler(event:FlexEvent):void

                {

                //myXML.send();

                }

                 

                 

                protected function save_clickHandler(event:MouseEvent):void

                {

                var info:Menus = new Menus();

                info.ID = 0;

                info.IMAGE = img.content;

                info.TITLE = "breakfast";

                info.CONTENT = TextConverter.export(re.textFlow, TextConverter.TEXT_LAYOUT_FORMAT, ConversionType.STRING_TYPE).toString();

                createMenusResult.token = menusService.createMenus(info);

                }

                 

                 

                protected function load_clickHandler(event:MouseEvent):void

                {

                getAllMenusResult.token = menusService.getAllMenus();

                 

                }

                 

                protected function myXML_resultHandler(event:ResultEvent):void

                {

                re.textFlow = TextConverter.importToFlow(event.result, TextConverter.TEXT_LAYOUT_FORMAT);

                }

                 

                protected function createMenusResult_resultHandler(event:ResultEvent):void

                {

                getAllMenusResult.token = menusService.getAllMenus();

                }

                 

                 

                protected function getAllMenusResult_resultHandler(event:ResultEvent):void

                {

                re.textFlow = TextConverter.importToFlow(event.result[0].CONTENT, TextConverter.TEXT_LAYOUT_FORMAT);

                }

                 

                ]]>

                </fx:Script>

                <fx:Declarations>

                <s:HTTPService id="myXML" url="assets/breakfast.xml" result="myXML_resultHandler(event)" resultFormat="e4x"/>

                <s:CallResponder id="getAllMenusResult" result="getAllMenusResult_resultHandler(event)"/>

                <menusservice:MenusService id="menusService" fault="Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)" showBusyCursor="true"/>

                <s:CallResponder id="createMenusResult" result="createMenusResult_resultHandler(event)"/>

                </fx:Declarations>

                <s:RichEditableText id="re" x="409" y="119" text="RichEditableText" width="258" height="373"/>

                <mx:Image id="img" x="176" y="119" width="174" height="373" source="images/breakfast.jpg"/>

                <s:Button x="168" y="34" label="Save" click="save_clickHandler(event)"/>

                <s:Button x="168" y="64" label="Load" click="load_clickHandler(event)"/>

                </s:Application>