質問

In my xpage which is bound to a domDoc datasource I want to build a preview mechanism for images stored in the datasource's richtext field. Designer and server are V 9.0.1.

The names of the attached images are stored as an array in a viewScope var and fed as source to a repeat control. The image control sits inside the repeat. I also put a link control alongside the image offering a means to download the file. The calculated url looks like this:

/dbpath/dbfile.nsf/xsp/.ibmmodres/domino/OpenAttachment/dbpath/dbfile.nsf/docunid/rtBodyField/filename.gif

Calculation of the link works perfect, but the images are never displayed. Instead Firebug tells me that the image's source url could not be resolved. And indeed I see that the db path part has been rendered twice before the /xsp/.ibmmodres/domino/OpenAttachment/ portion of the url (but only once after it!):

/dbpath/dbfile.nsf/dbpath/dbfile.nsf/xsp/.ibmmodres/domino/OpenAttachment/dbpath/dbfile.nsf/docunid/rtBodyField/filename.gif

Here's the code I'm using to calculate the source urls for both the link (using its value property) and the image (using its url property):

var unid=context.getUrlParameter('documentId');
var p=facesContext.getExternalContext().getRequestContextPath();
return p+'/xsp/.ibmmodres/domino/OpenAttachment'+p+'/'+unid + '/rtBodyFld/'+imgEntry;

Here's what I tried so far to solve that miracle:

a) calculate the db path (facesContext...) beforePageLoad, store it in a viewScope, then reference the viewScope when build the image's source ==> same result as above

b) used the image's value property instead of url ==> same result as above

c) use a standard html <img /> tag where the src argument is built using "#{javascript:...}" with the identical code as above ==> this works fine!

So I do have a workaround with solution c), but still I'd like to learn why the path element is doubled only in the first portion of the url, and only for image resources.

EDIT:
tried two more things:
d) pulled the image control outside my repeat then added a fixed (and valid) filename to the calculated url ==> same (bad) result as above

e) calculated the entire url portion only except the image file name beforePageLoad and stored that in a viewScope var ==> this is the weirdest result: outside the image viewscope contains the correct path info, but inside I see the same bad result as above. So it appears that inside the image the viewScope variable is altered in parts???

This is so weird that I feel I must have made a very simple and stupid error here, but what could that be?

役に立ちましたか?

解決 2

Alright, it is as I feared: I had not taken into account that a relative url defined for an image control is automatically prefixed with /dbpath/dbfile.nsf/.

That's why that part always appeared twice no matter how I calculated my own url. It would have worked if I had used absolute urls (http://server/path/dbfile.nsf/...)

So instead the calculated url has to be built like that:

var unid=context.getUrlParameter('documentId');
var p=facesContext.getExternalContext().getRequestContextPath();
return '/xsp/.ibmmodres/domino/OpenAttachment' + p + '/' + 
         unid + '/rtBodyFld/' + imgEntry;

他のヒント

Are you looking for how to calculate attachment URLs? Try this:

function getAttachmentURL(docID:java.lang.String, attachmentName:java.lang.String) {
    var base = getBaseURL();
    var middle = "/xsp/.ibmmodres/domino/OpenAttachment";
    if (base.substr(0,4) == "/xsp") {
        middle += base.substr(4);
    } else {
        middle += base;
    }
    var result = base + middle + "/" + docID + "/$File/" + attachmentName + "?Open";
    return result;
}

function getBaseURL() {
    var curURL = context.getUrl();
    var curAdr = curURL.getAddress();
    var rel = curURL.getSiteRelativeAddress(context);
    var step1 = curAdr.substr(0,curAdr.indexOf(rel));

    // Now cut off the http
    var step2 = step1.substr(step1.indexOf("//")+2);
    var result = step2.substr(step2.indexOf("/"));
    return result;   
   }

Hope that helps!

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top