aspose file tools*
The moose likes JSP and the fly likes null field value on submit Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "null field value on submit" Watch "null field value on submit" New topic
Author

null field value on submit

Tom Griffith
Ranch Hand

Joined: Aug 06, 2004
Posts: 257
Hello. If somebody has a minute, I have been wrestling with this for two days. I am working on a workflow application that allows users to create assignments, ie. oracle insert, from within a single tracking record. I coded javascript with a window.opener to give the user a dialog box where they select three fields which pertains to the particular assignment record...action, date_assigned, assignee. Within the dialog box, there is a submit button that inserts these fields along with several others inherited form the original tracking record (using hidden fields and self.opener...). Anyways, for my three fields in question, I am able to pass action and assignee to the javabean, but the javabean reads null for date_assigned, no matter what I do. I coded javascript to throw up an alert box with the value of date_assigned on submit and it has the proper value...but for some reason after the submit, the javabean reads null for date_assigned.

I have tried everything...every angle...nothing. Does anybody have any ideas? Thank you very much for reading this.
[ February 07, 2005: Message edited by: Tom Griffith ]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Post the doPost method and the HTML form.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Tom Griffith
Ranch Hand

Joined: Aug 06, 2004
Posts: 257
Ok. Thank you. Here is the date_assigned field that keeps reading as null in the javabean...the button next to the date_assigned field calls a javascript date picker. The date_assigned field defaults to today's date (in dd-mmm-yyyy format) via javascript when the form loads.



This is really frustrating. As a test, I've called the javascript that populates the date_assigned field with today's date on ~other~ fields and the value passes successfully...it just seems to bomb to null for this particular field.

This is the submit action for the form...all fields are passed to redirect_assgn_insert.jsp as request parameters...



The redirect_assgn_insert.jsp loads a javabean that performs a typical jdbc insert...getters, setters, prepared statement SQL, etc.

GETTER...

public String getDate_assigned()
{
return date_assigned;
}

SETTER...

public void setDate_assigned( String value )
{
date_assigned = value;
}

As an aside, I have another column for each record called date_created. This is the record creation date. Using the Date class and parsing/splitting today's date to obtain dd-mmm-yyyy, I populate this field in the javabean. I can't do this for date_assigned cuz the users have to be able to enter it. Also, all values are stored in Oracle as varchar2.
[ February 07, 2005: Message edited by: Tom Griffith ]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Dumb question, is the date_assigned tag inside the form?

Before fishing through all of the Java/JSP code, I would make sure that the browser is even sending the value in the first place.
If you have Mozilla/Firefox this is easy to do with liveHeaders.
http://livehttpheaders.mozdev.org/

A packet sniffer is also a nice development tool at times like this.

If you don't have access to any of these, a little function like this can save you a lot of time:


If the browser is not sending the name/value pair, then you know the problem is in your HTML or Javascript -- in which case, you're in the wrong forum ;-)
Tom Griffith
Ranch Hand

Joined: Aug 06, 2004
Posts: 257
Thank you very much. Where would I put that function?...because I found this problem via null catching in the javabean loaded by redirect_assgn_insert.jsp. If I put something like this within that javabean, won't it be kinda redundant and return null for date_assigned anyway?...

Oh yeah, actually when you asked me to post the form code, I went back to make sure the date_assigned field was within the form tags. Is that what you mean by the dumb question?
[ February 07, 2005: Message edited by: Tom Griffith ]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

To use it in a JSP, you would want to put it in a declaration tag and then call it from the top of your JSP page.

Or, you could just put it's contents into an include and paste it in the page whenever you need it.

You'll need to import java.util.Enumeration.
It also assumes you have a logger named 'log'.
Change 'log.debug' to 'System.out.println' or pass it the 'out' PrintWriter and use 'out.println' depending on where you want the output to go.


Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

If I put something like this within that javabean, won't it be kinda redundant and return null for date_assigned anyway?...


My point was to find out what the browser is sending you.
The best place to do this would be to look directly at the TCP traffic with a packet sniffer. The next best thing to do, is catch and print all the form params at the top of the JSP page. If it's not there then you don't need to debug any of your bean code. You know the browser is not sending it and the place to look is in your Javascript code.



Yes, that's what I meant. I've done things like put a form field outside of the form before.
Tom Griffith
Ranch Hand

Joined: Aug 06, 2004
Posts: 257
I think you kinda gave me a lead on this. I suspect that function will return null for the field. I moved one of my hidden fields into the visible html table that contains date_assigned and now that returns null and the onload javascript doesn't even access it. This is looking like a tagging problem of some sort. I'll let you know...but like you said earlier, I'll try this function you provided to verify that it's not being passed before looking at html. Thank you so much again...
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Just thought of another even simpler way to check this.
Comment out your javascript code and hardcode this in your form:

Tom Griffith
Ranch Hand

Joined: Aug 06, 2004
Posts: 257
Hi. It wasn't actually an HTML tag problem...I had that test field duped on the form.

Anyways, I took your advice and printed out some of the request parameters on the redirect jsp. All of a sudden, the date_assigned field took. This looks like something must be cached somewhere or whatever and when I called request.getParameter, it seemed to reset in the jvm or something.

Do you have any idea why? I've seen this kind of behavior before with parameter passing where I would just shut down my server for the day and the next morning the parameter passing would suddenly work. This was much more stubborn, it kept giving nulls even after I shut down the server and my local machine. Thank you very much again for the ideas of testing the parameters...

Maybe I should force garbage collection somewhere...

but still, why would this persist after shutdowns...
[ February 08, 2005: Message edited by: Tom Griffith ]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: null field value on submit