On Lun, 28 de Marzo de 2005, 13:57, Leszek Gawron dijo:
> Antonio Gallardo wrote:
>> Hi:
>>
>> Playing with the binding framework, I tried to set a constant value for
>> a
>> field:
>>
>> The field definition is:
>>
>> <fd:field  id="cli_test">
>>   <fd:datatype base="boolean"/>
>> </fd:field>
>>
>> The binding is:
>>
>> <fb:value id="cli_test" path="cli_test" direction="load"/>
>> <fb:javascript id="cli_test" path="cli_test" direction="save">
>>   <fb:save-form>
>>     //var formValue = widget.getValue();
>>     var appValue = doSaveConversion("false");
>>     jxpathPointer.setValue(appValue);
>>   </fb:save-form>
>> </fb:javascript>
>>
>> The load direction works well, the problem is while saving back. I
>> always
>> throw:
>>
>> Factory is not set on the JXPathContext - cannot create path: /cli_test
>>
>> Descripci�n : org.apache.avalon.framework.CascadingRuntimeException:
>> "resource://org/apache/cocoon/forms/flow/javascript/Form.js", line 190:
>> uncaught JavaScript exception:
>> at auth_success
>> (file:/home/desarrollo/tomcat/webapps/sga/resources/flow/auth.js, Line
>> 42):
>> org.apache.avalon.framework.CascadingRuntimeException:
>> "resource://org/apache/cocoon/forms/flow/javascript/Form.js", line 190:
>> uncaught JavaScript exception:
>> at createform
>> (file:/home/desarrollo/tomcat/webapps/sga/docs/cliente/forms/create/flow.js,
>> Line 8)
>> at (resource://org/apache/cocoon/forms/flow/javascript/Form.js, Line
>> 190):
>> org.apache.commons.jxpath.JXPathException: Exception trying to create
>> xpath cli_impuestosprecios; Factory is not set on the JXPathContext -
>> cannot create path: /cli_impuestosprecios
>>
>> What I can do? Please help.
> Is your field boolean or Boolean? if Boolean you have to initialize it:
>
> public clas Foo {
>      private Boolean bar = new Boolean( false );
> }
>
> or in constructor.
>
> JXPath is not able to create objects objects when assigning a value to a
> specified xpath (it is actually by extending some JXPath functionality
> but I have no idea how exactly and it's quite case oriented - not
> reusable).

Thanks for your comment, it gave a hint to find the solution of the problem.

I just committed a solution to partially solve the problem for most used
datatypes. Still pending for some of them, but hey! This is an start! ;-)

As you told, JXPath is not able by himself to create the needed object. It
needs a "factory" (provided by us) to create them:

http://jakarta.apache.org/commons/jxpath/apidocs/org/apache/commons/jxpath/JXPathContext.html#createPath(java.lang.String)

The Cocoon code already provided a factory that was not able to deal with
beans. And this was the root of the problem and the reason why this worked
when we used an XML file, but no worked when we used a bean. :-(

I just extended our current "factory" to deal with bean's attributes too.
Since the parent context already knows the bean. Then by introspection, I
was able to retrieve the class of the attribute and create a dummy
instance of the attribute class. Then we incorporate it to te JXPAth
engine by calling:

pointer.setValue(dummyObject);

If we do pointer.setValue(null); then JXPath is not able to recognize the
class of the attribute and throw the exception I saw.

I committed in 2.1.8-dev. If nobody is against, I am planning to add this
new feature in 2.2 too.

Best Regards,

Antonio Gallardo.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to