You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Jeremy Quinn <je...@apache.org> on 2005/09/22 19:20:02 UTC

CForms: AJAX problem since update

Hi All,

I have some forms that used the JX Macro form generator and AJAX,  
that worked before the recent update to the 2.2 version of CForms,  
but fail now.

The form contains some regular text fields, a repeater with a row-add  
button and a union with associated selection widget.

The repeater works fine.

The union with it's selection widget stopped working when I updated.

I can see in TCPMon, when you change the selector menu, all the right  
data is submitted.

I get this error when the on-change event occurs for the union  
selector :

org.apache.cocoon.forms.FormsRuntimeException: Form is not a repeater
         at fd:form - file:/[blah]/forms/[blah]-model.xml:5:2
         at <jx:if> - resource://org/apache/cocoon/forms/generation/ 
jx-macros.xml:214:54
         at <ft:repeater> - file:/[blah]/forms/[blah]-template.xml:30:35
         . . .

If I remove the repeater, the Union and it's selector work correctly.


I get a similar error under different circumstances.

Our pages use TimeBrowserUpdate widgets. That use the same  
BrowserUpdateTransformer to update small regions of the page,  
triggered by a timer on the Browser (and I still mean to commit this  
once I know where to put it).

This used to work as well. Since the update however, when you use one  
of these widgets in a page that also has a form that is generated  
using JX Macros, you get this error on update :

org.apache.cocoon.generation.JXTemplateGenerator$JXTException:  
java.lang.NullPointerException
         at <jx:if> - resource://org/apache/cocoon/forms/generation/ 
jx-macros.xml:45:52
         at <ft:widget> - file:[blah]/forms/search-advanced- 
template.xml:17:55

When the TBU updates, it sends only it's own data, not that of the form.

If you set the fd:form/@ajax to false, then the union starts working,  
but the TBU still has the same error.

