Repeat control, pass db and view in order to improve performance?
-
11-11-2019 - |
سؤال
I have the following repeat control showing all products:
<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>
Where getImgURLForProduct builds a URL from another database:
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;
}
I was wondering how I can improve the code so that the db and the view are not initialised for each and every item within a repeat control?
لا يوجد حل صحيح
لا تنتمي إلى StackOverflow