cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Derek Hohls" <DHo...@csir.co.za>
Subject Re: [REPOST] Setting multi-value widget values for dynamically createdforms
Date Wed, 04 Jun 2008 06:58:50 GMT
Robin

Thanks!  This worked - with the modification that you only need:

var values = new java.util.ArrayList();

Derek

>>> On 2008/06/03 at 03:57, in message <BB799591-CA3E-48D3-81A4-32E320217054@robinwyles.com>,
Robin Wyles <rob@robinwyles.com> wrote:
I'm not sure if it's the best way, but off the top of my head...

var values = new Packages.com.java.util.ArrayList();
values.add("option 1");
values.add("option 2");
values.add(someMethodToGetAString());
values.add(someOtherMethodToGetAString());
....
fwidget.setValue(values.toArray());


Basically, the trick is to pass a simple array to the multi-value  
widget containing only the values you need to set...

Cheers,

Robin


On 3 Jun 2008, at 14:48, Derek Hohls wrote:

> Robin
>
> How would you create the array programmtically
> ie. values array needs to be populated via data
> values sourced elsewhere ( and typically available
> in a string variable) rather than from a static list.
>
> Thanks
> Derek
>
>>>> On 2008/06/03 at 03:32, in message <F6853221-59B6-4F99- 
>>>> BED0-8B9712C8A188@robinwyles.com>, Robin Wyles  
>>>> <rob@robinwyles.com> wrote:
> 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
>>>>> <48341BB8.5CE9.00D4.0@csir.co.za>, "Derek Hohls"
>>>>> <DHohls@csir.co.za> 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: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Mime
View raw message