You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Nicole Hochleiter <ho...@seitenbau.com> on 2004/07/06 17:21:29 UTC

CForms, binding with repeater, new element overwrites old element

In stepping through org.apache.cocoon.forms.binding.RepeaterJXPathBinding 
public void doSave(Widget frmModel, JXPathContext jxpc) throws BindingException

I got the impression, that my new added element overwrites an existing one.

I'm working with bean binding, cocoon.2.1.5, Java 1.4.2.

Is it a bug or did I miss something in the configuration?

I got the idea that this is a bug, because I could fix this 'bug' in my special
case in putting some lines into that class,  like:
(but I do not want to keep it)
[...]
  //register the factory!
  while (rowIterator.hasNext()) {
      Repeater.RepeaterRow thisRow = (Repeater.RepeaterRow)rowIterator.next();
      // Perform the insert row binding.
      this.insertRowBinding.saveFormToModel(repeater, repeaterContext);
      // -->  create the path to let the context be created

      // -------- My FIX: the pointer pointed always to the last element, 
      // whicht not automatically was the new one
      Pointer newRowContextPointer = null;
      for (int i=0 ; i <= indexCount; i++) {
        newRowContextPointer = 
          repeaterContext.createPath(this.rowPathForInsert + "[" + i + "]");
        Object valueObject = newRowContextPointer.getValue();
        // here is where I check if it really is new (but it only works 
        // with my objectmodel
        if (valueObject instanceof ONStructureElement) {
          if (((ONStructureElement)valueObject).isNew() && 
              ((ONStructureElement)valueObject)._id==null)
           break;
        }
      }                    

      // this was the original line
      /*Pointer newRowContextPointer = repeaterContext.createPath(
              this.rowPathForInsert + "[" + indexCount + "]"); */
      // -------- END My FIX

      JXPathContext newRowContext =
              repeaterContext.getRelativeContext(newRowContextPointer);
      if (getLogger().isDebugEnabled()) {
          getLogger().debug("inserted row at " + newRowContextPointer.asPath());
      }
      //    + rebind to children for update
      this.rowBinding.saveFormToModel(thisRow, newRowContext);
      getLogger().debug("bound new row");
      indexCount++;
  }

Is it really a bug or can I fix my problem in configuring something?
TNX,
Nicole


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: CForms, binding with repeater, new element overwrites old element

Posted by Nicole Hochleiter <ho...@seitenbau.com>.
> [...]

> > So there are three possible sources of trouble:
> > 1. fd:field vs. fd:output
> > 2. (duplicate) binding for id and implicit direction="both"
> > 3. addUser method
> > 
> > Joerg
> > 
> Now I changed the the line in <fb:on-bind>... for id to direction="save" and it
> works fine. )
> 
> Thanks a lot!
> Nicole
> 


After all I still had some problems. In testing and stepping through the code I
found out, that datatype in the bean where my users are added must be something
like an array which has an order. First I had a HashSet where I added my users 
to.

Now, since it is an ArrayList, ist works.

Nicole


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: CForms, binding with repeater, new element overwrites old element

Posted by Nicole Hochleiter <ho...@seitenbau.com>.
Joerg Heinicke <joerg.heinicke <at> gmx.de> writes:

> 
> On 09.07.2004 09:19, Nicole Hochleiter wrote:
> 
...
> > 
> >     <fb:on-bind>
> >       <!-- executed on updates AND right after the insert -->
> >       <fb:value id="id" path="id"/>
> 
> This one duplicates the binding of fb:identity.
> 
> >       ...
> >     </fb:on-bind>
...
> > 
> >     <fb:on-insert-row>
> >       <fb:insert-bean
> >         classname="com.seitenbau.objectmodel.User"
> >         addmethod="addUser"/>
> 
> This method handles the adding of new beans, so maybe you do something 
> wrong there? My addObject methods mostly only look like:
> 
> public void addObject(Object obj) {
>      this.objects.add(obj);
> }
> 
> where this.objects is a collection. I guess it's the same for you.

yes, I have sth. like this. A new object is greated (with default constructor).
The object is empty and added like in your method.

