Search code examples
xpages-ssjs

Problems writing and reading text in a rtf


In an Xpage I have following rtf :

<xp:inputRichText value="#{document1.example_doc}">
        <xp:this.attrs>
                <xp:attr name="toolbar">
                         <xp:this.value><![CDATA[            [
            ["Bold", "Italic", "Underline", "Strike", "-", "TextColor", "BGColor" ],
            ["Indent", "Outdent"]
                                                ]
                ]]>       </xp:this.value>
                </xp:attr>
        </xp:this.attrs>
</xp:inputRichText>

When I save this document , I see < p dir="ltr"> at the start of every line. This gives me problems afterwards when I try to read the text of this rtf afterwards with var rtf = doc.getFirstItem("example_doc").getText();

The result is always an empty string

So, or I find another way of saving the rtf or I find another way of reading the text of the rtf


Solution

  • I found a solution to my problem.

    I'm binding a viewScope variable (exampl_doc) to the data attribute of the inputRichText. In the onclick event of the save button , I replace all the < p dir="ltr"> with < p>

    In that way when reading the rtf afterwards with var rtf = doc.getFirstItem("example_doc").getText(); , I'm getting the correct text of that field.

    try{
       var regex = /<p dir="ltr">/gi;
       var rtf = viewScope.example_doc.toString().replace(regex, '<p>');
       document1.replaceItemValue("example_doc",rtf);
       document1.save();
    }
    catch(e){
       sessionScope.error +=e.toString();
    }