Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

 

Tip
titleHelpful Tip

Data sources and formatters are fully extensible to allow you to add new functionality. You can define your own dataSource and formatter extension classes.

<formatter class="com.acme.formatters.PhoneNumberFormatter" id="digitFormatter"/>
<dataSource class="com.acme.datasources.CsvFile" id="cvsDS"/>

In addition, you can package extensions as plug-ins, allowing you to declare alternative tag names.

Custom formatter and dataSource objects are discussed below. Let's first make note of what any formatter and dataSource does.

 

Data Sources

A dataSource's main responsibilities include:

...

help See the developer guide for more - Data Sources

The out-of-box data framework provides the following dataSources:

...

help See the developer guide for more - Data source Tags

 

Tip
titleHelpful Tip

By supplying a Managed Client Object (MCO) method as the source attribute, you can cache data by retrieving and storing it in a data cache (Hashtable), then returning the existing data rather than making another request to the server for the same data. The method below will cache an XML document from the salesforce.jsp page mentioned in the previous Helpful Tip.

 /**
  * Get the result from the server
  * @return
  */
  public Document getResults(String query, boolean bRefresh){
     Document  document = null;
  
     try {
        //Check to see if the query has already been cached, if it has
        //and the a refresh is not desired return the cached document.

        if (bRefresh == false){
           document = (Document)_documentQueryHashTable.get(query);
           if (document != null) return document;
        }
   
        HttpResponse response = getSession().getNetService().retrieve("query.jsp?query="+URLEncoder.encode(query));   
        document = ParserFactory.getParser().parseXml(new String(response.getContent()));
   _    documentQueryHashTable.put(query, document);
     } catch (NetServiceException netServiceException) {
        netServiceException.printStackTrace();
     } catch (ParserException parserException) {
        parserException.printStackTrace();
     }
     return document;
}

A documentDataSource can then call this method through:

 <data:documentDataSource
          id="resultSet"
        
          source="mco://salesForceMco.getResults('select id, firstname, lastname, rating, company, email from lead', false)"
          xmlns:data="http://openxal.org/core/data"/>

Tip
titleStudio Tip

Using Nexaweb Studio, you can easily create data sources by dragging and dropping XML files into its visual editor. Once data sources are supplied they will be accessible from wizards and from outline views of other XML UI files.

 

...

help See the developer guide for more - Bindings

Iterators

Iterators provide functionality for creating complex UI structures such as tables, lists, and so forth.  By nesting iterators, you can create even more complex structures such as trees and tree tables.  An Iterator replicates its children for each item in a set of data.  The dataSource and select attributes of the iterator tag define the set of data. The following example shows an iterator creating a complex UI structure of panels and buttons within a scrollPane.

...

help See the developer guide for more - Formatter Tags

Custom code

First, create a class that extends the AbstractJavaFormatter class. This class implements the Formatter interface and handles initialization. Then, implement the class' formatObject method; this method performs the actual formatting of the supplied object into a new one.

...

To try this code, create an XML file called data.xml that has <data phoneNumber="1234567890"/> as its content.

 

Tip
titleHelpful Tip

Since the incoming object can be of many possible types, you will need to use the type conversion service supplied to change the incoming object of the formatObject method into a type with which your code can easily work. The interface TypeConversionService encapsulates functionality for changing types.

Convert the incoming object instance by calling ClientSession.getTypeConversionService.convertToString(incomingObject).

 

Putting it all together

Using Nexaweb data framework along with Nexaweb Studio's functionality can greatly reduce the amount of code needed to integrate your application with any back end data sources. Look for ways to effectively use one way data binding within applications. For example, you can implement one way data binding of shared XML documents. You can modify shared XML documents from the server, thus automatically synchronizing changes and triggering UI updates without the need to write any client side code.

...