cocoon-docs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From stev...@outerthought.org
Subject [WIKI-UPDATE] XSP+TransformCustomDate XSPTransformCustomDate HowTos Mon Feb 3 02:01:04 2003
Date Mon, 03 Feb 2003 01:01:04 GMT
Page: http://wiki.cocoondev.org/Wiki.jsp?page=XSP+TransformCustomDate, version: 1 on Mon Feb
 3 00:03:10 2003 by Scherler

New page created:
+ If you are using <esql/> you may need to transform a custom date string to a valid
Java Date object.
+ 
+ Here is an example:
+ {{{
+ <esql:query>
+ select * from reports  where date = #<xsp-request:get-parameter name="date"/>#
+ </esql:query>
+ }}}
+ 
+ The actual date of the <esql:query/> has to be in the format e.g. 01/29/2003, but
if you are a in e.g. Germany you are used to this date format: 29.01.2003.
+ 
+ __Step 1__
+ Create a HTML-Form save it as date.html in your cocoon-webapp dir.
+ {{{
+ <html>
+ <head>
+ <meta name="author"content="ThorstenScherler">
+ <title>TransformCustomDate</title>
+ </head>
+ <body>
+ <p>Please press Submit.</p>
+ <form action="date.xml" method="GET">
+ <input type="text" name="date" value="29.01.2003"/>
+ <input type="submit" value="Submit"/>
+ </form>
+ </body>
+ </html>
+ }}}
+ On submit this will result in attaching __/date.xml?date=29.01.2003__ to the uri where the
html form was called from.
+ 
+ __Step 2__
+ Create a file date.xsp and put this in your cocoon-webapp dir.
+ {{{
+ <xsp:page language="java" xmlns:xsp="http://apache.org/xsp">
+ <xsp:structure>
+ <xsp:include>java.util.*</xsp:include>
+ <xsp:include>java.text.*</xsp:include>
+ </xsp:structure>
+ <document>
+ <xsp:logic>
+ String datePattern = "dd.MM.yyyy";
+ SimpleDateFormat dateFormat = new SimpleDateFormat( datePattern );
+ String sDate_one ="";
+  try
+ {
+  sDate_one=request.getParameter("date");
+   }
+  catch( ParseException e )
+ {
+  getLogger().error("XSP param error: ", e);
+ }
+ Date date_one = null;
+  try
+ {
+     date_one = dateFormat.parse( sDate_one );
+ }
+ catch( ParseException e )
+ {
+  getLogger().error("XSP date error: ", e);
+ }
+ </xsp:logic>
+ <request>date.xml?date=<xsp:expr>sDate_one</xsp:expr>
+ </request>
+ <transformed>
+ <xsp:expr>date_one</xsp:expr>
+ </transformed>
+ </document>
+ </xsp:page>
+ }}}
+ 
+ __Step 3__ put this in your cocoon-webapp sitemap.xmap
+ {{{
+ <map:pipeline>
+ <map:match pattern="date">
+ <map:read src="date.html"/>
+ </map:match>
+ <map:match pattern="date.xml">
+ <map:generate type="xsp" src="date.xsp"/>
+ <map:serialize type="xml"/>
+ </map:match>
+ </map:pipeline>
+ }}}
+ 
+ __Testing__
+ Now request {{{http://localhost:8080/cocoon-webapp/date}}} and press the Submit-Button.
+ 
+ If everything works fine you will see a XML-page with a valid date.
+ If not - please check the logs.
+ 
+ __Modifying the date-Format__
+ {{{
+ String datePattern = "dd.MM.yyyy";
+ }}}
+ If you wish to modify the date-format please see [SimpleDateFormat Class Reference|http://oss.software.ibm.com/icu/apiref/classSimpleDateFormat.html].
+ 
+ Giving you an idea of how to do it:
+ {{{
+ String datePattern = "MM/dd/yyyy";
+ }}}
+ expect 01/31/2003 as the string-format.
+ 
+ Please let me know if you had problems with it? [Thorsten Scherler|Scherler]
+ 


Page: http://wiki.cocoondev.org/Wiki.jsp?page=XSPTransformCustomDate, version: 2 on Mon Feb
 3 00:06:07 2003 by Scherler

- Please let me know if you had problems with it? [Thorsten Scherler|Scherler]
?                                               ^

+ Please let me know if you had problems with it. [Thorsten Scherler|Scherler]
?                                               ^



Page: http://wiki.cocoondev.org/Wiki.jsp?page=HowTos, version: 56 on Mon Feb  3 00:08:52 2003
by Scherler

- * __[XSP TransformCustomDate]__ -- How to create a java date object from a date string from
a request-- [Scherler]
?                                                                                        --------------

+ * __[XSP TransformCustomDate]__ -- How to create a java date object from a date string --
[Scherler]



Mime
View raw message