我有以下显示所有产品的重复控件:
<xp:repeat id="rptProduct" rows="16" value="#{vwProduct}"
var="productRow">
<xp:panel styleClass="linkPanel" id="panel1">
<xp:text escape="false" id="imgHTML">
<xp:this.value><![CDATA[#{javascript:getImgURLForProduct(productRow.getDocument());}]]></xp:this.value>
</xp:text>
<xp:eventHandler event="onClientLoad"
submit="true" refreshMode="norefresh"></xp:eventHandler></xp:panel>
</xp:repeat>
其中 getImgURLForProduct 从另一个数据库构建 URL:
function getImgURLForProduct(doc:NotesDocument) {
var resourceDB:NotesDatabase = session.getDatabase(getWebServer(), applicationScope.aspCRMResourceDBPath);
var strReturnVal:String = "<a style='text-decoration: none;' href='#'>";
if (resourceDB != null) {
if (resourceDB.isOpen()) {
var vwResource:NotesView = resourceDB.getView("vwLookupAttachmentsForPrimaryImg");
if (vwResource != null) {
var pictureDoc:NotesDocument = vwResource.getDocumentByKey(doc.getItemValueString("fldProductCode"), true);
if (pictureDoc != null) {
if (pictureDoc.hasItem("fldThumbImage")) {
var rtiLockPicture:NotesRichTextItem = pictureDoc.getFirstItem("fldThumbImage");
var eos:java.util.Vector = rtiLockPicture.getEmbeddedObjects();
if (eos.isEmpty() == false) {
var eosi:java.util.Iterator = eos.iterator();
while (eosi.hasNext()) {
var eo:NotesEmbeddedObject = eosi.next();
if (eo.getType() == NotesEmbeddedObject.EMBED_ATTACHMENT) {
var strImageFile:String = "/" + applicationScope.aspCRMResourceDBPath + "/0/" + pictureDoc.getUniversalID() + "/$file/" + eo.getSource();
strReturnVal += "<img src='" + strImageFile + "' alt='" + eo.getSource() + "' border='0' width='105'>";
}
}
}
}
}
}
}
}
strReturnVal += "<br /><br /><span>" + doc.getItemValueString("fldProductCode") + "</span>";
strReturnVal += "</a>";
return strReturnVal;
}
我想知道如何改进代码,以便不会为重复控件中的每个项目初始化数据库和视图?