cancel
Showing results for 
Search instead for 
Did you mean: 

Check Mandatory

Former Member
0 Kudos

All,

I have a context node called DataSource and it has an field called First_Name..

Im checking whether its blank or not using below code..but getting an error

" com.sap.tc.webdynpro.progmodel.context.ContextException: NodeElement(ParentView.0): unknown attribute First_Name

Here is the code...

	this.CheckMandatory(IPrivateParentView.IDataSourceElement.FIRST__NAME);


public void CheckMandatory( java.lang.String fieldName )
  {
    //@@begin CheckMandatory()

	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) {
	String fieldLabel =
	wdContext.getNodeInfo().getAttribute(fieldName)
	.getSimpleType().getFieldLabel();
	messageMgr.reportContextAttributeMessage(
	wdContext.currentContextElement(),
	attributeInfo,
	IMessageParent.MISSING_INPUT,
	new Object[] { fieldLabel },
	true);
	}    
	}		
    //@@end
  }

Can anyone tell me what im missing..

BM

Accepted Solutions (1)

Accepted Solutions (1)

monalisa_biswal
Contributor
0 Kudos

Hi Bharati,

First_Name attribute is created under node DataSource, but while taking attributeInfo you are taking nodeInfo of root node not DataSource.

Replace this line with wdContext.getNodeInfo().getAttribute(fieldName);

wdContext.nodeDataSource().getNodeInfo().getAttribute(fieldName);

Hope It helps.

Former Member
0 Kudos

Now im getting below error:


  "   java.lang.IllegalArgumentException: No such attribute First_Name 

Corrected code as follows:


  public void CheckMandatory( java.lang.String fieldName )
  {
    //@@begin CheckMandatory()

	IWDMessageManager messageMgr =
	wdComponentAPI.getMessageManager();
	
	Object attributeValue =
	wdContext.currentDataSourceElement().getAttributeValue(fieldName);
	IWDAttributeInfo attributeInfo =
	wdContext.nodeDataSource().getNodeInfo().getAttribute(fieldName);
	if (attributeValue instanceof String) {
	if (((String) attributeValue).length() == 0) {
	String fieldLabel = "Test"	;
	messageMgr.reportContextAttributeMessage(
	wdContext.currentContextElement(),
	attributeInfo,
	IMessageParent.MISSING_INPUT,
	new Object[] { fieldLabel },
	true);
	}    
	}		
    //@@end
  }

BM..

monalisa_biswal
Contributor
0 Kudos

Again while displaying error message you refer to root node element.

messageMgr.reportContextAttributeMessage(

wdContext.currentContextElement(),<---Replace with DataSource

attributeInfo,

IMessageParent.MISSING_INPUT,

new Object[] ,

true);

Former Member
0 Kudos

I also found it But points to you...

Thanks a lot..

BM

Answers (3)

Answers (3)

Former Member
0 Kudos

Since original issue is resolved, closing this thread & opening another thread for Integer issue..

Former Member
0 Kudos

Can anyone tell me how to check whether Integer fields are populated or not?

BM

Former Member
0 Kudos

Hi Bharathi,

I guess you attribute type is integer. If your attribute type is integer then directly check whether value is 0 or not.

If it is type of String then use following code:

try {

Integer.parseInt(<context atrribute value>);

return true;

} catch (NumberFormatException nfe){

return false;

}

Regards,

Bhavik

Former Member
0 Kudos

Bhavik,

Thanks for your reply..I want to check whether user entered any value or not..THe integer field always populated with 0.

I want to check whether its initial or not. If its 0 then i need to throw an error message.How can i do that?

In SAP the fields types are NUMC.So will it convert it as Integer ot String?

BM

Former Member
0 Kudos

Solved..

Former Member
0 Kudos

Can anyone tell me how to check whether Integer fields are populated or not?

BM