cancel
Showing results for 
Search instead for 
Did you mean: 

Date field validation

Former Member
0 Kudos

Hello,

I have created a input field in my webdynpro application ...which is bounded to the context attribute of type date........at runtime it always displays the current system date.....now if i blank it out and hit the submit button ...i want to put a validation to ask the user to put in some value....but when i debugged i saw that the value still is the current system date rather than a blank value....how can i handle this and put a validation here....?

Any help would be highly appreciated...

Regards,

Anil

Accepted Solutions (1)

Accepted Solutions (1)

pravesh_verma
Active Contributor
0 Kudos

Hi Anil,

Just blank out the field will not help. Just hit the enter after that and you probelm will get solve. The reason is Webdynpro framework dont get any notification for the cleared field. As soon as you press enter after clearing the field there is framework controlled call which is send and the current values are picked in the context.

You can do one more thing to add the validation. Either on the click of the button you can add the validation logic or if you want there is action associated with a inputfield called onEnter. You can write the logic for validationon that field.

This is purely on the basis of your requirement.

I hope that helps. Please revert back in case you want any further assistance.

Thanks and Regards,

Pravesh

Former Member
0 Kudos

Hello Pravesh,

Thanks for the reply....after i blanked out the date field .....and pressed enter even then my validation was not called......

Also...if you remember in one of my other posts i wanted to remove the comma from the fields and you suggested me to create my own simple type and it's representation...that worked for it but now whenever those fields bounded to context attributes of simple type i created are blank ....the webdynpro framework calls the validations for it automatically first before any of my validations even if my validation fails along with it.....once the framework validations are passed then my validations work.....how can i avoid this...?

Murali,

I checked the wdDoInit() method and there is no code there for the date field.....please help...

Any help would be highly appreciated...

Regards,

Anil

Edited by: Anil Kumar on Jun 9, 2009 3:50 PM

nitin_mahajan2
Contributor
0 Kudos

If you have a field mapped to a attribute and you are showing a default value in it (Current System Date as in your case), you would have set it some where, please check where did you do that.

Nevertheless, the issue is not here because the behaviour is as expected.

OnSubmit Method, while reading the value from the field, try to print what is the value coming out by using componentAPI methods.

If the value is ""/"null" / null then send a exception message.

If not call the date validation.

I would want to look at your code to read the value and validate.

Regards,

Nitin

Edited by: Nitin Mahajan on Jun 9, 2009 6:07 PM

Former Member
0 Kudos

Hello Nitin,

Thanks for the reply....I have't put any code to display the default date as System Date....it is coming by default ....the only message i want to display is only when the user blanks out the field and hits the submit button....for which i have written the following code in the onAction() method of the submit button....and the value even after the user blanks the field is still the current system date....

IWDMessageManager mm =wdThis.wdGetAPI().getComponent().getMessageManager();

if(wdContext.currentContextElement().getTargetdate().toString()==null ||

wdContext.currentContextElement().getTargetdate().toString().equalsIgnoreCase(""))

mm.reportException("Please enter a value for Target Date",true);

Please help.

Regards,

Anil

pravesh_verma
Active Contributor
0 Kudos

Hi Anil,

Let me explain you in a step by step process.

1) Do not confuse this issue of date field with the Simple value set issue which you have posted earlier. That is a completly different issue. I hope for getting the date attached to your input field you would have used the datat type Date. So this is not at all related to what we did earlier. We have handled the case of imtegers in your last post.

2) Now let talk about your issue. You are having a date field but as soon as you clear some value from the inputfield by using the delete button from keyboard and hit a submit button you want to call for a validation. RIGHT??? Well this is what I said. If you use the key board for clearing the fields webdynpro framework cannot know what action you have performed. So as soon as you clear the field just hit the enter.

3) Now after hitting the enter just leave it as it is. Hitting enter ensures that a call to the framework has been initiated which has ensured that framework now know that there is a empty value in this date field.

4) The code you have given is not correct. Reason: Never use toString() funtion with the elements for checking null value. The simple reason is if by chance your element is null and you are using the toString() call you will always get a null pointer exception.

5) Use the following code in your submitt button:


IWDMessageManager mm =wdThis.wdGetAPI().getComponent().getMessageManager();


if(wdContext.currentContextElement().getTargetdate() ==null || wdContext.currentContextElement().getTargetdate().toString().equalsIgnoreCase("")){
// Please note that I have used toString() only after the NULL check. It will come to toString() call only when the value is not null, which is checked in 1st condition.
mm.reportException("Please enter a value for Target Date",true);
}

I hope this is clear now and solves your issue.

Thanks and Regards,

Pravesh

Former Member
0 Kudos

Hi Anil,

Your code seems quite correct.

But just remove the toString() in the code.Your date object should be java.util.Date.



Date Targetdate=null;    /* (Date is java.util.Date) */
Targetdate=wdContext.currentContextElement().getTargetdate();
if (Targetdate== null)
{
msgMgr.reportException("Please enter a value for Target Date",false);
}

Let me know whether your ploblem solved.

Regards,

Rajesh

Edited by: Rajesh on Jun 10, 2009 6:00 AM

Former Member
0 Kudos

Thanks for your help guys....i removed the toString() function where i am checking for null and it worked without pressing the enter key.....sorry for the confusion of the other post...

Regards,

Anil

Answers (2)

Answers (2)

Former Member
0 Kudos

HI

why dont you remove the binding from the simple type and write the validation in the onAction()

of the submit method , which can solve your problem .

Former Member
0 Kudos

Hello Murali,

I binded my own simple type for the fields since on hitting the submit button otherwise it shows the commas there if any validation fails....

Please help.

Regards,

Anil

Former Member
0 Kudos

hi

check the code once , and parameter mapping , i hope your default date code is inthe

init() method and validation code in the onAction of the submit ,then there should not be any problem

when you make the field blank and validate the date ,