on 04-26-2005 2:33 PM
<b><i>Hi all</i></b>,
I wrote a JSP using inputField htmlb like this:
<hbj:inputField id="inputDateDebut" type="date" showHelp="TRUE" maxlength="10" size="10"/>
Now I want to check the value and good format of the inputfield submit in the form but don't know how to do that ? When the field is empty and posted I get the value "0000-00-00" ! Is there a good way or document on the validator for inputfiled please ? How do you do usually?
<b><i>Best regards.</i></b>
Hi,
probably you are searching for something like this?
Put in any string and a locale. The method checks if it is a valid date.
Best regards,
Marcus
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi tafkap,
Normal is a matter of taste, and maybe if you would have
written HTMLB it would look more "normal" to us (and
probably less to others), but that's the way it's implemented.
Think of it like the case when the user entered 3 spaces
in an InputField and you have to check that
!enteredValue.trim().equals("").
The same way here, but the check is for equality to "0000-00-00".
Not very elegant, but I don't think there is any way around it...
Yoav.
Hi Guillaume,
I would propose using the Date Navigator ...
http://help.sap.com/saphelp_nw04/helpdata/en/aa/9b0e41a346ef6fe10000000a1550b0/frameset.htm
this way the user can't insert an invalid date and thus is never confronted with an error message
(and you don't have to care either).
Otherwise you can check values with the JavaScript API ...
http://help.sap.com/saphelp_nw04/helpdata/en/43/067941a51a1a09e10000000a155106/frameset.htm
or within your application that receives the data.
Best regards,
Kilian
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Guillaume,
at the server side this is even easier. You can use an instance of java.text.SimpleDateFormat
and parse the date string somehow like this:
import java.text.*;
import java.util.Date;
try {
DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
Date date = (Date)format.parse("0000-00-00");
} catch (ParseException e) {
System.out.println(e.getMessage());
// or whatever ...
}
You may also call
format.setLenient(false);
so that the interpretation of the date is more strict. For details hava a look at ...
http://java.sun.com/j2se/1.4.2/docs/api/java/text/SimpleDateFormat.html
Best regards,
Kilian
Hi Guillaume,
my supposition is that the date pattern is what you define it to be, you can also write more complicated code
that checks for several patterns ...
As I understand the validator classes in HTMLB, they are a framework for managing Java Script code and localized
error messages for field validation. When you have a look at the respective classes in the API documentation
of com.sapportals.htmlb.validation you will find no details about any data types or formats.
I think that these details are part of the business logic that has to be implemented by the developer.
Have a look at page 8 of this excellent article by Bill Guderian, he comes to a similar conclusion:
https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/ep/advanced techniques in sap html business.pdf
Best regards,
Kilian
User | Count |
---|---|
87 | |
10 | |
10 | |
9 | |
7 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.