cancel
Showing results for 
Search instead for 
Did you mean: 

Validate datatype of an attribute

Former Member
0 Kudos

Hi,

Need to validate whether value of an attribute is an instance of the datatype of the attribute.

Will the following code work ?

IWDNodeElement element = wdContext.nodePlants.getCurrentElement();

IWDAttributeInfo attrInfo = (IWDAttributeInfo)element;

if (element.getAtrributeText("test") instanceof attrInfo.getDataType()){

//code here

}

Do let me know.

Thanks !

Sri

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi Srikanth,

I hope the following link woul dbe helpful in your case

Regards

Noufal

Former Member
0 Kudos

Sounds strange.

First, you cannot cast a node element to an attribute info.

Second, why do you need to check the type of an attribute value at all?

Armin

Former Member
0 Kudos

Reason for second: dynamic UI generation for given context node / model. It's necessary to known built-in data type to create 'best match' UI control (drop down for enumeration, radio group for boolean, file upload / download for binary, etc)

VS

Former Member
0 Kudos

Armin,

I need to validate the data input in the field. One of the validation criteria is datatype....say "Is data input numeric". For this we need to look at the input data type and compare it with the datatype of the attribute. Do realise there may be a casting issue in my code. So, please advise the best approach. Thanks !

Former Member
0 Kudos

Hi

If the ValueAttribute u assigned to the InputField is of type Integer then WebDynPro itself Validates.

u need not Validate it separetly.

Wishes

Krishna kanth

Former Member
0 Kudos

Though I set the value attribute to type integer, I have been able to enter string data. When and how is the WD validation triggered ? Is there a way to capture this and throw a useful message to the user ? My use case requires to validate all fields at the time the user submits the form. So, need to look into each UI input element and the associated value attribute, and inform the user of any data issue.

Do let me know.

Thanks !

Former Member
0 Kudos

Hi

See u need not write any piece of code suppose where u r trying to Validate will Take care of that but ur Action shuld be Validating Action instead of Non-Validating Action.

See the Order of Actions is

1. WebDynpro will Validate First its own rules

2. Next is ur customized Validations will Take Place.

Try having some Empty Action on Input Field i.e onEnter of InputField Like that

See while creating Action for the Button Submission u Dont Check the CheckBox.

if u check it webDynpro will not Validate if not it Validates.

Hi

U need to check whether it is null or not but need not Validate whether it is Numeric or Not.

Wishes

Krishna kanth

Message was edited by: krishna kanth

Message was edited by: krishna kanth

Former Member
0 Kudos

Try the following

try{

IWDNodeElement element = wdContext.node<<NodeName>>().getCurrentElement();

if (element.getAttributeValue("ATTBName").getClass().newInstance() instanceof String ){

}

}

catch(Exception e)

{

}

Make sure that in the init method you need to create a n element of the node type .Otherwise you will get null pointer exception !!

Ex: IPrivateTestView.I<<NOde>>Element ele=wdContext.create<<Node>>Element();

ele.set<<Attrib>>("Temp");

wdContext.node<<Node>>().addElement(ele);

Regards, Anilkumar

Former Member
0 Kudos

Anil,

Thanks for the response. But, what if I need to iterate through a list of value attributes that could be string, numeric, date type etc ? Is there a generic way of validating the data types ? Rather that coding the if statement as "....instance of String", is there a way to code something like "<value of attribute> instance of <datatype of the attribute>".

Hope the question is clear enuf. Do let me know.

Thanks !

Former Member
0 Kudos

Hi,

Check the following code this might be useful for you.


  IWDNodeElement element = wdContext.getCurrentElement();
  IWDAttributeInfo attrInfo = (IWDAttributeInfo)element.node().getNodeInfo().getAttribute(<<AttrName>>);
  Object obj = element.getAttributeValue(<<AttrName>>);
  if (attrInfo.getDataType().getAssociatedClass().isInstance(obj)){
	   //your code here - just printing here
   wdThis.wdGetAPI().getComponent().getMessageManager().reportSuccess("Data : "+obj.toString());
   }

This thing works fine, but for primitive types like "boolean" and "int", it won't work.

Regards,

Santhosh.C