Convert currentDocumentIncomingRelations into DocumentModel

Hello,

I've created a new type of document in Studio to store a set of pictures. To store these pictures I simply create relations between my documents and the pictures. I'd like to display the thumbnails of the pictures referenced but I don't know how to pass the variable.

Here's what I tried :

<h:dataTable var="statement"
    value="#{currentDocumentIncomingRelations}"
    styleClass="dataOutput"
    rowClasses="dataRowEven, dataRowOdd"
    columnClasses="relationPredicateColumn, relationObjectColumn, relationCommentColumn, relationCommentColumn, relationCommentColumn, relationActionsColumn">

    <h:column>
        <f:facet name="thumbnail">
            <h:outputText value="image" />
        </f:facet>
        <h:graphicImage
            value="#{nxd:fileUrl('downloadPicture', statement , 'Thumbnail:content', currentDocument.dublincore.modified)}" />
    </h:column>

Of course I get an error

Cannot convert org.nuxeo.ecm.platform.relations.web.StatementInfoImpl@a23ec4 of type class org.nuxeo.ecm.platform.relations.web.StatementInfoImpl to interface org.nuxeo.ecm.core.api.DocumentModel

Do you know how I could display the thumbnails of the pictures relations ?

Thank you

Fabrice

0 votes

2 answers

2000 views

ANSWER



The “statement” variable represents the relation. As you're displaying incoming relations, you probably want to use the statement subject instead of its object (that should be a representation of the current document). So you can try something like:

<h:graphicImage value="#{nxd:fileUrl('downloadPicture', statement.subjectInfo.documentModel, 'Thumbnail:content', 'image title here')}" />

Be careful if you also display outgoing relations: the statement object might not represent a document (as relations can also point to a literal, or an URI that does not represent a document). There is API on the node to check for that, there is also another API to check that the document can be accessed by the current user.

Also note that the JSF function nxd:fileUrl is waiting for the image title as a last argument, so using a date with expression currentDocument.dc.modified is not a good idea.

Taking example on default templates displaying relations might help, see https://github.com/nuxeo/nuxeo-features/blob/release-5.5/nuxeo-platform-relations/nuxeo-platform-relations-web/src/main/resources/web/nuxeo.war/incl/tabs/document_relations.xhtml and also https://github.com/nuxeo/nuxeo-features/blob/release-5.5/nuxeo-platform-relations/nuxeo-platform-relations-web/src/main/resources/web/nuxeo.war/relation_node_template.xhtml

1 votes



This works fine.

Thank you very much for your answer.

0 votes