on 2007 Jul 11 6:09 PM
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
Hi
Set the state property to "required".
Regards
Ayyapparaj
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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>
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
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
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.
User | Count |
---|---|
69 | |
9 | |
8 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.