Community articlegetXFormsModels method
Added by IBM contributorIBM on July 26, 2013
Rate this article 1 starsRate this article 2 starsRate this article 3 starsRate this article 4 starsRate this article 5 stars

Description

Returns a list of XForms models that are in a form. This is useful for identifying the models in your form before calling a method that uses the modelID parameter, and for keeping track of the models that are contained within a multi-model form.
getXFormsModels can only be used when XForms processing is turned on. You cannot use this method on a form that has been opened using the readForm method with either the XFDL.UFL_SERVER_SPEED_FLAGS flag or the XFDL.UFL_XFORMS_OFF flag. Use the 0 flag or the XFDL.UFL_SERVER_SPEED_FLAGS_WITH_XFORMS flag to keep XForms processing turned on.

Method

   public String[] getXFormsModels() throws UWIException;


Parameters

This method has no parameters.

Returns

An array of Strings. Each String contains the ID of a model that is in the form.

Example

The following example prompts for a form to open. It opens the form and uses getXFormsModels to get a list of the XForms models that are in the form.
import java.io.IOException;
import java.io.InputStream;
import java.io.DataInputStream;
import com.PureEdge.DTK;
import com.PureEdge.IFSSingleton;
import com.PureEdge.error.UWIException;
import com.PureEdge.xfdl.FormNodeP;
import com.PureEdge.StringListHolder;
import com.PureEdge.xfdl.XFDL;
import com.PureEdge.dom.Document;
 
public class testCheckDataValidity {
 
    public static void main(String[] args) {
        try {
        // initialize the API
        DTK.initialize("test_dtk", "1.0.0", "8.0.0");
        DataInputStream in = new DataInputStream(System.in);			
        System.out.println("Enter filename: ");
        String fileName = in.readLine();
 
        // obtain an XFDL object
        XFDL theXFDL = IFSSingleton.getXFDL();
 
        // read in a form with XForms in 'initialize-only' mode (with fully constructed 
        // model but without the UI)
        FormNodeP theForm = theXFDL.readForm(fileName, XFDL.UFL_SERVER_SPEED_FLAGS_WITH_XFORMS);
        
        // obtain the list of model 'names' (ID's)
        String models[] =  theForm.getXFormsModels();
        
        // check & report overall data validity for every model 
        boolean valid = true, modelValid;
        for (int i = 0; i < models.length; i++)
        {
            modelValid = theForm.checkDataValidity(FormNodeP.UFL_STOP_ON_FIRST_INVALID, models[i], null, null); 
            System.out.println("model " + models[i] + " " + (modelValid ? "valid!" : "invalid") );
            valid  = valid && modelValid;
        }
        
        // report form's overall data validity 
        System.out.println("Form data is " + (valid ? "valid!" : "invalid"));
                
        // obtain & report the list of invalid data nodes for a default (first) model ignoring node relevance.
        StringListHolder invalidNodes =  new StringListHolder();
        theForm.checkDataValidity(FormNodeP.UFL_IGNORE_RELEVANCE, null, null, invalidNodes);
        if (invalidNodes.value != null)
        {
            for (int i = 0; i < invalidNodes.value.length; i++)
                System.out.println(invalidNodes.value[i]);
        }
        
        // obtain & report the list of invalid data nodes for a given data sub-tree (here, the 
        // entire 'data0' instance) of the default model
        invalidNodes =  new StringListHolder();
        theForm.checkDataValidity(0, null, "instance('data0')", invalidNodes);
        if (invalidNodes.value != null)
        {
            for (int i = 0; i < invalidNodes.value.length; i++)
                System.out.println(invalidNodes.value[i]);
        }
        
        theForm.destroy();
        System.out.println("Done!");
        return;
        }
            
        catch (Exception e) 
        {
            e.printStackTrace();
        }
            
        finally
        {
        }
 
    }
 
}


Parent topic:
FormNodeP class