在XPage中显示包含图像的富文本重复控制

时间:2013-04-26 19:01:05

标签: xpages lotus-domino

我有一个主文档,其中包含一组链接的更新文档,其中包含一些字段和一个富文本正文字段。我可以在重复控件中显示更新中的任何视图列,但我也希望在重复控件中显示富文本字段。

我尝试了几种方法,到目前为止还没有任何工作。

我尝试了这个解决方案:

rowData.getDocument().getFirstItem("Body").getMIMEEntityAsText()

和这一个:

rowData.getDocument().getFirstItem("Body").getMIMEEntity().getContentAsText(); 

和这一个:

http://iqjam.net/iqjam/iqjam.nsf/questions/20100914_How_to_Display_a_RichText_fiel.htm

<xp:repeat id="repeat1" rows="30" value="#{view1}" var="row">
    <xp:panel>
        <xp:this.data>
            <xp:dominoDocument var="doc" action="openDocument"
                documentId="#{javascript:row.getNoteID()}">
            </xp:dominoDocument>
        </xp:this.data>
        <xp:inputRichText id="inputRichText1" value="#{doc.ArticleContent}"
            readonly="true">
        </xp:inputRichText>
    </xp:panel>
</xp:repeat>

和这一个:

http://www.ibmpressbooks.com/articles/article.asp?p=1681058&seqNum=4

var nd:NotesDocument = rowData.getDocument();
var mime = nd.getMIMEEntity("body");
// if it is MIME then you can passthrough as HTML
if (mime != null) {
      return mime.getContentAsText();
}
// Otherwise just return the plain text
else {
      return nd.getItemValueString("body");
}

它们都只显示那些仅包含文字的文档。如果有嵌入的图像或图像和文本的混合,则不显示任何内容。

我很感激任何建议......

4 个答案:

答案 0 :(得分:4)

所以添加了Tim的ignoreRequestParams="true",这有效:

<xp:repeat id="repeat1" rows="30" value="#{view1}" var="row">
    <xp:panel>
        <xp:this.data>
            <xp:dominoDocument var="doc" action="openDocument"
                documentId="#{javascript:row.getNoteID()}" 
                ignoreRequestParams="true">
            </xp:dominoDocument>
        </xp:this.data>
        <xp:inputRichText id="inputRichText1" value="#{doc.ArticleContent}"
            readonly="true">
        </xp:inputRichText>
    </xp:panel>
</xp:repeat>

答案 1 :(得分:1)

好的,正如弗雷德里克所写,你有一个多部分的mime字段,所以你需要浏览所有的条目(文本和图像)。

<xp:text escape="false" id="subContent">
                                        <xp:this.value><![CDATA[#{javascript:
session.setConvertMIME(false);
if(level3List != null){
var nd:NotesDocument = level3List.getDocument();
if(nd != null){
 try{   
  requestScope.status = "";
  var cItem:NotesRichTextItem = nd.getFirstItem("content");
  var mime:NotesMIMEEntity = cItem.getMIMEEntity();
  if (mime != null) {
   // If multipart MIME entity
   if (mime.getContentType().equals("multipart")) {
    // Print content of each child entity
    var child1:NotesMIMEEntity = mime.getFirstChildEntity();
    while (child1 != null) {
     if(child1.getEncoding()==1727){
      //gif             
        requestScope.status +=
        "<img src=\"data:image/png;base64," + 
        child1.getContentAsText() +
        "\"/>"              
      }else{
       //plain
       requestScope.status += 
       child1.getContentAsText() //+ "\n"
     }          
      var child2:NotesMIMEEntity = child1.getFirstChildEntity();
       if (child2 == null) {
        child2 = child1.getNextSibling();
        if (child2 == null) {
         child2 = child1.getParentEntity();
        if (child2 != null) {
         child2 = child2.getNextSibling();
        }
       }
      }
      child1 = child2;
     }
      } else {
     // plain mime no multi
     requestScope.status = mime.getContentAsText();
    }
    } else {
    // No mime > plain text
    requestScope.status = nd.getFirstItem("content").getText();
    }
    // return to display
    return requestScope.status;
  }catch(e){
    return nd.getFirstItem("content").getText();
   }    
  }
}
// Restore conversion
session.setConvertMIME(true);}]]></xp:this.value>
</xp:text> 

我目前唯一面临的问题是,我正在失去图像的位置。它们将全部显示在底部。

此代码也可以在IBM文档中找到类似的代码

IBM

答案 2 :(得分:0)

如果您只有文本,则文档中只有一个mime实体。但是如果你有图像和文本,内容将存储为多部分mime。 Contenttype将是多部分。

然后你必须得到mime实体并从那个mimeentity获取getfirstsibling,如果内容类型是文本,那么得到它并呈现它。

答案 3 :(得分:0)

我不知道这是不是你要找的,但是嘿。 这是我前段时间做过的重复控件,它显示RichText字段中的图像。这是我展示图像的唯一方式,我花了无数个小时寻找更好的解决方案。

<xp:repeat id="repeat1" rows="30" var="imagename" indexVar="index">
      <xp:panel></xp:panel>
      <xp:this.value><![CDATA[#{javascript:doc.getItemValueArray("imagenames")}]]></xp:this.value>
      <xp:text escape="false" id="computedField1">
        <xp:this.value><![CDATA[#{javascript:var url = "/" + @ReplaceSubstring(database.getFilePath(), "\\", "/") + "/0/" +
document1.getDocument().getUniversalID()
url += "/$FILE/" + escape(imagename);
return "<a dojoType=\"dojox.image.Lightbox\" group=\"group1\" title=\"" +
imagename + "\" href=\"" + url + "\">" + imagename + "</a><br />"}]]></xp:this.value>
      </xp:text>
    </xp:repeat>