473,508 Members | 2,283 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Is it possible to have an empty integer?

dlite922
1,584 Recognized Expert Top Contributor
Sorry for the lolcat title, but seriously I don't know what the best approach would be.

I'm working with a table model. In the data I have a String, 2 Integers, and 1 Boolean column.

The Boolean and one of Integer columns CAN have empty values.

When I'm populating the data I'm setting the default values of the Boolean to false and the integer to null like so:

Expand|Select|Wrap|Line Numbers
  1.  
  2. result[ri][0] = sdtSrvc.getServiceId();
  3. result[ri][1] = "   "+sdtSrvc.getCallTag();
  4. result[ri][2] = (mapSrvc != null) ? mapSrvc.getCableID() : null; //<--------- Empty Integer Needed Here instead of null
  5. result[ri][3] = (mapSrvc != null) ? mapSrvc.getEnabledFlag() : false;
  6. result[ri][4] = sdtSrvc.getTransportStreamId();
  7.  
  8.  
Symptom of problem:
The records that DO have a value, JTable treats them like a string and aligns them to the left. Yuck!

I should mention I have overridden the AbstracTableModel's getColumnClass() like this:

Expand|Select|Wrap|Line Numbers
  1.  
  2.     @Override
  3.     public Class getColumnClass(int c)
  4.     {
  5.         Object val = getValueAt(0, c);
  6.  
  7.         if(val == null) {
  8.             Integer scrap = 0;
  9.             return scrap.getClass();
  10.         } else
  11.         {
  12.             return getValueAt(0, c).getClass();
  13.         }
  14.     }
  15.  
This method is called by JTable's Cell Render..er. As you can see I'm creating an int and returning it.

it works, but again Yuck! and what if there's an empty record in the String column. The cell render will treat it as an int.

If I could somehow declare my default value as an empty int that would be great and I can change the above method to just the return line:

return getValueAt(0, c).getClass();

and be done with it!

My other option is to evaluate c (the column index) and find which column it is and hard code the default type of that column, but again what if I reorder my columns or drop columns in the future? I'd rather not have this mess to maintain.

In short, can I have my cake and 'not' eat it too?

: )

Thanks for any feedback guys!


Dan
Nov 19 '10 #1
6 37027
Dheeraj Joshi
1,123 Recognized Expert Top Contributor
Integer can not be empty Dan. But you can display them as Strings. So if null is the value of in just display "". That is nothing to display.

Probably i am confused about your question :(

Regards
Dheeraj Joshi
Nov 22 '10 #2
dlite922
1,584 Recognized Expert Top Contributor
Thanks Dheeraj, That doesn't get the rid of the symptom. Which is: It makes the table think that column is a string instead of an integer, hence rending the numbers further down the list as a string!

If I hard code logic in the getColumnClass() method, then I'd hard code the column index. Something I don't want to do because it requires maintenance.

How would you go about handling this situation? At the moment I'm defaulting every empty column to an integer.

Thanks again,

Dan
Nov 22 '10 #3
Dheeraj Joshi
1,123 Recognized Expert Top Contributor
Why can't you render all the integers as String and display it in the table?

Yes, Overriding may not be a good option.

I would default all empty columns as a String.

Regards
Dheeraj Joshi
Nov 22 '10 #4
Dheeraj Joshi
1,123 Recognized Expert Top Contributor
What i am saying even if the values is int or null render it as String. (Unless your app is not very bulky).

It solves the rendering problems.

Regards
Dheeraj Joshi
Nov 22 '10 #5
dlite922
1,584 Recognized Expert Top Contributor
So I can do that, but it's not just the empty values that are rendered as string, but the integers in that row will now be displayed as integer (i.e. they are left aligned instead of right aligned, you can enter non-number characters instead of just digits, etc)

Thanks,
Nov 22 '10 #6
Dheeraj Joshi
1,123 Recognized Expert Top Contributor
I thought it is just displaying(read-only). But anyway if user can enter the values for the table then displaying them as String is not a good idea, since it involves a lot of validations when user enters some characters or symbols.

Regards
Dheeraj Joshi
Nov 23 '10 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

3
14745
by: Randell D. | last post by:
Folks, If I have a number that includes decimal points and I want to remove everything right of the decimal, how do I do it - I know I could explode using the point as a delimiter but that...
5
11572
by: Anton | last post by:
I have a table of zip codes, some with Canadian zips. I'd like to take a zip code and search for nearby zips. For example: Dim theZip As Integer = textbox1.text ....Parameter.Add(@ziplow,...
3
4859
by: nephish | last post by:
Hey there, i have a simple database query that returns as a tuple the number of rows that the query selected. kinda like this >>> cursor.execute('select value from table where autoinc > 234')...
19
32249
by: wetherbean | last post by:
Hi group..I am writing a playlist management protocol where I have a file that holds all the playlists and a file that holds all the songs....before a playlist is created I need to check to see if...
1
5543
by: Oleg Ogurok | last post by:
Hi all, I want to use RegularExpressionValidator to enforce non-empty integer format in a TextBox. However, the validator doesn't give the error when the textbox is empty. For example, if...
3
2504
by: Dean Slindee | last post by:
I want to build an array on the fly in code with a parameter passed for the number of elements in the array. I am trying to do this by looping, but get an array with just one element in the end....
1
2185
by: Sivaraman.S | last post by:
Hi, Can i pass integer array to methodInfo.Invoke(obj,args()). I am able to pass only string array to this function. This is the code i have written. Dim myType As Type = objClass.GetType()...
11
1814
by: nephish | last post by:
Hello there, i need a way to check to see if a certain value can be an integer. I have looked at is int(), but what is comming out is a string that may be an integer. i mean, it will be formatted...
1
2310
by: =?Utf-8?B?RG9u?= | last post by:
Hello, I'm creating a web service that will allow people to enter their contact information into a SQL Server table. I get it to work when I enter all of the fields and press the invoke button,...
5
1188
by: Joe | last post by:
does anyone have any clue??
0
7224
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7118
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7323
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7379
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7038
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
5049
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3180
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
763
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
415
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.