If you process the form using FormsTransformer instead of JXMacro  
generator, then it works as expected. (You have to switch between  
repeater and repeater widget, I don't know why).

I can see that the implementation of JX Macros has changed  
completely, but as of yet I cannot work out the cause of the problem.

Any suggestions would be welcome.


regards Jeremy

Re: CForms: AJAX problem since update

Posted by Sylvain Wallez <sy...@apache.org>.
Jason Johnston wrote:

> Jeremy Quinn wrote:
>
>>>> I have some forms that used the JX Macro form generator and AJAX,   
>>>> that worked before the recent update to the 2.2 version of  
>>>> CForms,  but fail now.
>>>
>
> The following patch works to fix the problem in my app, and also in 
> the TaskTree sample.  Neither of these had any union widgets though, 
> so could you please give it a try and see if it fixes your situation 
> as well?
>
> I'll put this in Bugzilla too.


Thanks for having digged that far Jason!

Jeremy, does it solve your problem?

Sylvain

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


Re: CForms: AJAX problem since update

Posted by Jason Johnston <co...@lojjic.net>.
Jeremy Quinn wrote:
>>> I have some forms that used the JX Macro form generator and AJAX,   
>>> that worked before the recent update to the 2.2 version of  CForms,  
>>> but fail now.

The following patch works to fix the problem in my app, and also in the 
TaskTree sample.  Neither of these had any union widgets though, so 
could you please give it a try and see if it fixes your situation as well?

I'll put this in Bugzilla too.

--Jason



Index: forms/java/org/apache/cocoon/forms/formmodel/Form.java
===================================================================
--- forms/java/org/apache/cocoon/forms/formmodel/Form.java    (revision 
291418)
+++ forms/java/org/apache/cocoon/forms/formmodel/Form.java    (working 
copy)
@@ -129,7 +129,7 @@
                  Widget parent = widget.getParent();
                  addParents: while (parent != this && parent != null) {
                      if 
(this.childUpdatedWidgets.add(parent.getRequestParameterName())) {
-                        parent = getParent();
+                        parent = parent.getParent();
                      } else {
                          // Parent already there, and therefore its own 
parents.
                          break addParents;
Index: forms/java/org/apache/cocoon/forms/generation/JXMacrosHelper.java
===================================================================
--- forms/java/org/apache/cocoon/forms/generation/JXMacrosHelper.java 
  (revision 291418)
+++ forms/java/org/apache/cocoon/forms/generation/JXMacrosHelper.java 
  (working copy)
@@ -235,9 +235,11 @@

      public boolean pushRepeater(String path) throws SAXException {
          boolean result = pushWidget(path, true);
-        Widget w = peekWidget();
-        if (!(w instanceof Repeater)) {
-            throw new FormsRuntimeException(w + " is not a repeater", 
w.getLocation());
+        if(result) {
+            Widget w = peekWidget();
+            if (!(w instanceof Repeater)) {
+                throw new FormsRuntimeException(w + " is not a 
repeater", w.getLocation());
+            }
          }
          return result;
      }

Re: CForms: AJAX problem since update

Posted by Jeremy Quinn <je...@apache.org>.
Hi Sylvain,

Many thanks for your reply.


On 22 Sep 2005, at 20:20, Sylvain Wallez wrote:

> Jeremy Quinn wrote:
>
>
>> Hi All,
>>
>> I have some forms that used the JX Macro form generator and AJAX,   
>> that worked before the recent update to the 2.2 version of  
>> CForms,  but fail now.
>>
>> The form contains some regular text fields, a repeater with a row- 
>> add  button and a union with associated selection widget.
>>
>> The repeater works fine.
>>
>> The union with it's selection widget stopped working when I updated.
>>
>> I can see in TCPMon, when you change the selector menu, all the  
>> right  data is submitted.
>>
>> I get this error when the on-change event occurs for the union   
>> selector :
>>
>> org.apache.cocoon.forms.FormsRuntimeException: Form is not a repeater
>>         at fd:form - file:/[blah]/forms/[blah]-model.xml:5:2
>>         at <jx:if> - resource://org/apache/cocoon/forms/ 
>> generation/ jx-macros.xml:214:54
>>         at <ft:repeater> - file:/[blah]/forms/[blah]-template.xml: 
>> 30:35
>>         . . .
>>

org.apache.cocoon.forms.FormsRuntimeException: Form is not a repeater
         at fd:form - file:/[blah]/forms/search-advanced-model.xml:5:2
         at <jx:if> - resource://org/apache/cocoon/forms/generation/ 
jx-macros.xml:214:54
         at <ft:repeater> - file:/[blah]/forms/search-advanced- 
template.xml:35:35
         at <jx:evalBody> - resource://org/apache/cocoon/forms/ 
generation/jx-macros.xml:34:23
         at <ft:form-template> - file:/[blah]/forms/search-advanced- 
template.xml:20:84
         at <map:serialize type="xml"> - file:/[blah]/sitemap.xmap: 
159:55
         at <map:transform> - file:/[blah]/sitemap.xmap:154:69
         at <map:transform type="encodeURL"> - file:/[blah]/ 
sitemap.xmap:127:40
         at <map:transform> - file:/[blah]/sitemap.xmap:123:72
         at <map:transform type="i18n"> - file:/[blah]/sitemap.xmap: 
120:31
         at <map:transform type="browser-update"> - file:/[blah]/ 
sitemap.xmap:119:42
         at <map:transform type="cinclude"> - file:/[blah]/ 
sitemap.xmap:118:36
         at <map:transform> - file:/[blah]/sitemap.xmap:117:77
         at <map:generate type="jx"> - file:/[blah]/sitemap.xmap:152:44
         at file:/[blah]/flow/query.js:137:-1
         at <map:call> - file:/[blah]/sitemap.xmap:388:43
         at <map:mount> - file:/Users/jerm/Development/Checkouts/ 
Apache/Cocoon/Cocoon_2_1_X/build/webapp/sitemap.xmap:709:57
         at  
org.apache.cocoon.forms.generation.JXMacrosHelper.pushRepeater 
(JXMacrosHelper.java:240)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke 
(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke 
(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:324)




>> If I remove the repeater, the Union and it's selector work correctly.
>>
>>
>> I get a similar error under different circumstances.
>>
>> Our pages use TimeBrowserUpdate widgets. That use the same   
>> BrowserUpdateTransformer to update small regions of the page,   
>> triggered by a timer on the Browser (and I still mean to commit  
>> this  once I know where to put it).
>>
>> This used to work as well. Since the update however, when you use  
>> one  of these widgets in a page that also has a form that is  
>> generated  using JX Macros, you get this error on update :
>>
>> org.apache.cocoon.generation.JXTemplateGenerator$JXTException:   
>> java.lang.NullPointerException
>>         at <jx:if> - resource://org/apache/cocoon/forms/ 
>> generation/ jx-macros.xml:45:52
>>         at <ft:widget> - file:[blah]/forms/search-advanced-  
>> template.xml:17:55
>>
>
>
> Can you give also the first lines of the java stacktrace to know  
> where the NPE happens?


java.lang.NullPointerException
resource://org/apache/cocoon/forms/generation/jx-macros.xml - 45:52
<jx:if>
file:/[blah]/forms/search-advanced-template.xml - 22:55
<ft:widget>
resource://org/apache/cocoon/forms/generation/jx-macros.xml - 34:23
<jx:evalBody>
file:/[blah]/forms/search-advanced-template.xml - 20:84
<ft:form-template>
file:/[blah]/sitemap.xmap - 159:55
<map:serialize type="xml">
file:/[blah]/sitemap.xmap - 154:69
<map:transform>
file:/[blah]/sitemap.xmap - 127:40
<map:transform type="encodeURL">
file:/[blah]/sitemap.xmap - 123:72
<map:transform>
file:/[blah]/sitemap.xmap - 120:31
<map:transform type="i18n">
file:/[blah]/sitemap.xmap - 119:42
<map:transform type="browser-update">
file:/[blah]/sitemap.xmap - 118:36
<map:transform type="cinclude">
file:/[blah]/sitemap.xmap - 117:77
<map:transform>
file:/[blah]/sitemap.xmap - 152:44
<map:generate type="jx">
file:/[blah]/flow/query.js - 137:-1

file:/[blah]/sitemap.xmap - 568:36
<map:call>
context://sitemap.xmap - 709:57
<map:mount>

java.lang.NullPointerException
         at  
org.apache.cocoon.forms.generation.JXMacrosHelper.pushWidget 
(JXMacrosHelper.java:158)
         at  
org.apache.cocoon.forms.generation.JXMacrosHelper.pushWidget 
(JXMacrosHelper.java:229)
         at sun.reflect.GeneratedMethodAccessor22.invoke(Unknown Source)




>
>
>> When the TBU updates, it sends only it's own data, not that of the  
>> form.
>>
>> If you set the fd:form/@ajax to false, then the union starts  
>> working,  but the TBU still has the same error.
>>
>> If you process the form using FormsTransformer instead of JXMacro   
>> generator, then it works as expected. (You have to switch between   
>> repeater and repeater widget, I don't know why).
>>
>> I can see that the implementation of JX Macros has changed   
>> completely, but as of yet I cannot work out the cause of the problem.
>>
>> Any suggestions would be welcome.
>>
>
>
> JX macros were largely refactored, and there was a little change to  
> widget scoping within <ft:repeater>. This scoping defines the base  
> widget that is used to resolve @id attributes on template  
> instructions, which is also available as the ${widget} variable.
>
> Within <ft:repeater> and before we enter <ft:repater-rows>, $widget  
> is now the repeater itself whereas it previously was the parent of  
> the repeater.
>
> The "addcontact" widget in the dynamic_repeater sample is a good  
> example of this change.
>
> We previously had
>  <ft:repeater id="contacts">
>    ...
>    <ft:repeater-rows>
>      ...
>    </ft:repeater-rows>
>    <ft:widget id="addcontact"/>
>  </ft:repeater>
>
> whereas we now have
>  <ft:repeater id="contacts">
>    ...
>    <ft:repeater-rows>
>      ...
>    </ft:repeater-rows>
>    <ft:widget id="../addcontact"/>
>  </ft:repeater>
>
> Can this be the cause of your problem?


I do not think so.

The repeater works correctly, AJAX or not.

I can make the Union work with AJAX, but only when the AJAXified  
Repeater is not present on the form.

The problems I am seeing (that did not exist before) seem to happen  
under two circumstances:

1. when a different AJAXified widget submits a form that contains an  
AJAXified Repeater

2. when a BrowserUpdate event is sent to the Server, that has not  
been triggered by CForms, but an JX Macro CForm is on the page.



thanks

regards Jeremy





Re: CForms: AJAX problem since update

Posted by Sylvain Wallez <sy...@apache.org>.
Jeremy Quinn wrote:

> Hi All,
>
> I have some forms that used the JX Macro form generator and AJAX,  
> that worked before the recent update to the 2.2 version of CForms,  
> but fail now.
>
> The form contains some regular text fields, a repeater with a row-add  
> button and a union with associated selection widget.
>
> The repeater works fine.
>
> The union with it's selection widget stopped working when I updated.
>
> I can see in TCPMon, when you change the selector menu, all the right  
> data is submitted.
>
> I get this error when the on-change event occurs for the union  
> selector :
>
> org.apache.cocoon.forms.FormsRuntimeException: Form is not a repeater
>         at fd:form - file:/[blah]/forms/[blah]-model.xml:5:2
>         at <jx:if> - resource://org/apache/cocoon/forms/generation/ 
> jx-macros.xml:214:54
>         at <ft:repeater> - file:/[blah]/forms/[blah]-template.xml:30:35
>         . . .
>
> If I remove the repeater, the Union and it's selector work correctly.
>
>
> I get a similar error under different circumstances.
>
> Our pages use TimeBrowserUpdate widgets. That use the same  
> BrowserUpdateTransformer to update small regions of the page,  
> triggered by a timer on the Browser (and I still mean to commit this  
> once I know where to put it).
>
> This used to work as well. Since the update however, when you use one  
> of these widgets in a page that also has a form that is generated  
> using JX Macros, you get this error on update :
>
> org.apache.cocoon.generation.JXTemplateGenerator$JXTException:  
> java.lang.NullPointerException
>         at <jx:if> - resource://org/apache/cocoon/forms/generation/ 
> jx-macros.xml:45:52
>         at <ft:widget> - file:[blah]/forms/search-advanced- 
> template.xml:17:55


Can you give also the first lines of the java stacktrace to know where 
the NPE happens?

> When the TBU updates, it sends only it's own data, not that of the form.
>
> If you set the fd:form/@ajax to false, then the union starts working,  
> but the TBU still has the same error.
>
> If you process the form using FormsTransformer instead of JXMacro  
> generator, then it works as expected. (You have to switch between  
> repeater and repeater widget, I don't know why).
>
> I can see that the implementation of JX Macros has changed  
> completely, but as of yet I cannot work out the cause of the problem.
>
> Any suggestions would be welcome.


JX macros were largely refactored, and there was a little change to 
widget scoping within <ft:repeater>. This scoping defines the base 
widget that is used to resolve @id attributes on template instructions, 
which is also available as the ${widget} variable.

Within <ft:repeater> and before we enter <ft:repater-rows>, $widget is 
now the repeater itself whereas it previously was the parent of the 
repeater.

The "addcontact" widget in the dynamic_repeater sample is a good example 
of this change.

We previously had
  <ft:repeater id="contacts">
    ...
    <ft:repeater-rows>
      ...
    </ft:repeater-rows>
    <ft:widget id="addcontact"/>
  </ft:repeater>

whereas we now have
  <ft:repeater id="contacts">
    ...
    <ft:repeater-rows>
      ...
    </ft:repeater-rows>
    <ft:widget id="../addcontact"/>
  </ft:repeater>

Can this be the cause of your problem?

Sylvain

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


Re: CForms: AJAX problem since update

Posted by Jason Johnston <co...@lojjic.net>.
Jeremy Quinn wrote:
> Hi All,
> 
> I have some forms that used the JX Macro form generator and AJAX,  that 
> worked before the recent update to the 2.2 version of CForms,  but fail 
> now.
> 
> The form contains some regular text fields, a repeater with a row-add  
> button and a union with associated selection widget.
> 
> The repeater works fine.
> 
> The union with it's selection widget stopped working when I updated.
> 
> I can see in TCPMon, when you change the selector menu, all the right  
> data is submitted.
> 
> I get this error when the on-change event occurs for the union  selector :
> 
> org.apache.cocoon.forms.FormsRuntimeException: Form is not a repeater
>         at fd:form - file:/[blah]/forms/[blah]-model.xml:5:2
>         at <jx:if> - resource://org/apache/cocoon/forms/generation/ 
> jx-macros.xml:214:54
>         at <ft:repeater> - file:/[blah]/forms/[blah]-template.xml:30:35
>         . . .

I was seeing this problem (or a very similar one that gives the same 
error) in my app too, and found a way to reproduce it in the samples.

Open tasktree_template.xml (which is supposedly supposed to be an AJAX 
sample but has ajax="false" for some reason) and change it to 
ajax="true".  Launch the sample, click "Add Subtask" and then click the 
"Add Subtask" in the added task.  You'll get the error in question.

Here's the relevant portion of the Java stacktrace:

org.apache.cocoon.forms.FormsRuntimeException: Form is not a repeater
	at fd:form - 
file:/home/jj/workspace/cocoon-2.1.x/build/webapp/samples/blocks/forms/forms/tasktree.xml:25:57
	at <jx:if> - 
resource://org/apache/cocoon/forms/generation/jx-macros.xml:214:54
	at <ft:repeater> - 
file:/home/jj/workspace/cocoon-2.1.x/build/webapp/samples/blocks/forms/forms/tasktree_template.xml:93:33
	at <jx:eval> - 
resource://org/apache/cocoon/forms/generation/jx-macros.xml:138:59
	at <ft:new> - 
file:/home/jj/workspace/cocoon-2.1.x/build/webapp/samples/blocks/forms/forms/tasktree_template.xml:117:36
	at <jx:evalBody> - 
resource://org/apache/cocoon/forms/generation/jx-macros.xml:34:23
	at <ft:form-template> - 
file:/home/jj/workspace/cocoon-2.1.x/build/webapp/samples/blocks/forms/forms/tasktree_template.xml:68:94
	at <map:serialize type="xml"> - 
file:/home/jj/workspace/cocoon-2.1.x/build/webapp/samples/blocks/forms/sitemap.xmap:216:32
	at <map:transform type="i18n"> - 
file:/home/jj/workspace/cocoon-2.1.x/build/webapp/samples/blocks/forms/sitemap.xmap:210:35
	at <map:transform> - 
file:/home/jj/workspace/cocoon-2.1.x/build/webapp/samples/blocks/forms/sitemap.xmap:209:66
	at <map:transform> - 
file:/home/jj/workspace/cocoon-2.1.x/build/webapp/samples/blocks/forms/sitemap.xmap:62:88
	at <map:transform type="i18n"> - 
file:/home/jj/workspace/cocoon-2.1.x/build/webapp/samples/blocks/forms/sitemap.xmap:203:35
	at <map:transform type="browser-update"> - 
file:/home/jj/workspace/cocoon-2.1.x/build/webapp/samples/blocks/forms/sitemap.xmap:202:46
	at <map:generate type="jx"> - 
file:/home/jj/workspace/cocoon-2.1.x/build/webapp/samples/blocks/forms/sitemap.xmap:201:79
	at resource://org/apache/cocoon/forms/flow/javascript/Form.js:180:-1
	at 
file:/home/jj/workspace/cocoon-2.1.x/build/webapp/samples/blocks/forms/flow/forms_flow_example.js:0:-1
	at <map:call> - 
file:/home/jj/workspace/cocoon-2.1.x/build/webapp/samples/blocks/forms/sitemap.xmap:170:38
	at <map:mount> - 
file:/home/jj/workspace/cocoon-2.1.x/build/webapp/samples/blocks/sitemap.xmap:66:68
	at <map:mount> - 
file:/home/jj/workspace/cocoon-2.1.x/build/webapp/samples/sitemap.xmap:194:65
	at <map:mount> - 
file:/home/jj/workspace/cocoon-2.1.x/build/webapp/sitemap.xmap:728:66
	at 
org.apache.cocoon.forms.generation.JXMacrosHelper.pushRepeater(JXMacrosHelper.java:240)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:324)
	at 
org.apache.commons.jexl.util.introspection.UberspectImpl$VelMethodImpl.invoke(UberspectImpl.java:268)
	at org.apache.commons.jexl.parser.ASTMethod.execute(ASTMethod.java:61)
	at 
org.apache.commons.jexl.parser.ASTReference.execute(ASTReference.java:68)
	at org.apache.commons.jexl.parser.ASTReference.value(ASTReference.java:50)
	at org.apache.commons.jexl.ExpressionImpl.evaluate(ExpressionImpl.java:86)
	at 
org.apache.cocoon.generation.JXTemplateGenerator.getValue(JXTemplateGenerator.java:799)
	at 
org.apache.cocoon.generation.JXTemplateGenerator.execute(JXTemplateGenerator.java:2654)
	at 
org.apache.cocoon.generation.JXTemplateGenerator.call(JXTemplateGenerator.java:2537)
	at 
org.apache.cocoon.generation.JXTemplateGenerator.execute(JXTemplateGenerator.java:2919)
	at 
org.apache.cocoon.generation.JXTemplateGenerator.execute(JXTemplateGenerator.java:3055)
	at 
org.apache.cocoon.generation.JXTemplateGenerator.call(JXTemplateGenerator.java:2537)
	at 
org.apache.cocoon.generation.JXTemplateGenerator.execute(JXTemplateGenerator.java:2919)
	at 
org.apache.cocoon.generation.JXTemplateGenerator.execute(JXTemplateGenerator.java:3064)
	at 
org.apache.cocoon.generation.JXTemplateGenerator.call(JXTemplateGenerator.java:2537)
	at 
org.apache.cocoon.generation.JXTemplateGenerator.execute(JXTemplateGenerator.java:2919)
	at 
org.apache.cocoon.generation.JXTemplateGenerator.performGeneration(JXTemplateGenerator.java:2497)
	at 
org.apache.cocoon.generation.JXTemplateGenerator.generate(JXTemplateGenerator.java:2488)