我正在将应用迁移到xpages。我有一个由应用程序收到的电子邮件创建的文档。创建的文档上的richtext字段包含电子邮件正文。有人通过更新此字段并按“发送”按钮来响应发件人。在实际发布之前,我会在发送的内容中添加一些文本并添加一些文本。我尝试了很多方法,但我很难过。
我知道.getItemValue返回一个向量,但我认为我还是给它一个镜头但是返回null。
var rtiIssueField = maildoc.createRichTextItem("body");
rtiIssueField.appendText("**IMPORTANT:blah **");
rtiIssueField.appendText("\n<LWST>");
rtiIssueField.appendText("\n"+stEntryDoc.getItemValue("Issue"));
rtiIssueField.appendText("\n</LWST>")
任何提示? 谢谢 CLEM
答案 0 :(得分:2)
非常感谢您的投入。我几乎就在那里......只需要清理几件事。但是通过你的提示,我能够做我需要的事情。我只是觉得我感谢你并发布了我提出的代码,以防其他人需要它。
var stream:NotesStream = session.createStream();
//Grab the contents of the rt field on the web that has just been edited:
var issueRT:NotesRichTextItem = getComponent("issue1").getValue();
//Prefix some additional information for the customer.
stream.writeText("**IMPORTANT: When responding, please do not include the history. That is, remove this line and everything below it. **");
//carriage return:
stream.writeText("<p>");
//Prefix a tag that will be used to strip off text if they respond WITH email history.
stream.writeText("<LWST>");
//carriage return:
stream.writeText("<p>");
//Prefix the
//Prefix a view scoped variable that contains things like date, responder, etc.
stream.writeText(viewScope.ResponseHeader);
//Add the contents of the rt field.
stream.writeText( issueRT.getText() );
//carriage return:
stream.writeText("<p>");
//Add the end tag.
stream.writeText("</LWST>");
//Create the email body field.
var emailBody:NotesMIMEEntity = maildoc.createMIMEEntity("body");
emailBody.setContentFromText(stream,"text/html;charset=UTF-8", 1725);
stream.close();
答案 1 :(得分:1)
跟我说:“网上没有RichText,它是过去的圣诞鬼,只有MIME”:-) stw
将邮箱首选项(在names.nsf中)设置为“Prefers Mime”,将Body字段设置为“Store as MIME”。这样可以省去从/到MIME / RichtText的持续转换(可能的格式丢失)的麻烦。然后,您可以在提交时截取ckedit字段,也可以使用doc.getMimeEntity来获取body字段。帮助中的.getMimeEntity具有您正在寻找的代码示例
答案 2 :(得分:1)
我创建了一个10旧应用程序的XPage版本,它将richtext(已输入)添加到现有字段。这段代码听起来可能会对你有所帮助:
var moveAddBody = function(doc:NotesDocument){
var addRt:NotesMIMEEntity = doc.getMIMEEntity("addBody");
var attFiles:NotesRichTextItem = doc.getFirstItem("attachedFiles");
if(addRt == null && attFiles == null) return;
if(attFiles != null) {
// println("attFiles: " + attFiles.getText() + ", length=" + attFiles.getValueLength());
}
// if(addRt != null && @Length(addRt.getContentAsText().trim()) <= 28) return; // The standard tags in an empty field fills 28 chars
// Something to move...
var tmpDoc:NotesDocument = doc.getParentDatabase().createDocument(); // Never saved - just left in the wind...
var mime:NotesMIMEEntity = tmpDoc.createMIMEEntity("myBody");
var stream:NotesStream = session.createStream();
var formatter = java.text.SimpleDateFormat('yyyy-MM-dd HH:mm');
var time = formatter.format(@Now());
var logLine:String = '<font size="2" color="#008080" face="sans-serif"><b>' + time + " - " + @Name("[Abbreviate]",@UserName()) + '</b></font>';
stream.writeText(logLine);
if(addRt != null && @Length(addRt.getContentAsText().trim()) > 28) {
stream.writeText('<font size="2" face="sans-serif">'); // Enforce "simiilar" font type/size...
stream.writeText(addRt.getContentAsText());
stream.writeText('</font>');
}
mime.setContentFromText(stream, "text/html", NotesMIMEEntity.ENC_NONE);
var prevMime = session.isConvertMime();
session.setConvertMime(true);
tmpDoc.closeMIMEEntities(true,"myBody");
var rt:NotesRichTextItem = doc.getFirstItem("Body");
var body = null;
if (rt != null) {
body = rt.copyItemToDocument(tmpDoc,"Body");
rt.remove();
}
rt = doc.createRichTextItem("Body");
var rtMime:NotesRichTextItem = tmpDoc.getFirstItem("myBody");
rt.appendRTItem(rtMime);
if(attFiles != null) {
if(addRt == null) rt.addNewLine(1);
rt.appendRTItem(attFiles);
attFiles.remove();
}
if(body != null) {
rt.addNewLine(2);
rt.appendRTItem(body);
}
if(addRt != null) {
addRt.remove();
addRt.recycle();
}
session.setConvertMime(prevMime);
return true;
}
您需要取出上面的一些代码,因为它还会添加一些格式化日期/时间(在有人低语“css ...”之前符合Notes版本;-))。它还处理附件。
希望你能用它来解决你的问题吗?
/约翰
答案 3 :(得分:0)
如果您想从应用程序创建邮件,请查看OpenNTF中的XPages Snippet:http://openntf.org/XSnippets.nsf/snippet.xsp?id=emailbean-send-dominodocument-html-emails-cw-embedded-images-attachments-custom-headerfooter bean提供您需要的一切。