jeudi 12 mars 2015

CQ-Getting date and time as raw strings using xtype="datetime"



I am pretty new to CQ and I am adding a new field to an existing form. I want to accept a date and time from the component dialog as strings. If I use xtype="datefield" and xtype="timefield" separately, I can get the date and time as strings just the way I need it. But, the UI looks bad and non-intiutive with two separate fields placed one below the other.


dialog.xml:



<startDate
jcr:primaryType="cq:Widget"
fieldLabel="Event Start Date"
fieldDescription="Select a date "
emptyText="Event start date "
name="./startDate"
format="d/m/Y"
xtype="datefield" />
<startTime
jcr:primaryType="cq:Widget"
fieldLabel="Event Start Time"
fieldDescription="Select a time "
emptyText="Event start time "
name="./startTime"
xtype="timefield" />


Java code in controller:



@Property(path = "startDate")
private String startDate;

@Property(path = "startTime")
private String startTime;


If I use xtype="datetime", the UI looks the way I like but the value is converted to UTC into a Date field.


dialog.xml



<startDateTime
jcr:primaryType="cq:Widget"
fieldLabel="Start Date &amp; Time"
name="./startDateTime"
dateFormat="d/m/Y"
xtype="datetime"/>


Java code in controller:



@Property(path = "startDateTime")
private Date startDateTime;


This is of no use to me as I need the date and time as raw strings, the way they were entered. The valueAsString option looked promising but does not give me date and time as strings. How can I achieve this?


Thanks in Advance




Aucun commentaire:

Enregistrer un commentaire