You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Paloma Gomez <pa...@gmail.com> on 2006/07/13 01:10:13 UTC

CForms: Time widget binding problem

Hi all,

After having a look at the CForms samples I'm trying to create my
first form. This is the first time I'm doing it, so maybe there are
things I think I understand and actually  I don't ;).

I'm having problems with the binding of a time widget to a bean and I
can't find any example of time widgets in cocoon samples. (I'm only
interested in the time, I know there are examples with dates).

Here is the widget definition:

<fd:field id="time" required="true">
   <fd:label>Time (hh:mm):</fd:label>
   <fd:datatype base="date">
	<fd:convertor datatype="date" variant="time" type="formatting">
		<fd:patterns>
			<fd:pattern>kk:mm</fd:pattern>
		</fd:patterns>
	 </fd:convertor>
    </fd:datatype>
</fd:field>

Now the binding:
<fb:value id="time" path="time">
   <fd:convertor datatype="date" variant="time" type="formatting">
       <fd:patterns>
          <fd:pattern>kk:mm</fd:pattern>
        </fd:patterns>
   </fd:convertor>
    </fd:datatype>
</fb:value>	
(I've tried some variants of this without success)

(There is something I don't understand well: why do I need two convertors?)

And finally the bean (I include only the fragments related to this widget)

[...]
import java.sql.Time;
[...]
public class EventBean {
[...]
private Time time;
[...]
public Time getTime() {
        return time;
    }

    public void setTime(Time time) {
        this.time = time;
    }
[...]
}

I use the datatype java.sql.Time because I want to use it to query a
database. I don't know if this is relevant or not.

I get the following error message:
[...]
Caused by: org.apache.commons.jxpath.JXPathException: Cannot modify
property: module.EventBean.time; Cannot convert value of class
java.lang.String to type class java.sql.Time;
org.apache.commons.beanutils.ConversionException

My system:
* cocoon-2.1.10-dev
* jetty
* Ubuntu Linux

Any hints would be appreciated.

Thanks

Paloma

--
Paloma Gomez

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


Re: CForms: Time widget binding problem

Posted by Paloma Gomez <pa...@gmail.com>.
Hi Jason,

> Maybe try this instead (uses the bean directly rather than jxpath's
> pointer):
>
> <fb:javascript id="time" path=".">
>    <fb:load-form>
>      widget.setValue(jxpathContext.getNode().getTime());
>    </fb:load-form>
>    <fb:save-form>
>      var time = new java.sql.Time(widget.getValue().getTime());
>      jxpathContext.getNode().setTime(time);
>    </fb:save-form>
> </fb:javascript>

It doesn't work either :/.
>
> > I'm not sure, but I think this does not work:
> > var time = new java.sql.Time(widget.getValue().getTime());

I know now that this portion was ok :).

I've decided to store both date and time in the bean as java.util.Date
and make the conversion later. Anyway, thanks for your help. It's made
me understand how the conversion works.

Regards,
Paloma
--
Paloma Gomez

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


Re: CForms: Time widget binding problem

Posted by Jason Johnston <co...@lojjic.net>.
Paloma Gomez wrote:
>> <fb:javascript id="time" path="time">
>>    <fb:load-form>
>>      // no conversion necessary since Time extends Date:
>>      widget.setValue(jxpathPointer.getValue());
>>    </fb:load-form>
>>    <fb:save-form>
>>      // create a Time from the Date:
>>      var time = new java.sql.Time(widget.getValue().getTime());
>>      jxpathPointer.setValue(time);
>>    </fb:save-form>
>> </fb:javascript>
> 
> I'm almost there but it still doesn't work. Now I get:
> 
> [quote]
> org.apache.commons.jxpath.JXPathException: Exception trying to create
> xpath time; Factory
> org.apache.cocoon.forms.binding.JXPathBindingBase$BindingJXPathFactory@11185e7 
> 
> could not create an object for path: /time
> [/quote]

Hmm, that's strange, it appears JXPath isn't able to do whatever it 
needs to do to create the jxpathPointer (JXPath is still sort of voodoo 
to me ;-) ).  Are you sure the path is correct?  Are you able to save to 
other properties on your bean?

Does the load-form portion work, or are you doing save only?

Maybe try this instead (uses the bean directly rather than jxpath's 
pointer):

<fb:javascript id="time" path=".">
   <fb:load-form>
     widget.setValue(jxpathContext.getNode().getTime());
   </fb:load-form>
   <fb:save-form>
     var time = new java.sql.Time(widget.getValue().getTime());
     jxpathContext.getNode().setTime(time);
   </fb:save-form>
</fb:javascript>


> I'm not sure, but I think this does not work:
> var time = new java.sql.Time(widget.getValue().getTime());

Nah, that part should be fine.  The error is happening before the 
javascript is even being executed, while it's setting up the JXPath 
context/pointer.

