Hi Derek,

As far as I can remember you just need to set the multi-value widget value to a simple array, and I don't think you should initialise the array with 10 values if you are only setting 1.

Something like this maybe:

var values = ["option1", "option2"]; // these are the values to pre- select
fwidget.setValue(values);

Cheers,

Robin



On 3 Jun 2008, at 08:13, Derek Hohls wrote:

I am reposting in the hope that someone can find a
few moments to look at this - I'm sure I am missing
something simple, but cannot see what it is...

On 2008/05/21 at 12:55, in message <[EMAIL PROTECTED]>, "Derek Hohls" <[EMAIL PROTECTED]> wrote:
I have a dynamically created form which I then access from flowscript

  var qit = newForm.getWidget().getChildren();
   if (qit != null) {
   while ( qit.hasNext() ) {
       fwidget = qit.next() ;
      ...

to get each widget.  I now need to pre-select some values for
all of the multi-value widgets.  (Note that the widget below has a
datatype of string).

Approach 1 is what I *think* is correct; Approach 2 I know is
wrong but it does confirm that the widget I am accessing is
a MultiValueField.

Any ideas as to how to make this work properly?

Thanks
Derek

(Side note:  if I omit this step, the rest of the form displays
as expected, and values for other widget types are set OK.)


Approach 1:

var values = java.lang.reflect.Array.newInstance(java.lang.String, 10);
values[0] = "Option 1";
fwidget.setValue(values); //NB also tried fwidget.setValues(values);

Result 1:

java.lang.NullPointerException
at org.apache.cocoon.forms.formmodel.MultiValueField.setValues (MultiValueField.java:190) at org.apache.cocoon.forms.formmodel.MultiValueField.setValue (MultiValueField.java:180)
...


Approach 2:

fwidget.setValue("Option 1");

Result 2:

java.lang.RuntimeException: Cannot set value of field "q-25--6" with an object of type java.lang.String at org.apache.cocoon.forms.formmodel.MultiValueField.setValue (MultiValueField.java:182)
...




--
This message is subject to the CSIR's copyright terms and conditions, e-mail legal notice, and implemented Open Document Format (ODF) standard. The full disclaimer details can be found at http://www.csir.co.za/ disclaimer.html.

This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. MailScanner thanks Transtec Computers for their support.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



--
This message is subject to the CSIR's copyright terms and conditions, e-mail legal notice, and implemented Open Document Format (ODF) standard. The full disclaimer details can be found at http://www.csir.co.za/ disclaimer.html.

This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. MailScanner thanks Transtec Computers for their support.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to