Class DropDownListUtils


  • public class DropDownListUtils
    extends Object
    Provides a utility class for creating Composer Drop Down List values.

    Composer DD List Example

    This Groovy example writes creates a Composer Drop Down (DD) list value and writes a schemaSeed XML Document for form prefill.

     import com.avoka.component.xml.XmlDoc
     import com.avoka.component.xml.DropDownListUtils
    
     def shiftDoc = new XmlDoc(shiftXml)
     def shiftList = DropDownListUtils.createDDListString(xmlDoc, "//shift", "shift_id", "shift_name")
    
     def xmlDoc = new XmlDoc(schemaSeed)
     xmlDoc.setText('/AvokaSmartForm/Timesheet/ShiftOptions', shiftList) 

    Composer Cascading DD List Example

    This Groovy example writes creates a Composer Cascading Drop Down (DD) List value and writes a schemaSeed XML Document for form prefill.

     import com.avoka.component.xml.XmlDoc
     import com.avoka.component.xml.DropDownListUtils
    
     def addressCSV = ..
     def addressXmlDoc = DropDownListUtils.createCascadingDropdownXml(addressesCSV)
     def countryList = addressXmlDoc.getNodeList("//root/country[@value='United States of America']")
    
     def xmlDoc = new XmlDoc(schemaSeed)
     xmlDoc.addNodeList("/AvokaSmartForm/country-list", countyList) 
    Since:
    3.5.0
    See Also:
    XmlDoc
    • Constructor Detail

      • DropDownListUtils

        public DropDownListUtils()
    • Method Detail

      • createDDListString

        public static String createDDListString​(XmlDoc xmlDoc,
                                                String xpath,
                                                String valueElm,
                                                String labelElm)
        Return a Composer Drop Down (DD) List formatted string, e.g "M|Male,F|Female,O|Other".
         def shiftDoc = new com.avoka.core.groovy.XmlDoc(shiftXml)
         def shiftList = shiftDoc.toDDListString('//shift', 'shift_id', 'shift_name')
        
         def xmlDoc = new com.avoka.core.groovy.XmlDoc(schemaSeed)
         xmlDoc.setText('/AvokaSmartForm/Timesheet/ShiftOptions', shiftList) 
        Parameters:
        xmlDoc - the XmlDoc instance containing the source XML
        xpath - the XPath to the list of XML elements to process
        valueElm - the name of the child element to use as the list item value
        labelElm - the name of the child element to use as the list item label
        Returns:
        the Drop Down (DD) List formatted string
      • createCascadingDropdownXml

        public static XmlDoc createCascadingDropdownXml​(String csvSource)
                                                 throws IOException,
                                                        ParserConfigurationException
        Create an XmlDoc object from the given CSV describing data for a cascading dropdown. Note that the columns are to be ordered from outermost to innermost dropdown, and headers must be provided. The header names need to match the element names in the XML. For each dropdown level, either a single column containing the values can be provided, or two columns containing the values and labels can be used. In the latter case, the header names must end in .value and .name, respectively.
        Parameters:
        csvSource - the CSV text
        Returns:
        the XmlDoc object
        Throws:
        IOException - if an IO error occurs
        ParserConfigurationException - if an XML parsing error occurs