Hi Simone

Your explanation is straight forward and made things clear to me.

Thank you very much!
Stefan

------------------------------------------------



Simone Gianni <[EMAIL PROTECTED]>

19.07.2006 17:54

Bitte antworten an
[email protected]

An
[email protected]
Kopie
Thema
Re: formatting problems with dates in flow-jxpath selection-list





Hi Stefan,
there seems to be a bit of confusion regarding where and how convertors
are used.

Convertors are used in 3 places :
- In the definition datatype
- In the definition selection-lists
- In the binding

In these 3 places cocoon forms needs to make a conversion between a
native datatype and a string, in particular :
- In the definition datatype it's converting from the form field value
and its representation in the HTML, which is actually a string
- In the selection lists it's transforming between a java value and the
HTML select value, which is a string
- In the binding it's converting between the form field value and its
representation in the XML, which is again a string :)

As you can see, convertors are not used for selection list labels,
because a selection list is a Map (represented by a Map object in java,
a _javascript_ associative array or an XML fragment) of value->label,
where label is already a String and does not need any conversion. When a
label is not provided, the value.toString() method is used.

So the problem is not in the convertor, but in the way you build the
selection list from _javascript_ :

       g_listData.receptionDate[i] = {value:element, label:element};

As you can see you are using the Date object both as value and as label,
the convertor only works on the value, you have to format the label
yourself in _javascript_. This can be accomplished in many ways, I can't
remember which facilities _javascript_ offers but alternatively you can
use the common java SimpleDateFormat simply instantiating it with var
formatter = new Packages.java.text.SimpleDateFormat('dd.MM.yy'); and
then using as it java, formatter.format(element) IIRC.

Hope this helps,
Simone



[EMAIL PROTECTED] wrote:

>
> Hello
>
> Does somebody know a solution for the problem described further down?
> Or has sombody an idea for a work-around?
>
> Help is very welcome and aprechiated a lot!
>
> Thanks in advance!
> Stefan
>
>
> Problem description
> ==============
> We want to display a selection list with various dates from which the
> user can select exactly one date. The user selection serves as a
> filter for a list of orders.
>
> The selection list displays on the html-page and works fine, B U T
>  the labels are not transformed according to the pattern (dd.MM.yy) we
> defined in the model.xml. The labels are still in the format
> 2006-06-02 00:00:00.0 (like they were without any transformation).
>
>
> Actual code (Java version: 1.4.2_12, Cocoon version: 2.1.9)
> ==========
>
> sitemap.xmap:
> ...
> <map:match pattern="*-display-pipeline">
>   <map:generate src=""> >   <map:transform type="forms"/>
>   <map:transform type="i18n">
>     <map:parameter name="locale" value="de_CH"/>
>   </map:transform>
>   <map:transform src=""> >   <map:transform type="jx"/>
>   <map:transform type="i18n">
>     <map:parameter name="locale" value="de_CH"/>  
>   </map:transform>
>   <map:serialize type="html"/>
> </map:match>
> ...
>
>
> filter.js:
> ...
> //prepare the list with the available reception dates
>
> max = g_orderForm.getReceptionDate().size();
> g_listData.receptionDate = new Array(max);
> iter = g_orderForm.getReceptionDate().iterator();
> i = 0;
>                
> while(iter.hasNext()) {
>         //NOTE: element is of datatype="date"
>         element = iter.next();
>         g_listData.receptionDate[i] = {value:element, label:element};
>         i++;
> }
> ...
> form.showForm("filter-disply-pipeline", {"g_listData":g_listData});
>
>
> filter_model.xml:
> ...
> <fd:field id="filter_receptionDate">
>   <fd:datatype base="date"/>
>   <fd:selection-list type="flow-jxpath"
> list-path="g_listData/receptionDate" value-path="value"
> label-path="label" datatype="date" null-text="*">
>     <fd:convertor type="formatting">
>       <fd:patterns>
>         <fd:pattern>dd.MM.yy</fd:pattern>
>             </fd:patterns>
>     </fd:convertor>                  
>   </fd:selection-list>
> </fd:field>
> ...
>
> filter_template.xml
> ...
> <td>
>   <ft:widget id="filter_receptionDate">
>     <fi:styling class='filter' size='1'
> > >   </ft:widget>
> </td>
>
>
>
>
--
Simone Gianni

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


Reply via email to