cancel
Showing results for 
Search instead for 
Did you mean: 

Validations

Former Member
0 Kudos

Hi

I want to put some validations on a input field to check whether empty or not.

How to do this.

Thanks

Monika

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos