You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Сергей Алешин <fk...@gmail.com> on 2011/09/18 14:06:21 UTC
how to set initial value in MultiValueField widjet
Hello everyone!
I use Cocoon 2.2.
Please tell me how to set initial value in MultiValueField widjet?
--
Serge Aleshin
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
RE: how to set initial value in MultiValueField widjet
Posted by Robby Pelssers <Ro...@nxp.com>.
Hi Serge,
Nice to hear you managed to resolve your own question. I see you are actually using an XML document as your datasource. I never had this particular use case so I never used the binding functionality.
Thx for sharing your solution. I'm sure others will benefit from this.
Robby
From: Serge Aleshin [mailto:fktiby@gmail.com]
Sent: Tuesday, September 20, 2011 12:40 PM
To: users@cocoon.apache.org
Subject: Re: how to set initial value in MultiValueField widjet
Hello Robby!
I solved my problem.
In form defenition file:
<fd:multivaluefield id="mm">
<fd:label>Name:</fd:label>
<fd:datatype base="string"/>
<fd:selection-list>
<fd:item value="IVAN"/>
<fd:item value="PETR"/>
<fd:item value="LIDA"/>
<fd:item value="GEORG"/>
<fd:item value="FEDYA"/>
</fd:selection-list>
</fd:multivaluefield>
In binding file:
<fb:context path="data" xmlns:fb="http://apache.org/cocoon/forms/1.0#binding"<http://apache.org/cocoon/forms/1.0#binding>>
<fb:multi-value id="mm" parent-path="." row-path="mm" />
</fb:context>
In data for binding file:
<data>
<mm>IVAN</mm>
<mm>LIDA</mm>
</data>
In flowscript file:
function loadDocument(uri) {
var parser = null;
var source = null;
var resolver = null;
try {
parser = cocoon.getComponent(Packages.org.apache.excalibur.xml.dom.DOMParser.ROLE);
resolver = cocoon.getComponent(Packages.org.apache.cocoon.environment.SourceResolver.ROLE);
source = resolver.resolveURI(uri);
var is = new Packages.org.xml.sax.InputSource(source.getInputStream());
is.setSystemId(source.getURI());
return parser.parseDocument(is);
} finally {
if (source != null)
resolver.release(source);
cocoon.releaseComponent(parser);
cocoon.releaseComponent(resolver);
}
}
cocoon.load("servlet:forms:/resource/internal/flow/javascript/Form.js");
function registration() {
var form = new Form("cocoon://form.def.xml");
form.createBinding("cocoon://binding.xml");
var document = loadDocument("cocoon://dataForMM.xml");
form.load(document);
form.showForm("registration-display-pipeline");
var viewData = { "username" : form.getChild("mm").getValue()[0] }
cocoon.sendPage("registration-success-pipeline", viewData);
}
That is all. The row with value "LIDA" and "IVAN" are "selected".
Thanks for help.
Hi Serge,
I don't think it's possible to accomplish your requirements directly in the form definition but it should be straightforward if you do it programmatically.
Since it's a multivalue-widget you can set the Options (values to pick from) by using void setSelectionList<http://cocoon.apache.org/2.1/apidocs/org/apache/cocoon/forms/formmodel/MultiValueField.html#setSelectionList%28org.apache.cocoon.forms.datatype.SelectionList%29>(SelectionList<http://cocoon.apache.org/2.1/apidocs/org/apache/cocoon/forms/datatype/SelectionList.html> selectionList)
If you want to set the default selected values then you have to use the void setValues<http://cocoon.apache.org/2.1/apidocs/org/apache/cocoon/forms/formmodel/MultiValueField.html#setValues%28java.lang.Object[]%29>(Object<http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Object.html>[] values)
I am not sure if have a very simple example at hand. But if you still can't get things working programmatically... let me know.
Robby
Re: how to set initial value in MultiValueField widjet
Posted by Serge Aleshin <fk...@gmail.com>.
Hello Robby!
I solved my problem.
In form defenition file:
<fd:multivaluefield id="mm">
<fd:label>Name:</fd:label>
<fd:datatype base="string"/>
<fd:selection-list>
<fd:item value="IVAN"/>
<fd:item value="PETR"/>
<fd:item value="LIDA"/>
<fd:item value="GEORG"/>
<fd:item value="FEDYA"/>
</fd:selection-list>
</fd:multivaluefield>
In binding file:
<fb:context path="data"
xmlns:fb="http://apache.org/cocoon/forms/1.0#binding">
<fb:multi-value id="mm" parent-path="." row-path="mm" />
</fb:context>
In data for binding file:
<data>
<mm>IVAN</mm>
<mm>LIDA</mm>
</data>
In flowscript file:
function loadDocument(uri) {
var parser = null;
var source = null;
var resolver = null;
try {
parser =
cocoon.getComponent(Packages.org.apache.excalibur.xml.dom.DOMParser.ROLE);
resolver =
cocoon.getComponent(Packages.org.apache.cocoon.environment.SourceResolver.ROLE);
source = resolver.resolveURI(uri);
var is = new
Packages.org.xml.sax.InputSource(source.getInputStream());
is.setSystemId(source.getURI());
return parser.parseDocument(is);
} finally {
if (source != null)
resolver.release(source);
cocoon.releaseComponent(parser);
cocoon.releaseComponent(resolver);
}
}
cocoon.load("servlet:forms:/resource/internal/flow/javascript/Form.js");
function registration() {
var form = new Form("cocoon://form.def.xml");
form.createBinding("cocoon://binding.xml");
var document = loadDocument("cocoon://dataForMM.xml");
form.load(document);
form.showForm("registration-display-pipeline");
var viewData = { "username" : form.getChild("mm").getValue()[0] }
cocoon.sendPage("registration-success-pipeline", viewData);
}
That is all. The row with value "LIDA" and "IVAN" are "selected".
Thanks for help.
> Hi Serge,
>
> I don't think it's possible to accomplish your requirements directly
> in the form definition but it should be straightforward if you do it
> programmatically.
>
> Since it's a multivalue-widget you can set the Options (values to
> pick from) by using |void| |*setSelectionList
> <http://cocoon.apache.org/2.1/apidocs/org/apache/cocoon/forms/formmodel/MultiValueField.html#setSelectionList%28org.apache.cocoon.forms.datatype.SelectionList%29>*||(SelectionList
> <http://cocoon.apache.org/2.1/apidocs/org/apache/cocoon/forms/datatype/SelectionList.html> selectionList)|
>
>
> If you want to set the default selected values then you have to use
> the | void| |*setValues
> <http://cocoon.apache.org/2.1/apidocs/org/apache/cocoon/forms/formmodel/MultiValueField.html#setValues%28java.lang.Object[]%29>*||(Object
> <http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Object.html>[] values)|
>
> ||
>
> |I am not sure if have a very simple example at hand. But if you still
> can't get things working programmatically... let me know.|
>
> ||
>
> |Robby|
>
RE: how to set initial value in MultiValueField widjet
Posted by Robby Pelssers <Ro...@nxp.com>.
Hi Serge,
I don't think it's possible to accomplish your requirements directly in the form definition but it should be straightforward if you do it programmatically.
Since it's a multivalue-widget you can set the Options (values to pick from) by using void setSelectionList<http://cocoon.apache.org/2.1/apidocs/org/apache/cocoon/forms/formmodel/MultiValueField.html#setSelectionList%28org.apache.cocoon.forms.datatype.SelectionList%29>(SelectionList<http://cocoon.apache.org/2.1/apidocs/org/apache/cocoon/forms/datatype/SelectionList.html> selectionList)
If you want to set the default selected values then you have to use the void setValues<http://cocoon.apache.org/2.1/apidocs/org/apache/cocoon/forms/formmodel/MultiValueField.html#setValues%28java.lang.Object[]%29>(Object<http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Object.html>[] values)
I am not sure if have a very simple example at hand. But if you still can't get things working programmatically... let me know.
Robby
From: Serge Aleshin [mailto:fktiby@gmail.com]
Sent: Monday, September 19, 2011 3:29 PM
To: users@cocoon.apache.org
Subject: Re: how to set initial value in MultiValueField widjet
Hello Robby!
Sorry for my English.
I mean, how to mark some values from values presented as "selected"?
For fd:field I use fd:initial-value. But I don't know how to set initial-value for fd:multivaluefield.
2011/9/19 Robby Pelssers <Ro...@nxp.com>>
Hi Serge,
You can still use the 2.1.10 API for checking how cocoon forms works.
http://cocoon.apache.org/2.1/apidocs/
Check org.apache.cocoon.forms.formmodel.MultiValueField
Normal way is to first get hold of the widget in question using flowscript.
Then you can invoke either the
-setValue(Object value)
-setValues(Object[] values)
Some sample code for your flowscript:
cocoon.load("servlet:forms:/resource/internal/flow/javascript/Form.js");
var formdefinition = new Form("cocoon://pattern_pointing_to_your_formdefinition");
var formWidget = formdefinition.form;
//now to lookup a widget you do sth like this
var mymultivaluewidget = formWidget.lookupWidget("replace_this_by_widget_id");
mymultivaluewidget.setValues(somevalues);
Hope this helps,
Robby Pelssers
-----Original Message-----
From: Сергей Алешин [mailto:fktiby@gmail.com<ma...@gmail.com>]
Sent: Sunday, September 18, 2011 2:06 PM
To: users@cocoon.apache.org<ma...@cocoon.apache.org>
Subject: how to set initial value in MultiValueField widjet
Hello everyone!
I use Cocoon 2.2.
Please tell me how to set initial value in MultiValueField widjet?
--
Serge Aleshin
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org<ma...@cocoon.apache.org>
For additional commands, e-mail: users-help@cocoon.apache.org<ma...@cocoon.apache.org>
--
Искренне ваш А.С.
Re: how to set initial value in MultiValueField widjet
Posted by Serge Aleshin <fk...@gmail.com>.
Hello Robby!
Sorry for my English.
I mean, how to mark some values from values presented as "selected"?
For fd:field I use fd:initial-value. But I don't know how to set
initial-value for fd:multivaluefield.
2011/9/19 Robby Pelssers <Ro...@nxp.com>
> Hi Serge,
>
> You can still use the 2.1.10 API for checking how cocoon forms works.
>
> http://cocoon.apache.org/2.1/apidocs/
>
> Check org.apache.cocoon.forms.formmodel.MultiValueField
>
>
> Normal way is to first get hold of the widget in question using flowscript.
>
> Then you can invoke either the
> -setValue(Object value)
> -setValues(Object[] values)
>
>
> Some sample code for your flowscript:
>
> cocoon.load("servlet:forms:/resource/internal/flow/javascript/Form.js");
> var formdefinition = new
> Form("cocoon://pattern_pointing_to_your_formdefinition");
> var formWidget = formdefinition.form;
>
> //now to lookup a widget you do sth like this
> var mymultivaluewidget =
> formWidget.lookupWidget("replace_this_by_widget_id");
>
> mymultivaluewidget.setValues(somevalues);
>
> Hope this helps,
> Robby Pelssers
>
> -----Original Message-----
> From: Сергей Алешин [mailto:fktiby@gmail.com]
> Sent: Sunday, September 18, 2011 2:06 PM
> To: users@cocoon.apache.org
> Subject: how to set initial value in MultiValueField widjet
>
> Hello everyone!
> I use Cocoon 2.2.
> Please tell me how to set initial value in MultiValueField widjet?
> --
> Serge Aleshin
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
>
>
--
Искренне ваш А.С.
RE: how to set initial value in MultiValueField widjet
Posted by Robby Pelssers <Ro...@nxp.com>.
Hi Serge,
You can still use the 2.1.10 API for checking how cocoon forms works.
http://cocoon.apache.org/2.1/apidocs/
Check org.apache.cocoon.forms.formmodel.MultiValueField
Normal way is to first get hold of the widget in question using flowscript.
Then you can invoke either the
-setValue(Object value)
-setValues(Object[] values)
Some sample code for your flowscript:
cocoon.load("servlet:forms:/resource/internal/flow/javascript/Form.js");
var formdefinition = new Form("cocoon://pattern_pointing_to_your_formdefinition");
var formWidget = formdefinition.form;
//now to lookup a widget you do sth like this
var mymultivaluewidget = formWidget.lookupWidget("replace_this_by_widget_id");
mymultivaluewidget.setValues(somevalues);
Hope this helps,
Robby Pelssers
-----Original Message-----
From: Сергей Алешин [mailto:fktiby@gmail.com]
Sent: Sunday, September 18, 2011 2:06 PM
To: users@cocoon.apache.org
Subject: how to set initial value in MultiValueField widjet
Hello everyone!
I use Cocoon 2.2.
Please tell me how to set initial value in MultiValueField widjet?
--
Serge Aleshin
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org