cancel
Showing results for 
Search instead for 
Did you mean: 

How to check the inpufield ?

Former Member
0 Kudos

<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>

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

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.

http://jakarta.apache.org/commons/validator/apidocs/org/apache/commons/validator/GenericValidator.ht...

Best regards,

Marcus

Former Member
0 Kudos

No. I'm very surprise to get this value ("0000-00-00") when the field is empty. I just want to know if it is normal or not.

Former Member
0 Kudos

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.

Former Member
0 Kudos

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

Former Member
0 Kudos

Sorry that don't solve my problem. I want to check the value in server side.

Former Member
0 Kudos

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

Former Member
0 Kudos

Is there no other way to do this ? Your supposition is that the date pattern is always "yyyy-MM-dd" ? Any idea about the use of "validator" in HTMLB ?

Regards.

Former Member
0 Kudos

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