我想讀取和寫入我的XPages應用程序中的RTF文本字段。在XPages中顯示和編輯RTF文本字段
在我Employee類我已經定義了應包含儘可能遵循了豐富的文本字段的內容領域:
private com.ibm.xsp.http.MimeMultipart comment;
public com.ibm.xsp.http.MimeMultipart getComment() {
return comment;
}
public void setComment(com.ibm.xsp.http.MimeMultipart comment) {
this.comment = comment;
}
現在在我的EmployeeDAO類我不知道我應該怎麼加載在Notes中的富文本內容文件並設置評論欄?
我發現下面的辦法,我認爲是不是「優雅」:
public void loadRT(Document doc){
MimeMultipart strValue = null;
try {
if (doc.hasItem("Body")){
if (doc.getFirstItem("Body") != null) {
//?? not sure what the type value stands for
if (doc.getFirstItem("Body").getType() != 1) {
strValue = MimeMultipart.fromHTML(doc.getItemValueString("Body"));
} else {
RichTextItem rti = (RichTextItem) doc.getFirstItem("Body");
if (rti != null) {
HttpServletRequest rq = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
String curURL = rq.getRequestURL().toString();
String docid = doc.getUniversalID();
String notesURL = curURL.substring(0, curURL.indexOf(rq.getContextPath()) + 1) + doc.getParentDatabase().getFilePath() + "/0/" + docid + "/" + "Body"
+ "?OpenField";
URL docURL;
try {
docURL = new URL(notesURL);
URLConnection uc = docURL.openConnection();
uc.setRequestProperty("Cookie", rq.getHeader("Cookie"));
uc.connect();
// do the HTTP request
BufferedReader in = new BufferedReader(new InputStreamReader(uc.getInputStream(), "UTF-8"));
// process the data returned
StringBuffer strBuf = new StringBuffer();
String tmpStr = "";
while ((tmpStr = in.readLine()) != null) {
strBuf.append(tmpStr);
}
strValue = MimeMultipart.fromHTML(strBuf.toString());
employee.setComment(strValue);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
}
} catch (NotesException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
在我的XPage我可以綁定這一個XP:爲遵循inputRichText控制:
<xp:inputRichText id="inputRichText1"
value="#{employeeBean.employee.comment}" style="height:400px"
readonly="#{employeeBean.employee.editable eq false}">
</xp:inputRichText>
我到目前爲止我還沒有如何將富文本控件調整爲其內容的大小,也沒有排除某些富文本工具欄選項。
我還沒有來到那麼遠如何保存任何調整。
我的方法是否正確?還是有更整潔,更清潔的方法?
僅供參考Notes文檔中的字段是Rich Text類型。內容是「唯一」的文字。目前使用Domino(web)表單並且使用Rich Text類型的字段。
任何幫助都非常感謝,因爲任何解釋/示例代碼似乎都很少!
是否需要在傳統的Notes表單中顯示數據?還是僅僅存儲數據? –
你好弗蘭克,文檔不能通過Notes表單編輯(該表單僅限於web) – Malin
在xpages應用程序中,我們將RichText html作爲純文本存儲在一個字段中,因爲網頁RichText不存在。 –