on 10-11-2005 12:31 AM
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...
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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
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
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
86 | |
23 | |
11 | |
9 | |
8 | |
5 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.