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

Integer value for form input

I hope this is a simple question. I have a java bean that I have created a WD model from and one of the attributes is of type "integer." I would like to use this value in the form, but whenever I bind the object to a fresh java bean it puts a '0' in the form because that is the 'null' value for an integer. Is there a simple way to make the web dynpro not populate 0 in the integer bound field? If I remove the 0 and try to submit the form blank, it gives an exception saying "Value contains non-numeric characters."

Ideas appreciated.

Thanks,

Dustin

P.S. I'd like not to create a "string" representation of the integer if at all possible because I do not want to change the bean...

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Oct 12, 2005 at 12:27 PM

    Dustin,

    If I understand you right, you have JavaBean property of type java.lang.Integer.

    Please make sure that after import model class attribute has type <b>com.sap.dictionary.predefined.objecttypes.integerObject</b>. If the type is other, you may right click on attribute, choose edit and select necessary type from local dictionary (com.sap.dictionary.predefiend.objecttypes / integerObject).

    Next WD should display NULL as empty text (and let you enter empty text for NULL value). I try this with SP11 IDE and NW04s server -- it works. If it doesn't works with your environment, then it is probably a WD bug.

    Valery Silaev

    EPAM Systems

    http://www.NetWeaverTeam.com

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Dustin,

      It seems that you didn't get a question 😊

      But anyway, let us paraphrase it: "if value==0 then do not display value at all"

      To implement this functionality do the following in view controller:

      1. Create 1..1 value node (selection 1..1) right under your model node (where JavaBean used as model class)

      2. Create attribute MyAttr in this node of type integerObject (see my previous posts)

      3. Make this attribute calculated (first line in attribute properties in IDE)

      4. Write the following for generated getter method:

      /* element here is from method params */
      final <YourJavaBeanClass> model = 
        (<YourJavaBeanClass>)element
          .node()
            .getParentElement()
              .model(); 
      final int value = model.get<YourJavaBeanProperty>();
      return 0 == value ? null : new Integer(value);

      5. Write the following for generated setter method:

      /* element & value here are from method params */
      final <YourJavaBeanClass> model = 
        (<YourJavaBeanClass>)element
          .node()
            .getParentElement()
              .model();
      model.set<YourJavaBeanProperty>
      (
        null == value ? 0 : value.intValue();
      );

      6. Bind input field to this calculated attribute

      VS

  • author's profile photo Former Member
    Former Member
    Posted on Oct 11, 2005 at 03:56 AM

    Hi Dustin,

    I don't think we can prevent the default '0' from showing up in the input field. But what we can do is make the action handler as non-validating and proceed further. This will let you to bypass the error message.

    Edit the action handler that is being invoked on 'submit'. Select the checkbox saying 'without validation'. After this even if you enter some non-integer value into the field, the attribute will still be having '0' as the value.

    This query may help you in this regard how to overwrite standard errors?

    Hope this helps,

    Best regards,

    Nibu.

    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.