Skip to Content
author's profile photo Former Member
Former Member

Validate datatype of an attribute

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

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Jun 11, 2005 at 04:58 AM

    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

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      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

  • author's profile photo Former Member
    Former Member
    Posted on Jun 11, 2005 at 05:07 PM

    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

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      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

  • author's profile photo Former Member
    Former Member
    Posted on Jun 14, 2005 at 06:47 AM

    Hi Srikanth,

    I hope the following link woul dbe helpful in your case

    problem-with-exception-handling

    Regards

    Noufal

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.