> 
> >     </fb:on-insert-row>
> >   </fb:repeater> 
> > 

> Do you have the id fields in the client, maybe as hidden input? If not 
> they will loose their values.

I have the id-field as a hidden field and I set the new one, if a I a new 
object, because in my application the user is not allowed to create totally new
objects. The user only can choose from a list, where then the id is taken.
So first I add a new row (with hidden id field), then I fill this hidden field
with javascript and then I send the form. This is why I need the setter for id.

[...]
> > 
> > and my com.seitenbau.objectmodel.User bean has a getter and setter for id.
> 
> I don't have a setter at all as cforms does not generate my ids. So I 
> also only have a direction="load" binding for the ids. Additionally I do 
> not deliver the ids to the client and so only have an fd:output for all ids.
> 
> So there are three possible sources of trouble:
> 1. fd:field vs. fd:output
> 2. (duplicate) binding for id and implicit direction="both"
> 3. addUser method
> 
> Joerg
> 
Now I changed the the line in <fb:on-bind>... for id to direction="save" and it
works fine. :-))

Thanks a lot!
Nicole





---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: CForms, binding with repeater, new element overwrites old element

Posted by Joerg Heinicke <jo...@gmx.de>.
On 09.07.2004 09:19, Nicole Hochleiter wrote:

>>> In stepping through org.apache.cocoon.forms.binding.RepeaterJXPathBinding
>>> public void doSave(Widget frmModel, JXPathContext jxpc) throws 
>>> BindingException I got the impression, that my new added element
>>> overwrites an existing one.
>>> I'm working with bean binding, cocoon.2.1.5, Java 1.4.2. Is it a
>>> bug or did I miss something in the configuration? I got the idea
>>> that this is a bug, because I could fix this 'bug' in my special
>>> case in putting some lines into that class, like: (but I do not
>>> want to keep it)
>> 
>> ...
>> 
>>> Is it really a bug or can I fix my problem in configuring
>>> something?
>> 
>> I had no look into your patch, but for me repeater binding works
>> without any patch, so it's probably a misconfiguration in your
>> binding file.
> 
> In my binding file I configured the repeater as follows:
>   <fb:repeater id="structureUser"
>                parent-path="."
>                row-path="user">
> 
>     <fb:identity>
>       <fb:value id="id" path="id"/>
>     </fb:identity>
> 
>     <fb:on-bind>
>       <!-- executed on updates AND right after the insert -->
>       <fb:value id="id" path="id"/>

This one duplicates the binding of fb:identity.

>       ...
>     </fb:on-bind>
> 
>     <fb:on-delete-row>
>       <fb:set-attribute name="isDeleted" value="true" />
>     </fb:on-delete-row>
> 
>     <fb:on-insert-row>
>       <fb:insert-bean
>         classname="com.seitenbau.objectmodel.User"
>         addmethod="addUser"/>

This method handles the adding of new beans, so maybe you do something 
wrong there? My addObject methods mostly only look like:

public void addObject(Object obj) {
     this.objects.add(obj);
}

where this.objects is a collection. I guess it's the same for you.

>     </fb:on-insert-row>
>   </fb:repeater> 
> 
> the model has something like:
>     <fd:repeater id="strukturUser" initial-size="0">
>       <fd:label>User</fd:label>
>       <fd:widgets>
>         <fd:field id="id">
>           <fd:datatype base="string"/>
>         </fd:field>

Do you have the id fields in the client, maybe as hidden input? If not 
they will loose their values.

> [...]
>         <fd:booleanfield id="select">
>           <fd:label>choose</fd:label>
>         </fd:booleanfield>
>       </fd:widgets>
>     </fd:repeater>
>   
>     <fd:repeater-action id="adduser" action-command="add-row"
>                         repeater="strukturUser">
>       <fd:label>add user</fd:label>
>     </fd:repeater-action>
>   
>     <fd:repeater-action id="removeuser" action-command="delete-rows"
>                         repeater="strukturUser" select="select">
>       <fd:label>remove user</fd:label>
>     </fd:repeater-action>
> 
> and my com.seitenbau.objectmodel.User bean has a getter and setter for id.

