cancel
Showing results for 
Search instead for 
Did you mean: 

Validate null values in web dynpro for Java

Former Member
0 Kudos

Hi guys,

I want to perform a mandatory field value check in a web dynpro input field. I have cretaed an application and want to ensure that user entered values into it, before it can processed further. I do not think there is/are any property avialable for this.

Any help on how to code.

Thanks a lot in advance.

regards

Sam

Message was edited by:

sameer chilama

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Sameer,

Try this out,

try

{

String name = wdContext.current<ContextNodeName>Element.getName();

...

}

catch(NullPointerException e)

{

wdcomponentAPI.getMessageManager().reportException("Cannot enter a null value", true);

}

You can do it for all types of contexts..

Hope it helps you..

Regards,

Alka

Answers (4)

Answers (4)

Former Member
0 Kudos

i got it

Former Member
0 Kudos

Guys,

What if my value is a standard code and is assigned to a model node and subsequently model attribute. How fo i get the value of this?

regards

Sam

Former Member
0 Kudos

Hi Sameer,

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 for example onAction of button.

onAction:

String name= null;

name = wdContext.currentContextElement().getname();

if (name == null || name= .trim().length() == 0) {

wdComponentAPI.getMessageManager().reportException(

"Name cannot be left blank",true);

} else{

<Perform the required logic>

}

Regards,

Jhansi

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.