> I've also tried
> var time = new java.sql.Time(widget.getValue());
> 
> and got the same result. Any ideas?
> 
> 
> BTW, I have set the path to "/" like in the bean binding examples (I
> hope that's ok):

Should be right, as long as you're saving directly to your bean.


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


Re: CForms: Time widget binding problem

Posted by Paloma Gomez <pa...@gmail.com>.
Hi Jason,

Thanks for your answer.


> You only need the converter in the binding if your target object expects
> a String representation of the widget's value, such as when you're
> binding to an XML document.  In your case you're not saving to a String
> so you don't need it.

OK, this makes things clearer :).

> You will, however, need something else to convert between the datatype
> of the widget (java.util.Date) and your bean property (java.sql.Time).
> I'm not sure if there's a better way to do it, but one approach would be
> a javascript binding:
>
> <fb:javascript id="time" path="time">
>    <fb:load-form>
>      // no conversion necessary since Time extends Date:
>      widget.setValue(jxpathPointer.getValue());
>    </fb:load-form>
>    <fb:save-form>
>      // create a Time from the Date:
>      var time = new java.sql.Time(widget.getValue().getTime());
>      jxpathPointer.setValue(time);
>    </fb:save-form>
> </fb:javascript>

I'm almost there but it still doesn't work. Now I get:

[quote]
org.apache.commons.jxpath.JXPathException: Exception trying to create
xpath time; Factory
org.apache.cocoon.forms.binding.JXPathBindingBase$BindingJXPathFactory@11185e7
could not create an object for path: /time
[/quote]

I'm not sure, but I think this does not work:
var time = new java.sql.Time(widget.getValue().getTime());

I've also tried
var time = new java.sql.Time(widget.getValue());

and got the same result. Any ideas?


BTW, I have set the path to "/" like in the bean binding examples (I
hope that's ok):

<fb:context xmlns:fd="http://apache.org/cocoon/forms/1.0#definition"
	    xmlns:fb="http://apache.org/cocoon/forms/1.0#binding" path="/" >


Thanks,

Paloma
--
Paloma Gomez

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


Re: CForms: Time widget binding problem

Posted by Jason Johnston <co...@lojjic.net>.
Paloma Gomez wrote:
> Hi all,
> 
> After having a look at the CForms samples I'm trying to create my
> first form. This is the first time I'm doing it, so maybe there are
> things I think I understand and actually  I don't ;).
> 
> I'm having problems with the binding of a time widget to a bean and I
> can't find any example of time widgets in cocoon samples. (I'm only
> interested in the time, I know there are examples with dates).
> 
> Here is the widget definition:
> 
> <fd:field id="time" required="true">
>   <fd:label>Time (hh:mm):</fd:label>
>   <fd:datatype base="date">
>     <fd:convertor datatype="date" variant="time" type="formatting">
>         <fd:patterns>
>             <fd:pattern>kk:mm</fd:pattern>
>         </fd:patterns>
>      </fd:convertor>
>    </fd:datatype>
> </fd:field>
> 
> Now the binding:
> <fb:value id="time" path="time">
>   <fd:convertor datatype="date" variant="time" type="formatting">
>       <fd:patterns>
>          <fd:pattern>kk:mm</fd:pattern>
>        </fd:patterns>
>   </fd:convertor>
>    </fd:datatype>
> </fb:value>   
> (I've tried some variants of this without success)
> 
> (There is something I don't understand well: why do I need two convertors?)

You only need the converter in the binding if your target object expects 
a String representation of the widget's value, such as when you're 
binding to an XML document.  In your case you're not saving to a String 
so you don't need it.

You will, however, need something else to convert between the datatype 
of the widget (java.util.Date) and your bean property (java.sql.Time). 
I'm not sure if there's a better way to do it, but one approach would be 
a javascript binding:

<fb:javascript id="time" path="time">
   <fb:load-form>
     // no conversion necessary since Time extends Date:
     widget.setValue(jxpathPointer.getValue());
   </fb:load-form>
   <fb:save-form>
     // create a Time from the Date:
     var time = new java.sql.Time(widget.getValue().getTime());
     jxpathPointer.setValue(time);
   </fb:save-form>
</fb:javascript>

That's just off the top of my head and untested, but hope it helps.
--Jason


> 
> And finally the bean (I include only the fragments related to this widget)
> 
> [...]
> import java.sql.Time;
> [...]
> public class EventBean {
> [...]
> private Time time;
> [...]
> public Time getTime() {
>        return time;
>    }
> 
>    public void setTime(Time time) {
>        this.time = time;
>    }
> [...]
> }
> 
> I use the datatype java.sql.Time because I want to use it to query a
> database. I don't know if this is relevant or not.
> 
> I get the following error message:
> [...]
> Caused by: org.apache.commons.jxpath.JXPathException: Cannot modify
> property: module.EventBean.time; Cannot convert value of class
> java.lang.String to type class java.sql.Time;
> org.apache.commons.beanutils.ConversionException
> 
> My system:
> * cocoon-2.1.10-dev
> * jetty
> * Ubuntu Linux
> 
> Any hints would be appreciated.
> 
> Thanks
> 
> Paloma
> 
> -- 
> Paloma Gomez
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
> 


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