I don't have a setter at all as cforms does not generate my ids. So I 
also only have a direction="load" binding for the ids. Additionally I do 
not deliver the ids to the client and so only have an fd:output for all ids.

So there are three possible sources of trouble:
1. fd:field vs. fd:output
2. (duplicate) binding for id and implicit direction="both"
3. addUser method

Joerg

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: CForms, binding with repeater, new element overwrites old element

Posted by Nicole Hochleiter <ho...@seitenbau.com>.
Joerg Heinicke <joerg.heinicke <at> gmx.de> writes:

> 
> On 06.07.2004 17:21, Nicole Hochleiter wrote:
> 
> > In stepping through org.apache.cocoon.forms.binding.RepeaterJXPathBinding 
> > public void doSave(Widget frmModel, JXPathContext jxpc) throws 
BindingException
> > 
> > I got the impression, that my new added element overwrites an existing one.
> > 
> > I'm working with bean binding, cocoon.2.1.5, Java 1.4.2.
> > 
> > Is it a bug or did I miss something in the configuration?
> > 
> > I got the idea that this is a bug, because I could fix this 'bug' in my 
special
> > case in putting some lines into that class,  like:
> > (but I do not want to keep it)
> 
> ...
> 
> > Is it really a bug or can I fix my problem in configuring something?
> 
> I had no look into your patch, but for me repeater binding works without 
> any patch, so it's probably a misconfiguration in your binding file.
> 
> Joerg
> 
In my binding file I configured the repeater as follows:
  <fb:repeater id="structureUser"
               parent-path="."
               row-path="user">

    <fb:identity>
      <fb:value id="id" path="id"/>
    </fb:identity>

    <fb:on-bind>
      <!-- executed on updates AND right after the insert -->
      <fb:value id="id" path="id"/>
      ...
    </fb:on-bind>

    <fb:on-delete-row>
      <fb:set-attribute name="isDeleted" value="true" />
    </fb:on-delete-row>

    <fb:on-insert-row>
      <fb:insert-bean
        classname="com.seitenbau.objectmodel.User"
        addmethod="addUser"/>
    </fb:on-insert-row>
  </fb:repeater> 

the model has something like:
    <fd:repeater id="strukturUser" initial-size="0">
      <fd:label>User</fd:label>
      <fd:widgets>
        <fd:field id="id">
          <fd:datatype base="string"/>
        </fd:field>     
[...]
        <fd:booleanfield id="select">
          <fd:label>choose</fd:label>
        </fd:booleanfield>
      </fd:widgets>
    </fd:repeater>
  
    <fd:repeater-action id="adduser" action-command="add-row"
                        repeater="strukturUser">
      <fd:label>add user</fd:label>
    </fd:repeater-action>
  
    <fd:repeater-action id="removeuser" action-command="delete-rows"
                        repeater="strukturUser" select="select">
      <fd:label>remove user</fd:label>
    </fd:repeater-action>

and my com.seitenbau.objectmodel.User bean has a getter and setter for id.
Do I miss something?

Nicole


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: CForms, binding with repeater, new element overwrites old element

Posted by Joerg Heinicke <jo...@gmx.de>.
On 06.07.2004 17:21, Nicole Hochleiter wrote:

> In stepping through org.apache.cocoon.forms.binding.RepeaterJXPathBinding 
> public void doSave(Widget frmModel, JXPathContext jxpc) throws BindingException
> 
> I got the impression, that my new added element overwrites an existing one.
> 
> I'm working with bean binding, cocoon.2.1.5, Java 1.4.2.
> 
> Is it a bug or did I miss something in the configuration?
> 
> I got the idea that this is a bug, because I could fix this 'bug' in my special
> case in putting some lines into that class,  like:
> (but I do not want to keep it)

...

> Is it really a bug or can I fix my problem in configuring something?

I had no look into your patch, but for me repeater binding works without 
any patch, so it's probably a misconfiguration in your binding file.

Joerg

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org