cancel
Showing results for 
Search instead for 
Did you mean: 

Convert currentDocumentIncomingRelations into DocumentModel

fabrice_
Champ on-the-rise
Champ on-the-rise

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

1 ACCEPTED ANSWER

Anahide_Tchertc
Elite Collaborator
Elite Collaborator

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-rel... and also https://github.com/nuxeo/nuxeo-features/blob/release-5.5/nuxeo-platform-relations/nuxeo-platform-rel...

View answer in original post

2 REPLIES 2

Anahide_Tchertc
Elite Collaborator
Elite Collaborator

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-rel... and also https://github.com/nuxeo/nuxeo-features/blob/release-5.5/nuxeo-platform-relations/nuxeo-platform-rel...

fabrice_
Champ on-the-rise
Champ on-the-rise

This works fine.

Thank you very much for your answer.

Getting started

Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.