GeeCON Prague 2014*
The moose likes JSP and the fly likes Form submit to bean reading null values Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » JSP
Bookmark "Form submit to bean reading null values" Watch "Form submit to bean reading null values" New topic
Author

Form submit to bean reading null values

Tom Griffith
Ranch Hand

Joined: Aug 06, 2004
Posts: 271
Hi. If anybody has a minute, I seem to come across this problem every so often...I submit a form to another jsp that loads a bean which uses setter methods to derive the values from the submitted form fields. THe problem is that the bean reads nulls for these fields...and I can't figure out why, nor do I remember how I ever resolve it. Some field values are selected values from select boxes, some are hidden fields, and some are visible text fields. I was thinking that values from select boxes or hidden fields could be bombing because they aren't technically text but I thought setters converted those anyway, plus the field types with text are giving me nulls as well. Any help is really appreciated and thank you in advance. Here are my setters from the bean...

public class Nquery_NUP {

String term_userid;
String term_commonname;
String term_db_source;
String current_user_office;

public void setTerm_userid( String value )
{
term_userid = value;
}

public void setTerm_commonname( String value )
{
term_commonname = value;
}

public void setTerm_db_source( String value )
{
term_db_source = value;
}

public void setCurrent_user_office( String value )
{
current_user_office = value;
}


System.out.println(term_userid);
System.out.println(term_commonname);
System.out.println(term_db_source);
System.out.println(current_user_office);
[ October 18, 2004: Message edited by: Tom Griffith ]
Tom Griffith
Ranch Hand

Joined: Aug 06, 2004
Posts: 271
Actually it's not the setters that convert the values to String objects, it's the jsp:setProperty on the target jsp which is loading the bean. All the parameters then are converted to String objects, so I don't think that's the problem, yet the parameter passing must be the problem...
[ October 18, 2004: Message edited by: Tom Griffith ]
Tom Griffith
Ranch Hand

Joined: Aug 06, 2004
Posts: 271
Ok. I've created a test target jsp that merely displays the request parameters from the initial jsp. The four field values are successfully being passed on as parameters on the submit...so somehow the bean is not reading the parameters as String objects...I think...so the setter methods in the bean are never called since the request parameters are not of type String??.. But then I thought jsp.setProperty converted them all to String objects. Is this right so far?...thank you...
[ October 18, 2004: Message edited by: Tom Griffith ]
Tom Griffith
Ranch Hand

Joined: Aug 06, 2004
Posts: 271
This is driving me crazy. I've spent all afternoon trying to get this bean to load these parameters...and I jsut keep getitng null after null. I simply cannot find why this is happening. This is the code on the target jsp that is loading the bean...

<jsp:useBean id="Nquery_NUP" class="com.nctims.Nquery_NUP" scope="request">
<jsp:setProperty name="Nquery_NUP" property="*"/>
</jsp:useBean>

I know the parameters from the fields on the source jsp are being passed because of the test target jsp I created...so the when I load this bean, with the above setters, it sees nulls for all values. If somebody could lend me a clue, I'd really appreciate it. I just can't find what I could be missing...thank you again.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61316
    
  66

1) You should have posted this in the JSP forum. I'll ask a sheriff to move it.

2) All request params are always Strings, so worrying about string conversion is a red herring.

3) The most likely cause of such problems are mismatches between the names of the request parameters and the mutators (setters). Check them carefully according to the JavaBean property naming rules.

4) In today's web app world, submitting a form to a JSP page is considered a poor pattern to follow. You should be submitting to a servlet controller where you have much more control over how the parameters are handled.
[ October 18, 2004: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Moving to JSP...


GenRocket - Experts at Building Test Data
Tom Griffith
Ranch Hand

Joined: Aug 06, 2004
Posts: 271
I'm sorry about not posting in the jsp forum, I'm still getting used to these forums...and thank you very much for the reply.

In any case, I do plan on lifting this junk off the jsp and into a controller at some point. I checked the spelling on all four setters over and over and there are no problems, and I have to figure that at least one of the four would have a correct spelling if that was the cause for this. But as of now, everything is still loading into the bean as null...

What is mystifying is that I've coded beans with jsp for several other JDBC queries and had no problems..but like I said, every once in a while I get this happening...but I tend to forget what I did to resolve it...

thank you again...
[ October 18, 2004: Message edited by: Tom Griffith ]
Tom Griffith
Ranch Hand

Joined: Aug 06, 2004
Posts: 271
Hi. This morning the bean loads the parameters. This is what happened before...and why I can't remember doing anything to "resolve" this. I let the jvm knock off for the day, make no code changes, and the next morning it decides to cooperate. I suspect some sort of cache. Thank you again...
[ October 19, 2004: Message edited by: Tom Griffith ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Form submit to bean reading null values