You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Alex Kovacs <al...@fast.fujitsu.com.au> on 2004/02/10 09:03:08 UTC
Problem with date format for a woody widget in xsp
Hi,
I am using cocoon-2.1.3 with Woody. I have a situation where I am using xsp
to display some data from a Woody form. The problem is when trying to
display the value of a date widget and the date format is the default one
instead of the one set in the widget definition. I have the following
configuration (using xml binding):
Widget definition:
...
<wd:field id="start_date">
<wd:datatype base="date">
<wd:convertor type="formatting">
<wd:patterns>
<wd:pattern>dd/MM/yyyy</wd:pattern>
</wd:patterns>
</wd:convertor>
</wd:datatype>
<wd:label>Start Date</wd:label>
</wd:field>
...
The confirm.xsp file:
...
<xsp:logic>
//Fetching the form from the request attribute
Form form = (Form)request.getAttribute("theform");
Field start_date = (Field)form.getWidget("start_date");
</xsp:logic>
...
<item>
<xsp:expr>start_date.getValue()</xsp:expr>
</item>
...
And the output is in the form of: "Tue Feb 10 00:00:00 EST 2004", instead of
"10/02/2004".
Can anyone help?
Rgds
Alex
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: Problem with date format for a woody widget in xsp
Posted by Alex Kovacs <al...@fast.fujitsu.com.au>.
Hi Tony,
Thanks for the help, I will try it and let you know how it worked.
Rgds,
Alex
----- Original Message -----
From: "Tony Edwards" <te...@civica.com.au>
To: <us...@cocoon.apache.org>
Sent: Wednesday, February 11, 2004 9:42 AM
Subject: Re: Problem with date format for a woody widget in xsp
> Hi Alex,
> I had a similar problem saving data back to a MySql database. The
> database only recognises dates in yyyy-MM-dd format and the flowscript
> was outputting dates like so:
> EEE, d MMM yyyy HH:mm:ss Z (the same as your issue).
> I fiddled with the <wd:convertor> settings but it didn't change the
> resulting format being sent to the database.
> To solve the problem I downloaded a date formatting javascript library
> from Matt Kruse (WWW: http://www.mattkruse.com/) called date.js (funny
> that).
> It was then just a simple call to a formatting method and the record was
> written without complaint.
> Another more xsp-centric solution is to include the following code in
> your xsp page:
> <xsp:page>
> <xsp:structure>
> <xsp:include>java.util.Date</xsp:include>
> <xsp:include>java.util.Calendar</xsp:include>
> <xsp:include>java.lang.Integer</xsp:include>
> <xsp:include>java.util.GregorianCalendar</xsp:include>
> <xsp:include>java.text.SimpleDateFormat</xsp:include>
> <xsp:include>java.lang.String</xsp:include>
> </xsp:structure>
>
> <xsp:logic>
> <![CDATA[
> public static String formatDate(Date value, String format) {
> SimpleDateFormat formatter;
> format = format.trim();
> if (format != null && !"".equals(format)) {
> formatter = new SimpleDateFormat(format);
> }
> else {
> formatter = new SimpleDateFormat();
> }
>
> return formatter.format(value);
> }
> </xsp:logic>
> <content>
> <para>Select 'Add' or 'View' from the options then
> select the month and year for the notice:</para>
> <para>Today's date is <xsp:expr>formatDate(new Date(),
> "dd-MMM-yyyy")</xsp:expr></para><br/>
> </content>
> </xsp:page>
> Hope this helps,
> Regards,
> Tony
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: Problem with date format for a woody widget in xsp
Posted by Tony Edwards <te...@civica.com.au>.
Hi Alex,
I had a similar problem saving data back to a MySql database. The
database only recognises dates in yyyy-MM-dd format and the flowscript
was outputting dates like so:
EEE, d MMM yyyy HH:mm:ss Z (the same as your issue).
I fiddled with the <wd:convertor> settings but it didn't change the
resulting format being sent to the database.
To solve the problem I downloaded a date formatting javascript library
from Matt Kruse (WWW: http://www.mattkruse.com/) called date.js (funny
that).
It was then just a simple call to a formatting method and the record was
written without complaint.
Another more xsp-centric solution is to include the following code in
your xsp page:
<xsp:page>
<xsp:structure>
<xsp:include>java.util.Date</xsp:include>
<xsp:include>java.util.Calendar</xsp:include>
<xsp:include>java.lang.Integer</xsp:include>
<xsp:include>java.util.GregorianCalendar</xsp:include>
<xsp:include>java.text.SimpleDateFormat</xsp:include>
<xsp:include>java.lang.String</xsp:include>
</xsp:structure>
<xsp:logic>
<![CDATA[
public static String formatDate(Date value, String format) {
SimpleDateFormat formatter;
format = format.trim();
if (format != null && !"".equals(format)) {
formatter = new SimpleDateFormat(format);
}
else {
formatter = new SimpleDateFormat();
}
return formatter.format(value);
}
</xsp:logic>
<content>
<para>Select 'Add' or 'View' from the options then
select the month and year for the notice:</para>
<para>Today's date is <xsp:expr>formatDate(new Date(),
"dd-MMM-yyyy")</xsp:expr></para><br/>
</content>
</xsp:page>
Hope this helps,
Regards,
Tony
Alex Kovacs wrote:
>Hi,
>
>I am using cocoon-2.1.3 with Woody. I have a situation where I am using
>xsp
>to display some data from a Woody form. The problem is when trying to
>display the value of a date widget and the date format is the default
>one
>instead of the one set in the widget definition. I have the following
>configuration (using xml binding):
>
>Widget definition:
> ...
> <wd:field id="start_date">
> <wd:datatype base="date">
> <wd:convertor type="formatting">
> <wd:patterns>
> <wd:pattern>dd/MM/yyyy</wd:pattern>
> </wd:patterns>
> </wd:convertor>
> </wd:datatype>
> <wd:label>Start Date</wd:label>
> </wd:field>
> ...
>
>
>The confirm.xsp file:
> ...
> <xsp:logic>
> //Fetching the form from the request attribute
> Form form = (Form)request.getAttribute("theform");
> Field start_date = (Field)form.getWidget("start_date");
> </xsp:logic>
> ...
> <item>
> <xsp:expr>start_date.getValue()</xsp:expr>
> </item>
> ...
>
>And the output is in the form of: "Tue Feb 10 00:00:00 EST 2004",
>instead of
>"10/02/2004".
>
>Can anyone help?
>Rgds
>Alex
>
>
>
>---------------------------------------------------------------------
>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
Re: Problem with date format for a woody widget in xsp
Posted by Bruno Dumon <br...@outerthought.org>.
On Tue, 2004-02-10 at 09:03, Alex Kovacs wrote:
> Hi,
>
> I am using cocoon-2.1.3 with Woody. I have a situation where I am using xsp
> to display some data from a Woody form. The problem is when trying to
> display the value of a date widget and the date format is the default one
> instead of the one set in the widget definition. I have the following
> configuration (using xml binding):
>
> Widget definition:
> ...
> <wd:field id="start_date">
> <wd:datatype base="date">
> <wd:convertor type="formatting">
> <wd:patterns>
> <wd:pattern>dd/MM/yyyy</wd:pattern>
> </wd:patterns>
> </wd:convertor>
> </wd:datatype>
> <wd:label>Start Date</wd:label>
> </wd:field>
> ...
>
>
> The confirm.xsp file:
> ...
> <xsp:logic>
> //Fetching the form from the request attribute
> Form form = (Form)request.getAttribute("theform");
> Field start_date = (Field)form.getWidget("start_date");
> </xsp:logic>
> ...
> <item>
> <xsp:expr>start_date.getValue()</xsp:expr>
> </item>
> ...
>
> And the output is in the form of: "Tue Feb 10 00:00:00 EST 2004", instead of
> "10/02/2004".
>
> Can anyone help?
The start_date.getValue() call returns a Date object, so the date you're
seeing it the default Date.toString() behaviour of Java.
Unfortunately, AFAIK, there's currently no method on the Field widget to
retrieve its converted string value (it's only part of the generated
XML). Seems useful to me though, and would only be 3 lines of code.
--
Bruno Dumon http://outerthought.org/
Outerthought - Open Source, Java & XML Competence Support Center
bruno@outerthought.org bruno@apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org