Roberto Marra wrote: > Hi guys, > still here with some problem of binding. Let me explain the situation. > First of all a snipped of how the file are made: > > -- Binding file -- > ... > <fb:value id="indirizzo1" path="indirizzo"/> > <fb:value id="cap" path="cap"/> > <fb:javascript id="nazione" path=".">
I suspect this path to be wrong? Reading those 3 together assumes there is one object in memory (let's call it x) upon which you're doing: x.setIndirizzo(form.lookupWidget("indirrizo1").getValue()); x.setCap(form.lookupWidget("cap").getValue()); x = doCountryConversion(form.lookupWidget("nazione").getValue()); (since you only provided a snippet the lookup-paths probably miss out on some context-prefixes) I hope you see better now whatis strange about it: why set two fields in x before replacing it completely? > <fb:load-form/> > <fb:save-form> > var formValue = widget.getValue(); > var appValue = doCountryConversion(formValue); > jxpathPointer.setValue(appValue); > </fb:save-form> > </fb:javascript> > ... > -- File definition -- > ... > <!-- Nazione --> > <fd:field id="nazione"> > <fd:label>Nazione:</fd:label> > <fd:datatype base="string"/> > <fd:selection-list src="cocoon:/nazioni.list"/> > </fd:field> > ... > > -- Java Bean -- > > public class ContactBean { > > > private Country nazione; > > public Country getNazione(){ > return this.nazione; > } > > > public void setNazione(Country _nazione){ > this.nazione = _nazione; > } > > } > > The problem is when the binding is doing this > "jxpathPointer.setValue(appValue);" I got this error: > > > > An Error Occurred > > uncaught JavaScript exception: at contatti (file:/D:/Programmi/Apache > Group/cocoon-2.1.5.1/build/webapp/mf/flow/contatti.js, Line 41) at > (resource://org/apache/cocoon/forms/flow/javascript/Form.js, Line 171): > org.apache.avalon.framework.CascadingRuntimeException: Error invoking > JavaScript event handler > > org.apache.avalon.framework.CascadingRuntimeException: uncaught > JavaScript exception: at contatti (file:/D:/Programmi/Apache > Group/cocoon-2.1.5.1/build/webapp/mf/flow/contatti.js, Line 41) at > (resource://org/apache/cocoon/forms/flow/javascript/Form.js, Line 171): > org.apache.avalon.framework.CascadingRuntimeException: Error invoking > JavaScript event handler > > cause: org.mozilla.javascript.JavaScriptException: at top-level script > (file:/D:/Programmi/Apache > Group/cocoon-2.1.5.1/build/webapp/mf/binding/contatti/contatti.xml, Line > 14): java.lang.NullPointerException > > The contatti.xml, Line 14 correspond to > "jxpathPointer.setValue(appValue);" but appValue is not null there is a > value!! > > Any suggestion is welcome. > NPE's normally indicate the 'null' is not in the argument, but rather in the object you call upon. (a lesson to be learned from digging stacktraces to the bottom-nested cause) So rather then suspecting 'appValue' we should question what might be wrong with 'jxpathPointer' (hence my guess about the path being wrong) Behind the scenes the jxpath based binding is trying something like this Object current; Class cls = current.getClass(); Method m = cls.getMethod("setSomeProp", new Class[]{Country.class}); m.invoke(current, new Object[] {newValue}); likely suspects for the NPE are eihter 1/ 'current' meaning the object to set the value upon is simply not there, or else 2/ 'm' meaning the object passed in doesn't have a setter for the property 'someProp' hopefully the full stacktrace can help you make that distinction else avoid the binding at first and write what you need in clear java or javascript using lookupWidget() and getValue() The binding is not a must: it tries to help writing those manual value-binding statements in a more condense and symmetric fashion (i.e. one set of statements that deal with both loading and saving), on the downside however it adds a layer that might obfuscate stacktraces and debugging and getting the @path statements right is known to be a daunting adventure from time to time. HTH -marc= -- Marc Portier http://outerthought.org/ Outerthought - Open Source, Java & XML Competence Support Center Read my weblog at http://blogs.cocoondev.org/mpo/ [EMAIL PROTECTED] [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]