A typical user would say that the easiest display for Dates is 3 text fields
holding day, month and year (at least mine did...). So I think to achieve
this all you have to do is create a form JavaBean that gets dates in this
format ((int, int, int) | (int, String, int)) and uses a SimpleDateFormat
instance to parse these into a Date object that it offers via an accessor
method. Transformation can be done lazily or eagerly as long as the
validation happens in the right time.
something like this:
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
...
public void setOrderDay(int orderDay) { this.orderDay = orderDay; }
public int getOrderDay() {return this.orderDay; }
public void setOrderMonth(int orderMonth) { this.orderMonth =
orderMonth; }
public int getOrderMonth() {return this.orderMonth; }
public void setOrderYear(int orderYear) { this.orderYear = orderYear; }
public int getOrderYear() {return this.orderYear; }
public Date getOrderDate() {
Date result = null;
if(!(orderDay == 0 || orderMonth == 0 || orderYear == 0)) {
try {
result = dateFormat.parse(orderDay + "/" + orderMonth
+ "/" +
orderYear);
}
catch(ParseException pe) {pe.printStackTrace();}
}
return result;
}
public void setOrderDate(Date orderDate) {
String orderStr = dateFormat.format(orderDate);
StringTokenizer tokens = new StringTokenizer(orderStr, "/");
try {
orderDay = Integer.parseInt(tokens.nextToken());
orderMonth = Integer.parseInt(tokens.nextToken());
orderYear = Integer.parseInt(tokens.nextToken());
}
catch(NumberFormatException nfe) {
nfe.printStackTrace();
}
}
...
zm.
-----Original Message-----
From: A mailing list for discussion about Sun Microsystem's Java Servlet API
Technology. [mailto:[EMAIL PROTECTED]]On Behalf Of Matthias
Hanel
Sent: Friday, February 22, 2002 3:01 PM
To: [EMAIL PROTECTED]
Subject: What is the best way to get a Date
from a formular?
Is there a way to set the inputtype of a formular to date?
There is no Javascript.
----------------------------------------------------------------------------
----------------
Hanel Matthias
Fachinformatiker (Anwendungsentwicklung) in Ausbildung
Logistik World GmbH Fon: +49-841-9014-300
Marie-Curie-Strasse 6 Fax: +49-841-9014-302
D- 85055 Ingolstadt mailto:[EMAIL PROTECTED]
----------------------------------------------------------------------------
----------------
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html