2

I have this computed text bound to a the body field using EL

 <xp:text escape="true" id="computedField1" value="#{doc.Body}"></xp:text>

Now I need to store this computedField in a Custom Control and send in the doc? What property definition should I use, and how do I reference the compositeData to the Body field in the cc

thanks

Thomas

Thomas Adrian
  • 3,543
  • 6
  • 32
  • 62

1 Answers1

8

Create a custom property on your Custom Control called dataSource and set the type to com.ibm.xsp.model.DataSource

Create a second custom property called computedFieldName and set it's type to string

In the computed field in the custom control set the value like

value="#{compositeData.dataSource[compositeData.computedFieldName]}"

When using the custom control just set the custom properties like:

computedFieldName="Body" dataSource="#{doc}"

Rob Mason
  • 1,385
  • 10
  • 23
  • I might be missing something. Why not skip the property definition entirely and in the CC and just continue to bind the computed field to the named datasource defined on the XPage, simply #{doc.Body}. – Peter Della-Nebbia Sep 01 '17 at 12:00
  • @PaulDella-Nebbia Doing it the way I've outlined means the custom control is more reusable. It can handle fields with different names and different data sources too. There is a way to write this to allow the custom control to accept anything, not just a document as the data source e.g. a bean. But the details of that method escape me at the minute. – Rob Mason Sep 01 '17 at 12:38
  • My example was simplified for Stack overflow, The real scenario contain file upload control used in many different XPages that have different data source names – Thomas Adrian Sep 01 '17 at 12:56
  • I've found the dynamic binding thing I'd mentioned in my earlier comment. See Stephan Wissel's answer for an even more dynamic way of binding data: http://stackoverflow.com/a/19309383/4193769 – Rob Mason Sep 01 '17 at 15:21
  • Well that make perfect sense then. – Peter Della-Nebbia Sep 05 '17 at 08:40