cancel
Showing results for 
Search instead for 
Did you mean: 

Mandatory for Date field

Former Member
0 Kudos
137

Hi All,

I want to display to Mandatory field if date field is blank or null...

But this code only valiadate ,the Entered date correct or not...

So how to display the Mandatory date field..

Please suggest me ...What is the error..

IWDMessageManager msgMgr = wdComponentAPI.getMessageManager();

Object attributeValue = wdContext.currentDateFieldsElement().getAttributeValue(fieldName);

Date theDate =

(Date) wdContext.currentDateFieldsElement().getAttributeValue(

fieldName);

IWDAttributeInfo attributeInfo =

wdContext.nodeDateFields().getNodeInfo().getAttribute(fieldName);

Calendar c = Calendar.getInstance();

c.set(Calendar.HOUR_OF_DAY, 0);

c.set(Calendar.MINUTE, 0);

c.set(Calendar.SECOND, 0);

c.set(Calendar.MILLISECOND, 0);

Date currentDate = new Date(c.getTimeInMillis());

if (theDate.before(currentDate)) {

{

// Throw an error message

msgMgr.reportContextAttributeMessage(

wdContext.currentDateFieldsElement(),

attributeInfo,

IMessageRequisitionForm.MISSING_INPUT,

new Object[] { fieldLabel },

true);

}

}

}

Please Tel me ......

Thanks & regards

Mathi

View Entire Topic
Former Member
0 Kudos

Hi

Set the state property to "required".

Regards

Ayyapparaj

Former Member
0 Kudos

Thanks For ur REply....

I mentioned inputfield "Required"....

But it is not worked....

Please help me & sugeest me.....

Thanks & regards

Mathi

Former Member
0 Kudos

Hi,

Was there any red * near to the label of the text box.

Do you have any validation event ?

Regards

Ayyapparaj

Former Member
0 Kudos

Hi,

Thanks for ur reply...

I tel u what i do..

1.first i set property...(reauired and set th label for)

2.i code in method take a current date

IWDMessageManager msgMgr = wdComponentAPI.getMessageManager();

Object attributeValue =

wdContext.currentDateFieldsElement().getAttributeValue(fieldName);

Date theDate =

(Date) wdContext.currentDateFieldsElement().getAttributeValue(

fieldName);

IWDAttributeInfo attributeInfo =

wdContext.nodeDateFields().getNodeInfo().getAttribute(fieldName);

Calendar c = Calendar.getInstance();

c.set(Calendar.HOUR_OF_DAY, 0);

c.set(Calendar.MINUTE, 0);

c.set(Calendar.SECOND, 0);

c.set(Calendar.MILLISECOND, 0);

Date currentDate = new Date(c.getTimeInMillis());

if (theDate instanceof Date) {

<b>removeLeadingZeroes</b>(

wdContext.currentDateFieldsElement().getAttributeAsText(

fieldName));

if (theDate.before(currentDate))

{

// Throw an error message

msgMgr.reportContextAttributeMessage(

wdContext.currentDateFieldsElement(),

attributeInfo,

IMessageRequisitionForm.DATE_IS_IN_PAST,

new Object[] { fieldLabel },

true);

}

}

public java.lang.String <b>removeLeadingZeroes</b>( java.lang.String fieldName )

{

if (fieldName == null)

return null;

int i = 0;

int n = fieldName.length();

while (i < n) {

if (fieldName.charAt(i) != '0')

break;

++i;

}

return fieldName.substring(i);

}

if could not give removeLeadingZeroes it produced error (runtime exception) (Null pointer exception)..

My Question is...Mandatory is worked if date is incorrect....

I want to set mandatory if that field name is null or balnk...

Please suggest me ....what is my mistake...

Thanks & regards

Mathi

Former Member
0 Kudos

If you could change the data type of your text box to date. you dont need this much of code and every thing will work fine

Former Member
0 Kudos

Hi,

Check out the tutorial for date validation

<a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/webdynpro/wd%20java/wd%20tutorials/a%20simple%20input%20form%20with%20message%20and%20error%20service%20support.pdf">A simple input form</a>

Former Member
0 Kudos

Hi

Thanks For ur reply...

I agree with your suggestion but if date is prevoius or future means it give madatory....

If i remove the date and click button,

It will produce mandatory like red color...

for ex:

you sugessted like

07/12/2007 -->past date or future date it will give mandatory

but i want

07/12/2007 -->there is date

I remove the date

then i go click button i will gine mandatory..(if field is blank)

Is it possible.....

Thanks & regards

Mathi

Former Member
0 Kudos

Yes make your action Validating

Go to the actions tab and check the validation

Former Member
0 Kudos

Hi,

I tried but not worked....

Please help me....

please tel me what is my mistake...

Thanks & regards

Mathi s

Former Member
0 Kudos

Hi,

In the Simple Input From check out the validation done for <i>Name</i> field.

it checks for null or no input.Same way do it for your date field.

Former Member
0 Kudos

Hi,

Thanks for ur reply..

If i entered value wrong(wrong date) value means the date field is worked...

But how validate the field... i also checked the field name null ..but it is not worked..

Is it possible..

If possible,Please suggest me...

thanks &regards

Mathi s

Former Member
0 Kudos

Hi Mathi,

Check whether the condition is executing by printing some custom message

For ex:-

if (theDate.before(currentDate))

{

wdComponentAPI().getMessageManager().reportWarning("Date is befor current Date");

}

Also, are u using datefield inside a table? If not, make the cardinality of DateFields node to 1.1

Regadrs

Fahad Hamsa

Former Member
0 Kudos

Hi

Thanks For reply..

If date field is blank,that field is mandatory...

Is it possible....

Pease tel me

Former Member
0 Kudos

Hi,

For your mandatory check of the date input,in the action

if(wdContext.currentContextElement().getDate()==null)

{

wdComponentAPI.getMessageManager().reportException("Date is null",false);

}

Date is a value attribute of type Date under the context.

Former Member
0 Kudos

Hi,

I want to know one thing....

Is mandatory applicable for date field..or not(if blank)

Please tel me.....

Former Member
0 Kudos

Hi Mathi,

Nobody here is able to understand what you need ?

What is requirement if you can explain properly elaborately may be we can help you ?

<b>Is mandatory applicable for date field..or not(if blank)</b>

What do you mean by that ?

Former Member
0 Kudos

Hi,

Very Sorry That means like red color mandatory...

is there any possibilities,if the date field is null it will be come as mandatory....

ok very thanks......

Former Member
0 Kudos

Hi,

You can get the Mandatory Red color asterik sign.

Create a inputfield and a label.Set the labeFor property of label to the inputField.

Create a context attribute "state" of type "com.sap.ide.webdynpro.uielementdefinitions.State" and map to the state property of the InputField.

Now in your action when the date field is null

if(wdContext.currentContextElement().getDate()==null)

{

wdComponentAPI.getMessageManager().reportException("Date is null",true);

wdContext.currentContextElement().setState(WDState.REQUIRED);

}

And if you want the outline of the InputField to be red as in the tutorial then you have to use

reportContetxAttributeMessage method of the Message Manager as explained in the Tutorial.

Hope this will solve your problem.

Former Member
0 Kudos

Hi,

Hi Thanks for ur reply...

Could u see my Previuos thread "Client user =Input field"....

Please suggest me what is the error and how to rectify that...

Thanks & regards

Mathi