logo

Even "simple" is hard when you're using Domino!

Yesterday I tried to explain a solution to a problem a lot of us might never face. But imagine now that we remove most of the factors involved. We end up with a simple requirement that still requires a hack.

Imagine a form with no files attachments and no need to be edited in the client. All it needs is one field to store all the HTML created by your web editor. You simply submit the content of the field to the Notes document and, when it's opened for reading, the HTML is sent to the browser for display. Easy? Is it heck!

First, let's rule out text fields. The size limit on them just doesn't cut it in a publishing scenario. We have to use Rich Text fields. This is where the problems begin!

Imagine you have a simple Rich Text field on your form called "Body". You type in "this is <b>HTML</b>" and submit it. When you open the document in read mode, you see exactly what you typed in. No bold text, just markup. This is of course what you should expect. If you type in an angle bracket > you'd expect to see an angle bracket. Domino doesn't know you want HTML stored. So you mark the field as PassThru HTML. This doesn't work. Don't ask me why, as I don't know. So you place square brackets [] round the field. This works but only if you happen to start and end the field contents with HTML markup. So you make sure it does by surrounding the field with [<!-- start Body --> and <!-- end Body -->]. This seems to work. But then you get that nagging feeling that something just ain't right. What if somebody were to type a stray closing ] bracket in the body, like I just did? It would break your page in spectacular fashion. A "normal" Rich Text field just won't do the job.

You start thinking about other options. What about the Java Applet? How does that do it? It lets you edit WYSIWYG style and the HTML is intact in read mode. After a little investigation you notice the field is stored as MIME content in the document. So you change your normal Rich Text and give it the property "Store contents as HTML and MIME". Sure enough the field is then stored as MIME. But it still doesn't show up as HTML in read-mode. The reason for this is that MIME from the Java Applet is stored with content-type header of "text/html" whilst MIME from the none Applet field is stored with content-type "text/plain"!!

What is needed is a way to tell Domino that this Rich Text field should be as HTML. As far as I know there is no way to do this. I've played with Web Query Save agents and the new MIME Java classes added to Domino 6. But had no luck. For now I am resigned to hiding Applets on the page and switching content back and forth with my own choice of editor.

What is needed is either a way to easily store fields with a content-type of text/html or a means of adding text fields with no size limit. I won't hold my breath for either. However, I do hope one of you guys knows some simple solution to this...

