Try something similar to this:


var objRequestForm = flowdata.getObject('start/request_form');
var fields = objRequestForm.get(0).getChildNodes();
for ( var i=0; i<fields.getLength(); i++)
{
try
{
var field = fields.item(i);
var value = String(field.getTextContent());
var key = String(field.getNodeName());
Packages.java.lang.System.out.println( key + ": " + value );
}
catch( e )
{
Packages.java.lang.System.out.println( i + " - " field + ": " + e );
}
}


Wolfgang






On 09.07.2012 00:36, nathanshaw wrote:
>
> Is it possible to loop through an entire form using flowdata.getObject?
> I am storing just about every bit of data from the form fields and right
> now if I add a new field, I have to also update my mapping activity to
> parse it, so I was hoping to make it a bit more dynamic so that I can
> add a new form field and my mapping activity will automatically be able
> to parse it. I used the expression builder to get the entire form into
> an object and I can begin looping through it as follows:
>
> Code:
> --------------------
> var objRequestForm = flowdata.getObject('start/request_form');
> for (var i = 0; i< objRequestForm.size(); i++) {
> Packages.java.lang.System.out.println('['+i+']: '+objRequestForm.get(i));
> Packages.java.lang.System.out.println("length: " + objRequestForm.get(i).length);
> }
> --------------------
>
>
> Here's the output in the jboss log:
>
> Code:
> --------------------
> 18:08:33,822 INFO [STDOUT] [0]: [request_form: null]
> 18:08:33,822 INFO [STDOUT] length: 61
>
> --------------------
>
>
> It seems like I should be able to get access to each of those nodes,
> but I can't figure out how. I tried a second loop, treating each
> element in two different ways, as follows:
>
> Code:
> --------------------
> var objRequestForm = flowdata.getObject('start/request_form');
> for (var i = 0; i< objRequestForm.size(); i++) {
> Packages.java.lang.System.out.println('['+i+']: '+objRequestForm.get(i));
> Packages.java.lang.System.out.println("length: " + objRequestForm.get(i).length);
>
> for (var j=0; j< objRequestForm.get(i).length; j++) {
> try { Packages.java.lang.System.out.println('['+j+']: '+objRequestForm.get(i).get(j)); } catch (err) { Packages.java.lang.System.out.println("Error using .get("+j+"): " + err) };
> try { Packages.java.lang.System.out.println('['+j+']: '+objRequestForm.get(i)[j]); } catch (err) { Packages.java.lang.System.out.println("Error using ["+j+"]: " + err) };
> }
> }
> --------------------
>
>
> Here is the jboss log output... doesn't like either.
>
> Code:
> --------------------
> 18:18:14,718 INFO [STDOUT] [0]: [request_form: null]
> 18:18:14,718 INFO [STDOUT] length: 61
> 18:18:14,719 INFO [STDOUT] Error using .get(0): TypeError: get is not a function.
> 18:18:14,720 INFO [STDOUT] Error using [0]: InternalError: Java class "org.apache.xerces.dom.DeferredElementNSImpl" has no public instance field or method named "0". 0 0
> .
> .repeated...
> .
> 18:18:14,823 INFO [STDOUT] Error using .get(60): TypeError: get is not a function.
> 18:18:14,824 INFO [STDOUT] Error using [60]: InternalError: Java class "org.apache.xerces.dom.DeferredElementNSImpl" has no public instance field or method named "60". 0 0
> --------------------
>
>
> Any other thoughts on how I might do this? Thanks in advance!
>
>