cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jason Johnston <coc...@lojjic.net>
Subject Re: CForms: Time widget binding problem
Date Thu, 13 Jul 2006 04:03:51 GMT
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


Mime
View raw message