Comments

    • avatar
    • pF
    • Fri 12 Dec 2003 05:47

    The old form property of "Treat document contetn as HTML" doesn't work?

    • avatar
    • Richard
    • Fri 12 Dec 2003 06:27

    Unfortunately, you cannot change the

    NotesMIMEEntity.ContentType & .ContentSubType properties (according to R5 help) ...

    So here's another hack ...

    On your form you have the following:

    1 rich-text field - visible in edit mode.

    20 text fields - visible in read mode (wrap these in pass-thru-html).

    Get the web-query-save agent to copy the data/text from the rich-text field into the text-fields, and it will need to cut the rich-text data/text into 10-15kb bites for each text-field ...

    Why 20 text fields? Well, it depends on how much data you are expecting .. 20 fields should hold about 200-300 kb of data/text.

    • avatar
    • laurens
    • Fri 12 Dec 2003 06:28

    I dislike RTF so much from past experience, that I never try to use them. So far this seems possible. I like text fields, but also run into the 32k (or 64k?) size limit, which still is a reasonable amount of text {Link} . Nevertheless I had to cut the above article in 4 pieces. Would a possible solution be to split the content of one text area over 4 or more different Notes fields? (quite a pain if you want to toggle between read and edit mode). Or for the same reason, split the content the RTF over 4 text fields using @abstract.

    • avatar
    • Jens
    • Fri 12 Dec 2003 06:58

    If you name the rich text field "HTML" Domino will just pass the content as html to the browser... Simple enough?

    :-)

  1. I use the following technique.

    Put a hidden rich text field on the form, and make sure it gets passed out to HTML (either use display:none, or set the 'send all fields' option).

    Put a textarea input on the form (a multiline text field).

    In Javascript, on page load, copy the contents of the rich text field (document.field.value) to the the text area. On submit, do the opposite, and clear the textarea so you don't save both copies.

    If you want DHTML rich text editing, copy the rich text field value to a div.innerHTML that you setup as contenteditable. Again, on submit, copy the div.innerHTML back to the rich text field. This only works in IE 5.(5?)+ though, when they introduced contenteditable.

    • avatar
    • Patrick
    • Fri 12 Dec 2003 07:44

    Just to re-iterate Jens 'simple' is easy if you know how :- Any field with a field name of 'HTML' will always be processed by Domino as PassThru HTML.

    • avatar
    • Jake
    • Fri 12 Dec 2003 08:21

    Wouldn't you know it ;o)

    I posted this and left for a two hour bike ride in the cold and rain to "clear my head".

    I got in a few minutes ago and started reading the comments via the emails that come to me. In amongst the mail was a spam. The subject was "Jake embarrasses himself". Normally I can spot spam a mile off. Given the cirumstances I fell for it and opened this mail from "Stewart Pruitt". What a fool I am. Double the shame!

    Anyway, thanks to Jen. I've not tried it yet but will report back soon. Hopefully with some goodd news for once.

    • avatar
    • Jake
    • Fri 12 Dec 2003 08:32

    That didn't take long did it... ok, it works. Brilliant. (see a later post from me. It doesn't work. Not brilliant!)

    Now I just want to save some face. This is, as you guys mentioned, simple. BUT! Why, why, why didn't I know this!!!!

    This infuriates me about Domino development. It's like a game. It's not what you know, or who you know, it's what who you know knows. How people come about this knowledge is anybody's guess. Internal leeks at Lotus?

    Remember this method {Link} of creating a checkbox called "%%Detach" to remove attachments? How did I know about this? Somebody at Lotus happened to mention it in an email. Where's the documentation for it?...

    Anyway, I am happy now because I have rid a form of the Applet and can enjoy my weekend without worrying about not being able to code the most basic of user requirements.

    I thank you all.

    • avatar
    • Adam
    • Fri 12 Dec 2003 08:50

    I just created a blank form with a field called "HTML" and it worked no problem. I copied the HTML from Codestore into it and previewed it in the browser... It seems identical to codestore website. What I don't understand is when I preview it, how does it pick up the stylesheets...

    • avatar
    • Adam
    • Fri 12 Dec 2003 08:52

    Ok.. Silly me.. just realised after posting previous entry... the command @Import... {Link}

  2. Hi Jake,

    You can always stay with the brackets around your field and use an simple js to test existence / replace ] with ]

  3. Sorry got caught at my own game,

    replace ] with &#93;

    • avatar
    • Patrick
    • Fri 12 Dec 2003 09:00

    This technique is documented in the R5 Designer Help database in a document called 'Storing HTML in a field'. I know the help is usually not too helpful, but sometimes it can be...

    • avatar
    • Adam
    • Fri 12 Dec 2003 09:07

    Hi Jake.. think your clock is out of wack.. Surely its not 9:00AM in the UK.. its 16:00 here in CET

    • avatar
    • Lance
    • Fri 12 Dec 2003 09:12

    I've been following this article and the remaining question I have is how does the text display to the 'editor'. Is it html or is it formatted text?

    I just can't see regular folks who want to publish an article, use html. Am I wrong here? They just won't get it. I haven't read up on the editor your using Jake, and I see that it stores the field as html, does the editor show it as plain formatted text?

    • avatar
    • Jake
    • Fri 12 Dec 2003 09:16

    Nicolas. I could do that but my approach to development is to avoid anything you shouldn't have to do. I always seek the "pure" solution.

    Patrick. Ok, go on, rub it in. Now I feel double double stupid. I have to say I think there are bells ringing ever so quietly in my head telling me I knew this all along.

    Adam. Not only the @Import but the fact that there's a <base href="codestore.net/" /> in there. This makes most things point to this server. The time is set by the hosts who are in CET (I think). It doesn;t bother me that the time is out. It's a relative thing....

    • avatar
    • Jake
    • Fri 12 Dec 2003 09:32

    Wait a cotton-picking minute!

    I've tested it some more and found a huge flaw with the HTML field. As the help states - "To pass HTML directly to the browser and force Domino to disregard all other fields, add a field named HTML to the form.".

    So, if you have a field called HTML. All that gets sent to the browser in read mode is the contents of the field!!!!

    I really really want to swear. Instead I am going to go and make a cup of tea and dream of a career in PHP.....

  4. Jake, I've got an old 4.6 book called "Professional Developers Guide to Domino", {Link}

    This documents the use of the HTML named Rich Text field.

    • avatar
    • Jerry Carter
    • Fri 12 Dec 2003 09:37

    Some of those previously mentioned hacks are starting to sound better all the time.

    I guess, in the end, we have to accept the limitations and get into the habit of telling the users what they can and can't reasonably get while staying within Domino. If they are sufficiently non-plussed, we can always suggest an alternative.

    I'm with you on the tea, Jake...

    • avatar
    • john
    • Fri 12 Dec 2003 09:56

    marking the field as PassThru HTML can work but I found you have to set the property first and then add the text after.

    In fact the more 'stable' way is to put your HTML text into RTF field 1, create an RTF field2, set it's pass-thru HTML property and then copy/append the contents of RTF1 onto it !

    Also, make sure that you put carriage returns into it before saving as Domino will break the text at unusual places and mess up the presentation of HTML - result - you end up seeing the HTML code and not the formatted output.

    • avatar
    • Ian B
    • Sat 13 Dec 2003 08:59

    Jake,

    Did you actually try putting [ or ] in the RTField that had [<!-- start Body --> and <!-- end Body -->] around it? It seems logical that a stray bracket will reek havoc but I just tried and Domino just treats it like any other character, and continues the pass-thru. I've experimented with any number of brackets in any order.

    See website link for screenshot.

    As that works, for flexibility, you could put a check box to indicate whether the content will be HTML and hide the surrounding square brackets and markup accordingly.

  5. YOU CAN MARK A FIELD AS PASS-THRU HTML!

    BUT if it's all by itself with no HTML around it then you have to make sure you have a space before and after the field and include them in the pass-thru HTML region.

    Highlight just the field and tick pass-thru HTML don't work, highlight the field AND a space before and after the field DOES work!

    A stoopid but typical Notes behaviour foible I stumbled across one day.

    I would have thought you'd be use to this by now?

    • avatar
    • Jake
    • Mon 15 Dec 2003 04:32

    Andrew. You're right. I have tried that. And it doesn't work. Unless I'm missing something else. Maybe the line before and after the line with the field on needs to be special as well...

  6. I've done this too in the past, and it worked for me too, however, I've a sneaking suspicion that you may also have to have the RT field in a table, its all a bit icky isn't it.

  7. Couldn't you use the PassThruHTML property of NotesRichtextStyle to mark the rtf as HTML? If my memory serves me right u can use it in conjunction with 2 rtf-fields. One for storing, one for presentation. Simply append the content of the storing field to the presentation field after appending the style in a WQO-Agent:

    Set item = doc.getFirstItem("StoreField")

    Call doc.removeItem("PresentField")

    Set newitem = doc.createRichTextItem("PresentField")

    Dim richStyle As NotesRichTextStyle

    Set richStyle = s.CreateRichTextStyle

    richStyle.PassThruHTML = True

    If newitem.Type = RICHTEXT Then

    Call newitem.AppendStyle(richStyle)

    Call newitem.appendRTItem(item)

    End If

    • avatar
    • dave
    • Mon 15 Dec 2003 15:32

    for what it's worth you can extend to usability of the text field by manipulating the IsSummary flag in the webquerysave. By setting this field to false Domino gives you a lot more room to store your text within the document.

    • avatar
    • Jake
    • Mon 15 Dec 2003 17:47

    Dave. I tried to email you at thay magecraft.net address but it was returned. Do you mind dropping me a line if you read this?

  8. Hi Jake!

    Have you tried to make use of the cgi param 'REQUEST_CONTENT'? This param should have the capacity to hold the amount of data that you are asking for.

    I had a Domino DB where I didn't want to give the users 'Author' access right, but still I would like them to post forms in that particular database. (I know it sounds strange...) However, the solution to this was to create a static page (or HTML file) containing the form. The submission of the form (a POST) is handled by an LotusScript agent that retrives the form data by using something like:

    set doc = session.documentcontext

    strPostData = doc.GetItemValue("Request_content")(0)

    myVar = ExtractParam(strPostData,"quote") 'extract the field data

    • avatar
    • Jo
    • Tue 16 Dec 2003 12:06

    hi,

    Just tossing in an idea, havent' tried this...

    Just save your html in any rich text field in the doc.

    In the WQO agent redirect to an agent that opens the doc and then prints the contents of the field to the output.

    j.

    • avatar
    • Jake
    • Tue 16 Dec 2003 12:14

    Thanks for the idea Jo.

    There are literally dozens of approaches to this problem that will probably achieve the goal. What I want to do is avoid using any of them. Why should we have to? We shouldn't! The solution I want to find is the cleanest...

  9. A little late I saw this post, and I won't take the time to read all what was written about it, so maybe the way I work was already mentioned before (if so, feel free to remove my post).

    First of all, I used the editor "ACE" ({Link} this one is not free, but cheap and has a lot of useful features, looks good etc. Before that I used an open source alternative and my solution also worked for this one.

    The editor used its own textarea or div for adding content, onsubmit the content is copied to a richtext field (made invisible clientside by using a style="display: none" but I assume you could also just make a hidden domino field). The opposite is done if you want to load the html for editing: onload the html is copied to the editor.

    This richtext field is made passthru html and the property "Web access" is on "using html".

    Now, if I just want to display it, I use the same richtext field with the same properties, it doesn't matter if I use a new form for display or the same one.

    Hope this helped?

    • avatar
    • dh
    • Wed 13 Apr 2005 22:31

    I haven't quite figured out the details of this, but if text in the rich text applet is the appropriate color of green, it is treated as pass through HTML. I discovered this by creating a table in MS-Word, then cutting and pasting it into the rich text applet. The html appears in one of the greens (though the rich text applet doesn't make it obvious which patch in the color matrix is being used). I also got it to insert a figure into the rich text applet by using the appropriate green on an <IMG SRC=...> code. (Interestingly, the picture itself, not the html code, appears in the rich text applet when it is in edit mode.)

    • avatar
    • Jason
    • Tue 4 Oct 2005 06:30 AM

    If you are using LotusScript to generate the contents of the RTF:

    Dim session As New NotesSession

    Dim rtStyle As NotesRichTextStyle

    Set rtStyle = session.createRichTextStyle

    rtStyle.PassThruHtml = True

    Call rtBody.AppendStyle(rtStyle)

    Call rtBody.AppendText("<table......")

    • avatar
    • AK
    • Wed 14 Dec 2005 06:30 AM

    Hi,

    I want to send a retrieve the contents of a http post-send, for which I am using the following statements:

    set doc = session.documentcontext

    strPostData = doc.GetItemValue("Request_content")(0)

    But the problem is that "Request_content" does not accept strings more than 32K. Is there any way I can increase this limit?

    • avatar
    • msosvi
    • Tue 18 Sep 2007 06:43 PM

    "What is needed is a way to tell Domino that this Rich Text field should be as HTML. As far as I know there is no way to do this. I've played with Web Query Save agents and the new MIME Java classes added to Domino 6. But had no luck."

    I hope that this serves you:

    import lotus.domino.*;

    import java.util.Vector;

    public class WebSave extends AgentBase {

    public void NotesMain() {

    try {

    Session session = getSession();

    AgentContext agentContext = session.getAgentContext();

    /*------*/

    Document docContext=agentContext.getDocumentContext();

    session.setConvertMIME(false);

    Item body=docContext.getFirstItem("Body");

    MIMEEntity mime=body.getMIMEEntity();

    Vector headers = mime.getHeaderObjects();

    for (int j = 0; j < headers.size(); j++) {

    MIMEHeader header = (MIMEHeader)headers.elementAt(j);

    if (header.getHeaderName().equals("Content-Type")){

    header.setHeaderVal("text/html");

    }

    }

    docContext.save(true,true);

    session.setConvertMIME(true);

    /*------*/

    } catch(Exception e) {

    e.printStackTrace();

    }

    }

    }

    Thank you for your blog.

    • avatar
    • Johann
    • Tue 18 Mar 2008 05:10 PM

    I used something different and simpler to me:

    1. Put the HTML code into an editable Rich Text Field.

    2. Check the "Automatically enable edit mode" on form properties.

    3. In the onload event I put the code using innerHTML property

    document.body.innerHTML=document.forms[0].borrador.value

    In my case I replace all the body HTML with the HTML in borrador rich text field.

    It works OK to me.

Your Comments

Name:
E-mail:
(optional)
Website:
(optional)
Comment:


About This Page

Written by Jake Howlett on Fri 12 Dec 2003

Share This Page

# ( ) '

Comments

The most recent comments added:

  • avatar Johann about 16 years ago
  • avatar msosvi about 17 years ago
  • avatar AK about 18 years ago
  • avatar Jason about 19 years ago
  • avatar dh about 19 years ago
  • avatar Martin about 20 years ago

Skip to the comments or add your own.

You can subscribe to an individual RSS feed of comments on this entry.

Let's Get Social


About This Website

CodeStore is all about web development. Concentrating on Lotus Domino, ASP.NET, Flex, SharePoint and all things internet.

Your host is Jake Howlett who runs his own web development company called Rockall Design and is always on the lookout for new and interesting work to do.

You can find me on Twitter and on Linked In.

Read more about this site »

More Content