You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Nicolas Maisonneuve <n....@gmail.com> on 2005/05/17 22:44:09 UTC

Re: CForm model to POJO with a "natural" binding [RE: was Display a CForm Repeater in JXTemplate]

ok maybe i'm not very clear:

the binding framework is good but useless for simple/natural binding.
Exemple of a form:

<form>
<field name="title"/>
<booleanfield name"field"/>

<repeater name="contacts">
  <field name="name" />
...</repeater>
...
a useful tool/feature would be:

var my bean = form.modelToPojo() 

the bean will have this structure 
bean.title
bean.field
bean.contacts[i].name
etc...

and form.pojoTomodel(bean)
-----------------

It's possible to do this ? if yes how do you this ?

because the form.getModel() is not POJO and when you use it somewhere
outside to the flowscript , we can't use it as easily as in
flowscript, so why not create directly the real object ?

nicolas 






On 5/14/05, nicolas maisonneuve <n....@gmail.com> wrote:
> It doesn't work in JX but works in flowscript because model is not POJO but
> a scriptableWidget.
> Ok ,  so I must manually transform the model in a POJO in the flowscript.. a
> dumb task
> 
> Var Mymodel= new Object();
> Mymodel.simplewidgetID = model.simplewidgetID
> Mymodel.repeaterwidgetID= new Array(model.repeaterwigetID.length);
> For (var i=0; i<i ; i++) {
> Mymodel.repeaterwidgetID[i]=model.repeaterwidgetID[i];
> }
> Etc..
> Ok but is there any way to create/bind a POJO automatically, with reflection
> code or a tool ?
> 
> 
> Nicolas
> 
> > -----Message d'origine-----
> > De: news [mailto:news@sea.gmane.org] De la part de oceatoon
> > Envoyé: samedi 14 mai 2005 13:39
> > À: users@cocoon.apache.org
> > Objet: Re: Display a CForm Repeater in JXTemplate
> >
> > Nicolas Maisonneuve wrote:
> >
> > > In pratice I would like transform the data of the form , so I use JX
> > > as the generator of the pipeline where the data are injected. My first
> > > step is just to display the results of the JX generator.
> > >
> > > But it's really strange that anybody find a simple solution for this
> > > simple problem.
> > > 1 Is there a simple way to access to the data in a repeater in a JX ?
> > > 2- Why in flowscript the access "model.field[0].name"  works but not in
> > JX
> > > ? (it would be interessing to develop ths kind of access in JX , no ?)
> > By experience JX is full of little bugs (that's why devers are
> > restructuring
> > it) so you have go step by step and be patient ;-) and the solution is
> > certainly there to be found:
> >
> > if things don't work with JEXL then also try the Xpath syntax, especially
> > in
> > the forEach tags and variables , they don't work exactly alike (PLS, don't
> > ask me you????).
> > You probably tried
> > <jx:out value="${model.field[0].name}"/>
> > or maybe something like
> > <jx:out value="#{model.getRow(0).getChild("name").value}"/> does it work ?
> > then go from there
> >
> > Tibor
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> > For additional commands, e-mail: users-help@cocoon.apache.org
> 
>

Re: CForm model to POJO with a "natural" binding [RE: was Display a CForm Repeater in JXTemplate]

Posted by Sylvain Wallez <sy...@apache.org>.
Nicolas Maisonneuve wrote:

>ok maybe i'm not very clear:
>
>the binding framework is good but useless for simple/natural binding.
>Exemple of a form:
>
><form>
><field name="title"/>
><booleanfield name"field"/>
>
><repeater name="contacts">
>  <field name="name" />
>...</repeater>
>...
>a useful tool/feature would be:
>
>var my bean = form.modelToPojo() 
>
>the bean will have this structure 
>bean.title
>bean.field
>bean.contacts[i].name
>etc...
>
>and form.pojoTomodel(bean)
>-----------------
>
>It's possible to do this ? if yes how do you this ?
>  
>

Two solutions come to mind:
- a new <fb:bean> binding, that would bind a full widget subtree to a POJO.
- a new form.createBeanBinding() that would essentially do the same as a 
binding file with a single <fb:bean> instructions, thus avoiding to 
write a seperate file when there's only a bean to bind.

Sylvain

-- 
Sylvain Wallez                        Anyware Technologies
http://apache.org/~sylvain            http://anyware-tech.com
Apache Software Foundation Member     Research & Technology Director