The Ultimate Domino Web Editor
Don't worry. This entry starts off looking like a rant but ends with some really good news.
No sooner yesterday had I written this long-winded rant at Lotus than I had been through a load of forms and enabled the Java Applet on them. Things were working ok and I was resigned to the fact that this was the way it had to be. Then I added a few File Upload Controls to the forms. Yet another problem to deal with! Rich Text fields using the Java Applet "absorb" the attachments on the web. Whether or not the file has anything at all to do with the first applet-field on the form doesn't seem to matter. To get round this I have had to hide (style=display:none) another Editor Applet at the top of the form, called "Attachments". At this point I was ready for writing another rant to vent my anger at how ridiculous it all is. Then came some good new that had a lovely calming effect on my soul.
In yesterday's post I mentioned that all we needed was:
a way to programatically set the MIME type of the field to text/html instead of text/plain
This, effectively, is what the code David Schmidt posted in response does. I'm not exactly sure how it works, but it does. And that's all I care about for now. The code is run during the WebQuerySave event of a field with a normal RichText field on it that contains HTML code. When the resulting document is opened to read, the code is sent to the browser as HTML rather than plain text. Brilliant. it may be a hack of sort but it's not half as bad as the other hacks I've seen or been using. Here's the code:
Dim vWebSession As New notessession
Dim vThisDatabase As notesdatabase
Dim vThisDocument As notesdocument
Dim vRichStyle As NotesRichTextStyle
Dim vRTItem As Variant
Dim vHTMLCode As Variant
Set vThisDatabase = vWebSession.CurrentDatabase
Set vThisDocument = vWebSession.DocumentContext
Set vRichStyle = vWebSession.CreateRichTextStyle
vRichStyle.PassThruHTML=True
Set vRTItem = vThisDocument.GetFirstItem( "Body" )
If ( vRTItem.Type = RICHTEXT ) Then
vHTMLCode= vRTItem.GetUnFormattedText()
Call vThisDocument.RemoveItem("Body")
Set vRTItem = vThisDocument.CreateRichTextItem( "Body" )
Call vRTitem.AppendStyle( vRichStyle )
Call vRTitem.AppendText(vHTMLCode)
End If
Consider the simple form below, on which I've been testing this code with my favourite cross-browser Rich Text editor - HTMLArea 3. The rich text field ("Body") isn't marked as PassThru with any hacks, nor does it use the Java Applet. Yet we can use it to store HTML by simply running the above code on the field, each time it is saved.
You can test the form for yourself if you like. Unlike hacks I've used in the past this allows you to store no limit of HTML. Well, I've tested it up to 200kb!
Making all lines, up to and including the Body field, passthru prevents this ugly code and any errors.
There's more to be said about HTMLArea than I can fit in one blog. The form I linked to is called "simple" for a reason! Expect more examples, an article and a demo database. Thanks to David Schmidt I think we could well have found the ultimate Domino web editor for Rich Text fields!
Note: If you can't wait for the demo database, drop me a line and I'll send you one over...
Hi Jake,
I am a little bit confused. (In the pinball game of life my flippers are little bit further apart than everyone else) :-)
Is it that you dont want to use the Java Applet rich text Notes editor because attachments show up in the first rich text field on the form? Sorry if Im being a bit thick..
Allen
Allen, there are numverous reasons I don't want to use the Java Applet. See Tuesday's post for a list of reasons. The fact that they screw-up file attachment handling is yet another reason.
Maybe I confused things by talking about the files and HTMLArea in the same post. The files I just *had* to rant about to get it off my chest and the HTMLArea thing is something I am excited about and want to pass on.
The thing with writing blog entries is that it always make perfect sense to the author ;o)
This is amazing. What looks like cracking code from David, delight from Jake and a memorable quote from Allen!
Jake is amazing, he welds Big Brother power. Don't remove people's entries because it does not fit into your blog or days rant.
Is there someone reading this that may beable to help me with Java View applets and the onreadystaechange event.
Stu. I will do what the hell I like! If you want help with a view applet go to the forums.
Simply Brilliant. Cheers!! to David and Jake. One ugly beast of a problem is finally laid to rest.
David, can you give me your email address, so I can discuss the onreadystatechange offline. It will keep grumpy Jake happy.
Stu,
You act like your entitled to have someone else do your work for you.
Grow up! If you want free advise try being respectful and gracious. Otherwise call Lotus support!
Jake -
I'm confused. Is the object of the game just to get Domino to render HTML entered in a rich text field? If so, what's wrong with the square bracket trick (e.g. [<h3> My heading</h3>]?
Or are you trying to get HTML marked-up output without forcing users to enter HTML marked-up input?
I hope the question is clear - just trying to phrase it is making my head spin...
Sean
No worries Sean. It's a confusing topic.
There are two problems with marking the field as PassThru. One is that it's easy for the user to accidentally cancel passthru mode by entering a stray ] bracket. The other problem is that I've seen fields marked up like this misbehave and enter stray "@NewLines" in to the HTML. This is ok until the new line happens within an opening/closing tag and things go very wrong!
Ok, this does look promising. I know your not using the client Jake, but do you know what the saved richtext looks like from the client?
I'm living in a mixed client (web/client) world and wonder if this is truly the holy grail we've been looking for?
I hate to disappoint Lance but this ain't no grail! For a mixed environment there is only really one solution and that's to do it the way Lotus want you to.
If you view one of these HTMLArea pages in the client you'll just see HTML code. Even with "Render PassThru in Client" ticked and even with the field marked as passthur explicitly on the form. A shame really.
Lance, unfortunately, I too am in a mixed environment for the predominant application that I work on.
I have tried many different methods of translating documents between the two clients. I have to say that I definately understand your pain and am willing to share what I have tried.
I wanted to give another thank you to Jake and David for this. My web only applications will benifit greatly from this.
Can I ask a stupid question? (Ok, that wasn't it ;-) ) Is that just for web only access databases?
I keep struggling trying to figure out how to get the attachments from the client in to work on the web and vice versa.
Oops, sorry, my browser hadn't refresed with those previous posts. Just ignore me, it's been a long day. :P
Just made neet enchantment. Now it is properly displayed in the Notes client as well. You cannot edit it, since it will remove html but you can see the same way like in the brouser
Jake, I'll send you utdated database with coding that allows viewing on Notes client side as well. Trying to find solution for editing as well (might be impossible)
Actually made it to work almost COMPLETELY!!!!
Yes it working!!! (sorry for exitement)
It's good to see somebody else getting exctied Sas. Send over the DB and I'll pass on the news to all the others.
On its way. Now I am working on the attachments piece
Jake, could I get a copy of that demo database? It just so happens I was agonizing over the very same problem you mentioned, WRT rich text fields "absorbing" attachments.
I couldn't see a way to upload files or add an upload control. Is it there and I'm just missing it, or is it something that still needs to be developed? If it's the latter, I'll be happy to do it -- I just need to know.
Thanks!
I do not understand what the problem with the attachments? Works fine for me. Even with Java richtext :))))
Great stuff!!!!
Thanks Jake
Update. Looks like all pieces finally works as designed :)
hi Jake
Any chance you can mail me db? - Would like to see if I can get a version working which allows client editing as well without messing stuff up.
We're almost there with the Notes + Web editing but I'll mail you one over anyway Steve to see what you do.
Ok guys, its done. Notes+Web+Attachment support. If you can't wait for Jake to put up full article just drop me a line
Could you please send me a the demo database to my e-mail?
Could you send me a demo of the database to my email
Hy!
I am interested in that database where you can edit content in Notes and Web. thank you in advance:)
Is there any change that I can get a copy of the demo database created that allows editing of rich text fields in both Notes and the Web.
This has been an area of frustration for a lot of developers and you might consider adding a download link to this database on your blog.
Thanks