I originally posted this on Adobe's web site back in Nov/06...

Title: Sending a ByteArray of rich text to a Java Web Service via
WebService component.

Topic: Keeping the rich text (HTML formatted string) intact

I was able to send and receive rich text (HTML formatted txt) intact
via a Java web service using Weblogic 9.2. Creating a web service in
Weblogic 8.1 is more difficult so I opted for this route. Regardless
what back end implementation you are using, in order to keep rich text
intact is to send it via a ByteArray in flex. And with the web service
(possibly using Coldfusion), be sure that the input parameter and
return types that the WSDL creates are "base64Binary."

Creating a web service in Weblogic 9.2 is pretty easy. If you are
using this app server then the 9.2 docs on Web Services is how I
created my back end. My web service simply accepts a byte[] as a
parameter and returns it.

public class HelloWorldImpl {

 public byte[] getBytes(byte[] bAry) {
  return bAry;
 }
}

In flex:

[Bindable] private var bAryObj:ByteArray = new ByteArray();
[Bindable] private var txtResult:String;

public function sendingBytes(event:Event) {

 // inputTxt is a HTML formatted string a.k.a rich text
 bAryObj.writeUTF(inputTxt);

 // call webService
 wsData.getBytes.send();
}

public function webSvcHandler(event:ResultEvent) {

 var b:ByteArray = new ByteArray();
 b.position = 0; // make sure you read the array from the beginning

 // use binding of txtResult in some component as {txtResult}
 txtResult = b.readUTF() as String;
}

mxml - be sure mxml parameter names match exactly the web service
parameter names:

<mx:WebService id="wsData"
 wsdl="yourWsdl"
 result="webSvcHandler(event)"
 fault="faultHandler(event)"

<mx:operation name="getBytes">
<mx:request xmlns="">
<bAry>{bAryObj}</bAry>
</mx:request>
</mx:operation>
</mx:WebService>

I used a Button component to call sendingBytes() via the click event.

Hope I didn't forget anything...and hope this helps.

Bob I.




--- In [email protected], "pdflibpilot" <[EMAIL PROTECTED]> wrote:
>
> I am trying to develop a method to allow web administrators to be able
> to edit text in their Flex application directly in the UI (without
> Flex). This text gets saved to mySQL when they close the rich text
> editor.  
> 
> The data is stored correctly in mySQL however when its retrieved it
> gets formated as an XML object when extracted from the event.result.
> 
> While this makes it easy to populate the various labels and text
> objects with the rich text data. The problem is that the rich text
> data gets formatted as XML with new lines and indents. Like in this
> dmup............
> 
> <contentLive>
>   <TEXTFORMAT LEADING="2">
>     <P ALIGN="CENTER">
>       <FONT FACE="Verdana" SIZE="14" COLOR="#FFFFFF" LETTERSPACING="0"
> KERNING="0">
>         <B>This is </B>
>         <FONT COLOR="#0033FF">
>           <B>
>             <U>live content</U>
>           </B>
>         </FONT>
>       </FONT>
>     </P>
>   </TEXTFORMAT>
> </contentLive>
> 
> How can I force it to treat it as raw text just like its stored in
> mySQL without the formatting ?
>

Reply via email to