Widgets: How to retrieve a property on a pointed object?

Hello all,

May be my question has an obvious answer I did overlooked:

In Case Management model CaseLink object points the owner Case document by storing it's Id (caseDocumentId attribute). In the listing widget of case links in Inbox mailbox, I'd like to retrieve and display a property coming from the owner Case.

Can I achieve this in XML using the Id of the Case? Or do I need code a custom widget for that?

Thanks in advance.

0 votes

2 answers

1697 views

ANSWER



Hi,

You'll need some logic to retrieve the document from its id (taking example on the document suggestion widget templates for instance) and then you'll be able to retrieve the property.

From 5.6, it's possible to use EL expressions in “field” XML elements, so the answer is yes. If you're using a lower version, you'll probably have to use a custom widget template.

1 votes



Hi, Thanks for the quick answer. Yes, I'm using 5.6. Could you please give me a sample or refer to the doc?
08/17/2012

On second thought, it would be wiser to define a widget template anyway, so that you can handle use cases where target document is not found, undefined, etc…

Anyway you can use something like: <pre> <code> <field>#{docSuggestionActions.getDocumentWithId(layoutValue.theSchema.theFieldHoldingTheId).theOtherSchema.thePropToDisplay}</field> </code> </pre>

Layout doc is at http://doc.nuxeo.com/x/OoAO but i still need to add a chapter about field bindings…

08/17/2012

thanks, that's exactly what I need. However, it doesn't seem to be working, got nothing displayed. How can I debug such a call (docSuggestionActions.getDocumentWithI() )? Thanks.
08/17/2012

how can I learn moe about the syntax of EL expressions? haven't found much in the Nuxeo EP doc. Is that the part you are still to add?
08/17/2012

if you're not acquainted with standard EL, reading standard doc is a start.

we're actually using jboss EL (that adds features to call methods with parameters) but that's pretty straight-forward once you know EL.

other than that, we just defined a custom EL resolver for documents so that we can use a syntax #{doc.schema.field} to easily retrieve property values from documents.

the doc i need to write will explain how information given in the "field" tag is transformed into an EL expression. if you're already using an EL expresion as value, there will be no transformation.

08/20/2012

OK for the EL syntax, thanks. It's rather the layout context variables use like layoutValue, data, document etc.. that is not clear for me.
08/20/2012


Thanks Anahide for your support and the detailed answers. However, I still cannot make it work:

Here is my layout contrib:

  <extension target="org.nuxeo.ecm.platform.forms.layout.WebLayoutManager" point="layouts">
    <layout name="cm_inbox_caselink" override="true">
      <templates>
        <template mode="any">
          /layouts/layout_listing_ajax_template.xhtml
        </template>
      </templates>
      <properties mode="any">
        <property name="showListingHeader">true</property>
        <property name="showRowEvenOddClass">true</property>
      </properties>
      <columns>
        <column>
          <properties mode="any">
            <property name="useFirstWidgetLabelAsColumnHeader">true</property>
          </properties>
          <widget>listing_reference</widget>
        </column>
    ...

Here is the widget definition:

<widget name="listing_reference" type="text">
          <labels>
            <label mode="any">label.casemanagement.document.reference</label>
          </labels>
          <translated>true</translated>
          <fields> 
            <field>data.cslk.caseDocumentId</field> 
            <field>#{docSuggestionActions.getDocumentWithId(data.cslk.caseDocumentId).case.reference}</field>
          </fields>
        </widget>

I put here both

case.reference is a new property I've added overriding case schema, but I've also tested with dc.title, no difference. I've made a handful of tests, tested to retrieve the pointed CaseItem object instead of Case etc.. There is no error / java exception raised but the result is empty.

Please see what I'm doing wrong.

0 votes