• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to submit a null in radio button

 
Dayton Shepherd
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I will try this a second time. I earlier typed my information directly into the space online and clicked submit and never had my question show up online. I am new to java and “object oriented” programming and have lost my mentor and trying to do maintenance on a application that someone else wrote. I am working in eclipse Lomboz with jdk 1.4, struts 1.3, spring 1.3 and hibernate 2 with a mixture of hibernate and jdbc data base connections connecting to Oracle10 database and our application server is Oracles OC4J_101330. I do know that we can’t upgrade hibernate, etc because the OC4J won’t support the upgrades.
I was asked to add the following question to one of the JSP screens. “Is this an H2B job order? Yes No”. I looked at it and figured that a radio button would be the best route and went that direction. I copied some code from that page and made some field name changes, etc. so that it reads as follows:

I have the code working when “Yes” is selected but my problem is when they select “No” and it is in the defaultValue. The field in the table accepts three values, “A”, “B”, and null . My problem is when the “No” value is selected, it is not submitting a null but a space and give an error of “Invalid value” on trigger insert of the database. I have tried the following values “”, “ “, “null”, “NULL”. I have tried to put in a value of “N” and in the area where I am doing my error checking tried to re assign the value form “N” to null but haven’t been able to get that accomplished. I need some guidance on what I am doing wrong.

My preferred method is to be able to recognize a null value and to insert a null value into the table but would go with the “N” and re-assign it to a null. I think that the radio button is a better choice than a check box but would be open to change is I can be shown or explained why it would work.

The majority of the records in the database have a null in that field and only a few “A” and “B”. This is the public side of an application that had the private side written in oracle forms. If it was only for my code, I would set it up so that it accepted a “N’ in the field and change all the nulls to “N”. The private side is working ok so they don’t want to change it unless absolutely necessary.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65123
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My problem is when the “No” value is selected, it is not submitting a null but a space

Because that's exactly what the code is saying to do. Though cutally, it's not a "space", but an empty string.

You will not be able to get it to submit a null. That's just not the way radio buttons work in HTML. Just detect the empty string and do whatever you need to do with it.
 
Dayton Shepherd
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you give me some advice on how to re-assigned the value from a space or a "N" to a null for inserting in the database since I can directly work with a null?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65123
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An "if" statement?
 
Dayton Shepherd
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I understand that, I have tired the following:

Plus some other code (System.setProperty("H2BJOBFLAG", null);) request.setProperty("H2BJOBFLAG", null); but haven't figured out how to re-assign my parameter to have a value of null.
The above code doesn't work but used "System.out.println ("H2B:null");" inside the if statement to know that it was going into the if statement and getting print outs on my Console. I need guidance on what direction to go.
Thanks in advance.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65123
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
At this point I'm going to move the topic to the general Java forums as this is just basic Java.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49823
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Beware of setting things to null; you can get nasty exception problems like that.

You cannot set an object to null, only a reference can be set to point to null. And references are hidden behind variable names (identifiers). So you would need something like
 
Dayton Shepherd
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I understand that and everything I have tried gives an error
For example the following gives "Unable to dispatch JSP page "...""cannot find symbol"



I am sure what to do at this point to fix my problem.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic