cancel
Showing results for 
Search instead for 
Did you mean: 

Mandatory check problem

Former Member
0 Kudos

Hi everyone,

I have some code to check if the mandatory inputfield is filled by the user:

public void CheckMandatory( java.lang.String fieldname )

{

//@@begin CheckMandatory()

IWDMessageManager messageMgr = this.wdThis.wdGetAPI().getComponent().getMessageManager();

Object attributeValue = this.wdContext.currentContextElement().getAttributeValue(fieldname);

IWDAttributeInfo attributeInfo = this.wdContext.getNodeInfo().getAttribute(fieldname);

if (((String) attributeValue).length() == 0){

messageMgr.reportContextAttributeMessage(wdContext.currentContextElement(),attributeInfo,IMessageBasics_Error.MISSING_INPUT,new Object[] { fieldname },true);

}

//@@end

}

but when we excute the code to "if (((String) attributeValue).length() == 0)",dump window appears.I debugged into the code and found the "attibuteValue" is not an empty string but an null value,maybe that's the reason for the dump.

How to deal with the problem? Thanks in advance.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

Take the value as string

Instaed of this

Object attributeValue = this.wdContext.currentContextElement().getAttributeValue(fieldname);

put this

String value ="";

value = this.wdContext.currentContextElement().getAttributeAsText(fieldname);

Then check for this condition

if (value.length() == 0) {

messageMgr.reportContextAttributeMessage(wdContext.currentContextElement(),attributeInfo,IMessageBasics_Error.MISSING_INPUT,new Object[] { fieldname },true);

}

Answers (5)

Answers (5)

Former Member
0 Kudos

Hi Begue,

Implement Chandran's method for validation.

Using the Required property will not help, if the fieldValue, is a String type Context.

Coz, NULL is a valid value for String Object.

Regards,

Alka.

Former Member
0 Kudos

Hi ,

Instead of writing code,

you can select the state property of Inputfield as required.

I think this will do..

Thanks,

Gunja

Former Member
0 Kudos

Hi,

Try this

if ( null == attrributeValue || attributeValue.trim().length() == 0)){

messageMgr.reportContextAttributeMessage(wdContext.currentContextElement(),attributeInfo,IMessageBasics_Error.MISSING_INPUT,new Object[] { fieldname },true);

}

//@@end

}

--

Shyam

Former Member
0 Kudos

Hi ,

Try this way

IWDMessageManager messageMgr = wdComponentAPI.getMessageManager();

Object attributeValue =

wdContext.currentContextElement().getAttributeValue(fieldName);

IWDAttributeInfo attributeInfo =

wdContext.getNodeInfo().getAttribute(fieldName);

if (attributeValue instanceof String) {

if (((String) attributeValue).length() == 0) {

messageMgr.reportContextAttributeMessage(

wdContext.currentContextElement(),

attributeInfo,

IMessageRequisitionForm.MISSING_INPUT,

new Object[] { fieldLabel },

true);

}

} else if (attributeValue instanceof Integer) {

}

Regards

LakshmiNarayana

Former Member
0 Kudos

Hi

Make use of this code

Object attrValue = wdContext.currentContextElement().getName();
 if(attrValue==null)
 {
    wdComponentAPI.getMessageManager().reportSuccess("The Value is Null");
 }
 else
 {
     wdComponentAPI.getMessageManager().reportSuccess("Entered  Value"+wdContext.currentContextElement().getName());
  }

Regards

Chandran S