cancel
Showing results for 
Search instead for 
Did you mean: 

Integer value for form input

Former Member
0 Kudos

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...

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

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

Former Member
0 Kudos

Hello Valery,

Actually, the type in the JavaBean is of primitive type 'int' not java.lang.Integer. Will I still be able to adjust the model object even though it is of type int?

Thanks,

Dustin

Former Member
0 Kudos

Dustin,

Yes, but you have to do 2 changes:

1. First as I described with generated model class

2. Second: alter type of filed in your JavaBean from int to java.lang.Integer

VS

Former Member
0 Kudos

Hi Valery,

I was trying to avoid changing the JavaBean model.

The model was originally created by a TogetherSoft XMI model and the underlying data object directly maps to a JDO object so it would require some retrofitting on the backend if I changed the bean.

Do I have any other option?

Thanks for your speedy responses.

Dustin

Former Member
0 Kudos

Dustin,

I was sure that you are using JavaBean Model Import rather then XMI.

Probably you may get desired behavior via calculated context attributes. But first I have to know what empty input means? Zero? Some other value?

VS

Former Member
0 Kudos

I explained it as JavaBean model for simplification...

Right now that context attribute is always populated with '0' and I would like it to be populated with blank when it is null.

D

Former Member
0 Kudos

Dustin,

This exactly what I mean: Java primitive type <b><i>int</i> may not be null</b>. So what value should be treated as null? If all values are valid, then you have to change XMI model + JDO classes to allow entering null values.

VS

Former Member
0 Kudos

I realize that int is 0 when it is null. I was looking for a web dynpro specific fix. It doesn't look like there is a solution since the model is tightly coupled with the UI.

I thought there might be some way to esentially blank that value out, but that doesn't seem to be the case.

Thanks,

Dustin

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Hope this helps,

Best regards,

Nibu.