Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Does ValueXPath support XPath functions

    I want to concat two fields from my RestDataSource for the calendar title.

    Since calendars seem to have no equivalent to ListGridField, I guess the only option is to combine it already in the DataSourceField.

    I try to achieve this by using the XPath function concat:
    Code:
            RestDataSource dataSource = new RestDataSource();
            dataSource.setFetchDataURL(Constants.REST_API + link);
    	dataSource.setRecordXPath("//record");
    	dataSource.setDataFormat(DSDataFormat.XML);
    
    	DataSourceTextField textField = new DataSourceTextField("text");
    	
    	// Register name for xpath functions
    	XmlNamespaces namespaces = new XmlNamespaces();
    	namespaces.addNamespace("fn","http://www.w3.org/2005/xpath-functions");
    	dataSource.setXmlNamespaces(namespaces);
    
    	// Use xpath function
    	textField.setValueXPath("fn:concat(field1,field2)");
    But the result is always the string "undefined".

    Can I use at all XPath functions in ValueXPath? If so: How do I register the functions?
    Last edited by anja_burrmann; 12 Oct 2010, 13:47.

    #2
    Use transformResponse or a FieldValueExtractor to add custom logic to how values are derived from the response.

    Comment


      #3
      Thanks a lot for the hint, Isomorphic!

      In case somebody stumbles over the same issue:
      Code:
      DataSourceTextField textField = new DataSourceTextField("text");
      textField.setFieldValueExtractor(new FieldValueExtractor() {
      	@Override
      	public Object execute(Object record, Object value,
      			DataSourceField field, String fieldName) {
      		String field1 = XMLTools.selectString(record, "field1");
      		String field2 = XMLTools.selectString(record, "field2");
      		return field1 + field2;
      	}
      });

      Comment

      Working...
      X