Werner Punz schrieb:
Here is a custom facelet component I have written a while ago...
<ui:composition>
<t:dojoInitializer require="dojo.widget.DropdownDatePicker" />
<t:inputText value="#{entity[fieldName]}" id="#{id}" forceId="true" >
<s:convertDateTime pattern="dd.MM.yyyy"/>
</t:inputText>
<script type="text/javascript">
var #{id}_value = dojo.byId("#{id}").value;
if(!#{id}_value)
#{id}_value = "";
dojo.widget.createWidget("DropdownDatePicker",{widgetId:
"#{id}_dojoWidget", inputId: "#{id}", inputName: "#{id}",
dateFormat:"%d.%m.%Y"
},dojo.byId('#{id}'));
dojo.widget.byId("#{id}_dojoWidget").inputNode.value = #{id}_value;
</script>
</ui:composition>
usage:
<ir:dojodatepicker id="fromDate"
entity="#{appointmentdetailview}"
fieldName="startDate" />
>
Ok sorry for the formatting errors, but what happens is just basically
that the date picker is bound to an input text component, which then is
utilized by jsf itself (The programmatic approach is chosen because it
allows speed optimizations by turning the dojo parsing off (basically
factor 2-4 on some pages)
the main problem is that facelets are view only hence the
#{entity[fieldName]} construct to pass the values properly, secondly
we deal with two different date format definitions here
<s:convertDateTime pattern="dd.MM.yyyy"/> on the java side
and
dateFormat:"%d.%m.%Y" on the dojo side, both basically doing the same
As for speed optimizations I have not blogged this and have not adjusted
the examples but since MyFaces has been using programmatic only creation
of components for quite a while:
following will give another speed boost:
<t:dojoInitializer parseWidgets="false" searchIds="[]" />
this turns off the dojo page parsing entirely...
if you need to turn it on selectively, add the ids of the divs or
controls you want to have parsed to the searchids list
like following:
<t:dojoInitializer parseWidgets="false" searchIds="['divid1','divid2']" />