• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

My bean doesn't quite work

 
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've been programming jsp's for a few months now. So far I have programmed in the Model 0 pattern ;)

But after constantly being yelled at by article after article I decided to take small step away from Model 0 and try to make a bean. So I created my class...



It is very simple. I have a form with these 5 fields and a Submit button. On submit I run some javascript to see if the search criteria falls into a certain set of combinations that are allowed. After that it goes over to a jsp for some processing. But the only value that actually gets held by the bean is the first field PO. The next three return null and the last one return 0.

I did an out.print(myPackage.getPO()); ect, for all my fields. That is how I found out their values. Why would the last string be a 0 and not a null, and why wouldn't they be taking to the bean? Any ideas?

PS. I'm new here. Please be nice ;)
[ November 20, 2007: Message edited by: Bear Bibeault ]
 
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You didn't mention what your bean has to do with your form.

While you're trying to take steps in the right direction, an important one to take -- and now is a really good time - is to stop submitting data to JSPs. Submit to a servlet that performs any data processing.
[ November 19, 2007: Message edited by: Bear Bibeault ]
 
Bryce Martin
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just need it to redirect to the correct page based on the search combination that was used. I'd like to start using servlets but I'm just trying to get one thing working at a time. The problem isn't on my resulting JSP. The problem is with the form info being picked up by the bean. Why isn't that happening??
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How are you passing the form information to the bean?
Can you post the JSPs that use it (or the significant part, if they're long)?
 
Bryce Martin
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OnSubmit i go to linkagebean.jsp where this code happens...



if I entered something into the PO field it sees it, but the next 3 are always null, and the last one is always 0. Here is the form code on my Selection.jsp.



I do some validation with javascript as to the choice combinations that are allowed. Nothing special there.

I don't put any kind of bean tag on the Selection.jsp page. Do I need to? I didn't think I did. Its odd that it only picks up the first field in the bean.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your parameter names don't match the bean specification.

The tag:
<jsp:setProperty name="myPackage" property="*"/>
instructs the JSP engine to match the request parameters with your bean's properties.

So, if you're bean's property methods are getJob and setJob, the form parameter should be "job", not "Job".

You might have trouble with "PO".
If so, the easiest thing to do is rename it to purchaseOrder and then rename the bean properties to getPurchaseOrder and setPurchaseOrder.
 
Bryce Martin
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you explain how the case sensitivity works? It seems counterintuitive that the cases of job and Job don't match. What are the rules for this?

PS...forget about the 0 value. That is not related to my bean. I found out what that was. It was from some code farther down on my linkagebean.jsp

I almost have it, i just have to resolve the PO issue. I think i'm just going to make it Po instead of PO...that should do it.
[ November 20, 2007: Message edited by: Bryce Martin ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you google for "Java Ben Specification" you can find all the particulars.

In a nutshell, bean properties start with a lower case letter and are camel syntax.
Examples:
firstName, lastName, socialSecurityNumber, etc..

The mutators and accessors should use the standard get/set syntax.
Examples:
getFirstName, getLastName, getSocialSecurityNumber

So, if your form param is "myParameter", the JSP engine will try to match it to a method in your bean named "setMyParameter".

Two letter variable names can get tricky (Like 'PO') so I tend to avoid them.
 
Bryce Martin
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok. So I'm still having trouble with this. I've tried so many different ways of doing this but it just won't pick up my purchaseOrder in the bean. I have two different values that have some mixed cases. The first one is purchaseOrder, the other one is custName. custName works fine. I get no errors and the data displays just perfect. So I've modeled purchaseOrder after that but it still can't find it. I'll keep playing with it, but I'm out of fresh ideas as to why it won't see it...
 
Bear Bibeault
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is it purchaseOrder or po?

Is your accessor named getPurchaseOrder()?

Are you sure that the updated and compiled bean is in the right place? Have you restarted the app since compiling?
 
Bryce Martin
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good lookout on the accessor. That was the one thing I forgot to change. I stared at that for a while ago and just didn't see it.

Thanks a Ton.
 
Honk if you love justice! And honk twice for tiny ads!
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic