on 02-02-2007 4:35 AM
Hi
I want to put some validations on a input field to check whether empty or not.
How to do this.
Thanks
Monika
Hi,
this is common code for test the Whether the input field is empty then we have to display the error.
Add the attribute in the context.
public void checkMandatory( java.lang.String displayName, java.lang.String fieldContextID )
{
//@@begin checkMandatory()
IWDMessageManager messageMgr =wdThis.wdGetAPI().getComponent().getMessageManager();
String attributeValue = wdContext.currentContextElement().getAttributeAsText(fieldContextID);
IWDAttributeInfo attributeInfo =wdContext.getNodeInfo().getAttribute(fieldContextID);
if (attributeValue != null)
attributeValue = attributeValue.trim();
if (attributeValue.length() == 0) {
//String fieldLabel = this.wdContext.getNodeInfo().getAttribute(displayName).getSimpleType().getFieldLabel();
messageMgr.reportContextAttributeMessage(wdContext.currentContextElement(),attributeInfo,
IMessageOrderStatusApplication.EMPTY_INPUT,
new Object[] { displayName },
true);
}
//@@end
}
in on action write the code like
this.checkMandatory("Please enter the inputvalue","contextattributename");
wdComponentAPI.getMessageManager().raisePendingException();
it you want to add for more input fields
add second contexzt attribute
this.checkMandatory("Please enter the secondinputvalue","contextattributename1");
wdComponentAPI.getMessageManager().raisePendingException();
thanks,
Lohi.
Message was edited by:
Lohitha M
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Monika,
When you want to validate input filed there shoule be some action to be performed.
For example if you have a value attribute named "Name" and you have bounded that to an Input Filed then you can perform the following logic to validate that input field onAction of something.
String name= null;
name = wdContext.currentContextElement().getname();
if (name == null || name= .trim().length() == 0) {
wdComponentAPI.getMessageManager().reportException(
"Name cannot be left blank",
true);
}else{
-
}
Regards,
Jhansi
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Monika,
Even I am new to Web Dynpro.. so I can suggest a simple method.
I assume you must have binded the input field with a context.
You can put the code where u are accessing this context into a TRY block and catch the NullPointer exception for that.
and in the catch block you can print an adequate message with the following code:
wdCompontAPI.getMessageManager().reportException("Message",true);
I hope this helps you....
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Monika,
I suggest you to go through sample applications.
https://www.sdn.sap.com/irj/sdn/downloaditem?rid=/library/uuid/1aaae990-0201-0010-49a7-cc792a943ba1
https://www.sdn.sap.com/irj/sdn/downloaditem?rid=/library/uuid/28a7bed1-0401-0010-d181-f0d3292eab7e
Reagrds, ANilkumar
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
86 | |
10 | |
10 | |
9 | |
6 | |
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.